Advertisement
Guest User

viewJob.js

a guest
Jun 16th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var fullJobID;
  2. var smplJobID;
  3. var parentID;
  4.  
  5.  
  6. function formatDate(date) {
  7.     let hours = date.getHours();
  8.     let minutes = date.getMinutes();
  9.     let ampm = hours >= 12 ? 'pm' : 'am';
  10.     hours = hours % 12;
  11.     hours = hours ? hours : 12; // the hour '0' should be '12'
  12.     minutes = minutes < 10 ? '0' + minutes : minutes;
  13.     let strTime = hours + ':' + minutes + ' ' + ampm;
  14.     return date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear() + " at " + strTime;
  15. }
  16.  
  17. toastr.options = {
  18.     "closeButton": true,
  19.     "debug": false,
  20.     "newestOnTop": true,
  21.     "progressBar": true,
  22.     "positionClass": "toast-top-right",
  23.     "preventDuplicates": true,
  24.     "onclick": null,
  25.     "showDuration": "300",
  26.     "hideDuration": "1000",
  27.     "timeOut": "5000",
  28.     "extendedTimeOut": "2500",
  29.     "showEasing": "swing",
  30.     "hideEasing": "linear",
  31.     "showMethod": "fadeIn",
  32.     "hideMethod": "fadeOut"
  33. };
  34.  
  35. Template.viewJob.helpers({
  36.     isWarranty: function (jobType) {
  37.         return jobType === "Warranty"
  38.     },
  39.     isExtended: function (jobType) {
  40.         return jobType === "Extended"
  41.     },
  42.     formattedDate() {
  43.         let d = this.jobDate;
  44.         let e = formatDate(d);
  45.         return e;
  46.     },
  47.     shortDesc() {
  48.         if (this.description.length > 40) {
  49.             return this.description.substr(0, 50) + '...';
  50.         } else {
  51.             return this.description;
  52.         }
  53.     },
  54.     jobID() {
  55.         let a = this.jobNum;
  56.         let e = this.jobType.substr(0, 1);
  57.         smplJobID = a;
  58.         fullJobID = e + a;
  59.         parentID = this._id;
  60.         thIndex = this.index;
  61.         return '<span class="label label-default" id="jobID">' + fullJobID + '</span>';
  62.     },
  63.     phNumber: function () {
  64.         return Phoneformat.formatLocal('AU', this.number);
  65.     },
  66.     email: function () {
  67.         return this.email
  68.     },
  69.     status: function () {
  70.         let status = this.status;
  71.         switch (status) {
  72.             case "New":
  73.                 return '<span class="label label-primary">New</span>';
  74.                 break;
  75.             case "Assigned":
  76.                 return '<span class="label label-success">Assigned</span>';
  77.                 break;
  78.             case "Pending Parts":
  79.             case "Pending Approval":
  80.                 return '<span class="label label-warning">Pending</span>';
  81.                 break;
  82.             case "Stale":
  83.                 return '<span class="label label-danger">Stale</span>';
  84.             default:
  85.                 return ""
  86.         }
  87.     },
  88.     clipBtn: function () {
  89.         return '<span class="btn btn-info btn-xs btn-copy-link" data-clipboard-text=' + fullJobID + '><i class="fa fa-clipboard" aria-hidden="true"></i></span>'
  90.     },
  91.     pdfBtn: function () {
  92.         return '<span class="btn btn-primary2 btn-xs" id="pdfBtn"><i class="fa fa-file-pdf-o" aria-hidden="true"></i></span>'
  93.     },
  94.     notes: function () {
  95.         return this.notes
  96.     }
  97. });
  98.  
  99.  
  100. Template.viewJob.events({
  101.     'click .btn-copy-link': function () {
  102.         toastr.info(fullJobID + " - Successfully copied to clipboard");
  103.     },
  104.     'click .toast': function () {
  105.         toastr.clear();
  106.     },
  107.     'mouseenter #jobID': function () {
  108.         Dropdowns.show('jobID')
  109.     },
  110.     'mouseleave #jobID': function () {
  111.         setTimeout(function () {
  112.             Dropdowns.hide('jobID');
  113.         }, 1500);
  114.     },
  115.     'click #pdfBtn': function () {
  116.         var doc = new jsPDF();
  117.         var specialElementHandlers = {
  118.             '#editor': function (element, renderer) {
  119.                 return true;
  120.             }
  121.         };
  122.         doc.fromHTML($('#render_me').get(0), 15, 15, {
  123.             'width': 170,
  124.             'elementHandlers': specialElementHandlers
  125.         });
  126.         doc.save(fullJobID + '.pdf');
  127.  
  128.     },
  129.  
  130.     'click .whichIndex': function() {
  131.         console.log(this.index);
  132.     }
  133. });
  134.  
  135. Template.viewJob.onCreated(function () {
  136. });
  137.  
  138. Template.viewJob.onRendered(function () {
  139.     var clipboard = new Clipboard('.btn-copy-link');
  140.     var self = this;
  141.     this.autorun(function () {
  142.         // hack to force the autorun to reevaluate
  143.         Template.currentData();
  144.  
  145.         // onRendered code...
  146.         Meteor.call('setJobOpen', fullJobID, Meteor.user().emails[0].address, parentID);
  147.     });
  148.  
  149.     $('#textArea.editable').editable({
  150.         success: function (response, newValue) {
  151.             Jobs.update(
  152.                 {"_id": parentID},
  153.                 {
  154.                     "$set": {
  155.                         'notes.$.title': newValue
  156.                     }
  157.                 }
  158.             )
  159.         }
  160.     })
  161. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement