APIs

Show:
  1. /**
  2. A public terminal for users to collect queue numbers
  3. @class FQCustomerTerminal
  4. @constructor
  5. @return {Object} instantiated FQCustomerTerminal
  6. **/
  7. define(['jquery', 'backbone', 'bootbox', 'qrcode', 'QueueModel', 'moment'], function ($, Backbone, Bootbox, qrcode, QueueModel, moment) {
  8.  
  9. var FQCustomerTerminal = Backbone.View.extend({
  10.  
  11. /**
  12. Constructor
  13. @method initialize
  14. **/
  15. initialize: function () {
  16. var self = this;
  17. self.m_base_url = BB.CONSTS.BASE_URL + '?mode=remoteStatus&param=';
  18. $(Elements.FASTERQ_LINE_NAME).text(self.model.get('name'));
  19. $(Elements.FQ_TAKE_NUMBER_LINE_NAME).text(self.model.get('line_name'));
  20. self._createQRcode();
  21. self._listenPrintButton();
  22. self._listenEmailButton();
  23. self._listenSMSButton();
  24. },
  25.  
  26. /**
  27. Listen to custom selection on queue id creator via Print button
  28. @method _listenPrintButton
  29. **/
  30. _listenPrintButton: function () {
  31. var self = this;
  32. $(Elements.FQ_PRINT_NUMBER).on('click', function (e) {
  33. e.preventDefault();
  34. e.stopImmediatePropagation();
  35. self._getServiceID();
  36. return false;
  37. });
  38. },
  39.  
  40. /**
  41. Listen to custom selection on queue id creator via QR scan
  42. @method _createQRcode
  43. **/
  44. _createQRcode: function () {
  45. var self = this;
  46. var q = $("#qrcode");
  47. q = q[0];
  48. var qrcode = new QRCode(q, {
  49. width: 200,
  50. height: 200
  51. });
  52. var url = self._buildURL();
  53. log(url);
  54. qrcode.makeCode(url);
  55. },
  56.  
  57. /**
  58. Listen to custom selection on queue id creator via email
  59. @method _listenEmailButton
  60. **/
  61. _listenEmailButton: function () {
  62. var self = this;
  63. $(Elements.FQ_SENDIT_BUTTON).on('click', function (e) {
  64. var email = $(Elements.FQ_ENTER_EMAIL).val();
  65. if (!BB.lib.validateEmail(email)) {
  66. bootbox.alert('the emailed entered is invalid');
  67. return false;
  68. }
  69. $(Elements.FQ_DISPLAY_EMAIL_SENT).text('check your email').fadeIn();
  70. setTimeout(function () {
  71. $(Elements.FQ_DISPLAY_EMAIL_SENT).fadeOut();
  72. $(Elements.FQ_ENTER_EMAIL).val('');
  73. }, 5000);
  74. self._sendQueueEmail(email);
  75. });
  76. return false;
  77. },
  78.  
  79. /**
  80. Listen to custom selection on queue id creator via SMS
  81. @method _listenEmailButton
  82. **/
  83. _listenSMSButton: function () {
  84. var self = this;
  85. $(Elements.FQ_CALL_IT).on('click', function (e) {
  86. var sms = $(Elements.FQ_ENTER_SMS).val();
  87. if (sms.length < 6) {
  88. bootbox.alert('the phone number entered is invalid');
  89. return false;
  90. }
  91. $(Elements.FQ_DISPLAY_SMS_SENT).text('we will call you').fadeIn();
  92. setTimeout(function () {
  93. $(Elements.FQ_DISPLAY_SMS_SENT).fadeOut();
  94. $(Elements.FQ_ENTER_SMS).val('');
  95. }, 5000);
  96. self._sendQueueSMS(sms);
  97. });
  98. return false;
  99. },
  100.  
  101. /**
  102. Send customer email with link to create queue
  103. @method _sendQueueEmail server:sendQueueEmail
  104. @param {String} i_email
  105. **/
  106. _sendQueueEmail: function (i_email) {
  107. var self = this;
  108. $.ajax({
  109. url: BB.CONSTS.ROOT_URL + '/SendQueueSMSEmail',
  110. data: {
  111. business_id: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('business_id'),
  112. line_id: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('line_id'),
  113. line_name: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('line_name'),
  114. email: i_email,
  115. call_type: 'EMAIL',
  116. url: self.m_base_url
  117. },
  118. success: function (e) {
  119. },
  120. error: function (e) {
  121. log('error ajax ' + e);
  122. },
  123. dataType: 'json'
  124. });
  125. },
  126.  
  127. /**
  128. Send customer SMS / call when service id is up
  129. @method _sendQueueSMS server:sendQueueSMS
  130. @param {String} i_sms
  131. **/
  132. _sendQueueSMS: function (i_sms) {
  133. var self = this;
  134. $.ajax({
  135. url: BB.CONSTS.ROOT_URL + '/SendQueueSMSEmail',
  136. data: {
  137. business_id: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('business_id'),
  138. line_id: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('line_id'),
  139. line_name: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('line_name'),
  140. sms: i_sms,
  141. call_type: 'SMS',
  142. url: self.m_base_url
  143. },
  144. success: function (e) {
  145. },
  146. error: function (e) {
  147. log('error ajax ' + e);
  148. },
  149. dataType: 'json'
  150. });
  151. },
  152.  
  153. /**
  154. Get the next service id from remote server
  155. @method _getServiceID server:setQueue
  156. **/
  157. _getServiceID: function () {
  158. var self = this;
  159. // save with extra parameters
  160.  
  161. var model = new QueueModel();
  162.  
  163. model.save({
  164. business_id: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('business_id'),
  165. line_id: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('line_id'),
  166. type: 'PRINT'
  167. }, {
  168. success: (function (model, data) {
  169. $(Elements.FQ_DISPLAY_PRINT_NUMBER).text(model.get('service_id'));
  170. self._printNumber(model.get('service_id'), model.get('name'));
  171. }),
  172. error: (function (e) {
  173. log('Service request failure: ' + e);
  174. }),
  175. complete: (function (e) {
  176. })
  177. });
  178. },
  179.  
  180. /**
  181. Print current customer service id
  182. @method _printNumber
  183. @param {Number} i_service_id
  184. **/
  185. _printNumber: function(i_service_id, name){
  186. var self = this;
  187. var $printDiag = $(Elements.PRINT_DIAG);
  188. //var div = document.getElementById("printerDiv");
  189. var p = function(){
  190. $('body').append('<h2></h2>')
  191. }
  192. var arg = BB.lib.base64Encode(i_service_id + ':_:' + name)
  193. $printDiag.html('<iframe src="print.html?serviceId=' + arg + '" onload="this.contentWindow.print();"></iframe>');
  194.  
  195. // $printDiag.find('h1').text('your number is ' + i_service_id);
  196. // $printDiag.find('h3').text('created on ' + moment().format('MMMM Do YYYY, h:mm:ss a'));
  197. // var divContents = $(Elements.PRINT_DIAG).html();
  198. // var printWindow = window.open('', '', 'height=250,width=450');
  199. // printWindow.document.write('<html><head><title>' + self.model.get('name') + '</title>');
  200. // printWindow.document.write('</head><body><center>');
  201. // printWindow.document.write(divContents);
  202. // printWindow.document.write('</center></body></html>');
  203. // printWindow.document.close();
  204. // printWindow.print();
  205. },
  206.  
  207. /**
  208. Create URL string to load customer terminal UI for FasterQ queue generation
  209. @method _buildURL
  210. @return {String} URL
  211. **/
  212. _buildURL: function () {
  213. var self = this;
  214. var data = {
  215. line_id: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('line_id'),
  216. business_id: BB.comBroker.getService(BB.SERVICES.FQ_LINE_MODEL).get('business_id'),
  217. call_type: 'QR'
  218. };
  219. data = $.base64.encode(JSON.stringify(data));
  220. return self.m_base_url + data;
  221. }
  222. });
  223.  
  224. return FQCustomerTerminal;
  225.  
  226. });
  227.  
  228.