Advertisement
Guest User

Untitled

a guest
May 25th, 2018
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ($scope, $http, spUtil, nowAttachmentHandler, $rootScope, $sanitize, $window, $sce, i18n) {
  2.     var c = this;
  3.     c.quantity = 1;
  4.     $scope.data.sc_cat_item.description = $sce.trustAsHtml($scope.data.sc_cat_item.description);
  5.     c.widget._debugContextMenu = [
  6.         [ i18n.getMessage("Open") + " sc_cat_item", function(){
  7.             var item = c.data.sc_cat_item;
  8.             $window.open("/$sp.do?id=form&table=" + item.table + "&sys_id=" + item.sys_id); }]
  9.     ];
  10.     c.showAddCartBtn = function() {
  11.         return c.options.show_add_cart_button &&
  12.             c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
  13.             !c.data.sc_cat_item.no_cart;
  14.     }
  15.  
  16.     c.showQuantitySelector = function() {
  17.         return c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
  18.             !c.data.sc_cat_item.no_quantity;
  19.     }
  20.  
  21.     $scope.$on('dialog.upload_too_large.show', function(e){
  22.         console.log($scope.m.largeAttachmentMsg);
  23.         spUtil.addErrorMessage($scope.m.largeAttachmentMsg);
  24.     });
  25.    
  26.     $scope.m = $scope.data.msgs;
  27.     $scope.submitButtonMsg = $scope.m.submitMsg;
  28.     var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function() {});
  29.     ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * 24);
  30.     function setAttachments(attachments, action) {
  31.         $scope.attachments = attachments;
  32.     }
  33.     $scope.attachmentHandler.getAttachmentList();
  34.  
  35.     $scope.confirmDeleteAttachment = function(attachment, $event) {
  36.     $rootScope.$broadcast("dialog.delete_attachment.show", {
  37.       parms: {
  38.         ok: function() {
  39.           $scope.attachmentHandler.deleteAttachment(attachment);
  40.           $rootScope.$broadcast("dialog.delete_attachment.close");
  41.         },
  42.         cancel: function() {
  43.           $rootScope.$broadcast("dialog.delete_attachment.close");
  44.         },
  45.         details: attachment.name
  46.       }
  47.     })
  48.   }
  49.  
  50.     // Breadcrumbs
  51.     if ($scope.data.sc_cat_item) {
  52.         var bc = [{label: $scope.page.title, url: '?id=' + $scope.data.sc_catalog_page}];
  53.         if ($scope.data.category)
  54.             bc[bc.length] = {label: $scope.data.category.name, url: $scope.data.category.url};
  55.  
  56.         bc[bc.length] = {label: $scope.data.sc_cat_item.name, url: '#'};
  57.         $rootScope.$broadcast('sp.update.breadcrumbs', bc);
  58.         spUtil.setSearchPage('sc');
  59.     }
  60.  
  61.     var g_form;
  62.     $scope.$on('spModel.gForm.initialized', function(e, gFormInstance){
  63.         g_form = gFormInstance;
  64.  
  65.         // This runs after all onSubmit scripts have executed
  66.         g_form.$private.events.on('submitted', function(){
  67.             if ($scope.data.sc_cat_item.item_action === "order")
  68.                 getOne();
  69.             else if ($scope.data.sc_cat_item.item_action === "add_to_cart")
  70.                 addToCart();
  71.         });
  72.     });
  73.  
  74.     $scope.triggerAddToCart = function() {
  75.         $scope.data.sc_cat_item.item_action = "add_to_cart";
  76.         $scope.data.sc_cat_item.quantity = c.quantity;
  77.         if (g_form)
  78.             g_form.submit();
  79.     }
  80.  
  81.     $scope.triggerOnSubmit = function(){
  82.         //alert("Submit pressed")
  83.         $scope.data.sc_cat_item.item_action = "order";
  84.         $scope.data.sc_cat_item.quantity = c.quantity;
  85.        
  86.         //if (g_form)
  87.             //g_form.submit();
  88.             cacheUserInfo();
  89.     }
  90.  
  91.     // order / create request
  92.     function getOne() {
  93.         postCatalogFormRequest().success(function(response) {
  94.             var a = response.answer;
  95.             var n = a.number;
  96.             $scope.$emit("$$uiNotification", response.$$uiNotification);
  97.             $scope.$emit("$sp.sc_cat_item.submitted", a);
  98.             if (n)
  99.                 issueMessage(n, a.table, a.sys_id);
  100.             $scope.submitting = false;
  101.             $scope.submitButtonMsg = $scope.m.submittedMsg;
  102.         });
  103.     }
  104.  
  105.     function addToCart() {
  106.         postCatalogFormRequest().success(function(response) {
  107.             $rootScope.$broadcast("$sp.service_catalog.cart.add_item");
  108.             $rootScope.$broadcast("$sp.service_catalog.cart.update");
  109.             //spUtil.addInfoMessage("Added item to shopping cart");
  110.             $scope.submitting = false;
  111.         });
  112.     }
  113.  
  114.     function postCatalogFormRequest() {
  115.         setFieldsReadonly();
  116.         $scope.submitted = true;
  117.         $scope.submitting = true;
  118.         var t = $scope.data.sc_cat_item;
  119.         t._attachmentGUID = $scope.data._attachmentGUID;
  120.         // calls into SPCatalogForm.getItem()
  121.         return $http.post(spUtil.getURL('sc_cat_item'), t);
  122.     }
  123.  
  124.     // spModel populates mandatory - hasMandatory is called by the submit button
  125.     $scope.hasMandatory = function(mandatory) {
  126.         return mandatory && mandatory.length > 0;
  127.     };
  128.  
  129.     // switch catalog items
  130.     var unregister = $scope.$on('$sp.list.click', onListClick);
  131.     $scope.$on("$destroy", function() {
  132.         unregister();
  133.     });
  134.  
  135.     function onListClick(evt, arg) {
  136.         $scope.data.sys_id = arg.sys_id;
  137.         spUtil.update($scope);
  138.     }
  139.  
  140.     function setFieldsReadonly(){
  141.         var allFields = g_form.getFieldNames();
  142.         for(var fieldName in allFields){
  143.             g_form.setReadOnly(allFields[fieldName], true);
  144.         }
  145.     }
  146.  
  147.     function issueMessage(n, table, sys_id) {
  148.         var page = table == 'sc_request' ? 'sc_request' : 'ticket';
  149.         if (c.options.page) {page = c.options.page;}
  150.         if (c.options.table) {table = c.options.table;}
  151.         var url = spUtil.format(c.options.url, {page: page, table: table, sys_id: sys_id});
  152.         if (c.options.auto_redirect == "true") {
  153.             $window.location.href = url;
  154.             return;
  155.         }
  156.  
  157.         var t = $scope.m.createdMsg + " " + n + " - ";
  158.         t += $scope.m.trackMsg;
  159.         t += ' <a href="' + url + '">' + $scope.m.clickMsg + '</a>';
  160.         spUtil.addInfoMessage(t);
  161.     }
  162.  
  163.   /////////////////////////////////////////////////////////////////////////////////////
  164.     // B9B - remote widget recall button code - place the data from the cache table on the form
  165.     /////////////////////////////////////////////////////////////////////////////////////
  166.     $rootScope.$on('customEvent', function(event,obj) {
  167.         //alert("Recall triggered");
  168.        
  169.         //alert("Found value: " + $scope.data.recall.found);
  170.         if ($scope.data.recall.found==true) {
  171.             //alert("User history found. UserID: " + $scope.data.recall.uID);
  172.             g_form.setValue("u_mr_recipient", $scope.data.recall.mr_recipient);
  173.             g_form.setValue("u_mr_backup_name", $scope.data.recall.mr_backup_name);
  174.  
  175.             //alert("Pick up job: " + $scope.data.recall.mr_pickup_job);
  176.             if ($scope.data.recall.mr_pickup_job=='true') {
  177.                 g_form.setValue("u_mr_pickup_job", 'Yes');
  178.             } else {
  179.                 g_form.setValue("u_mr_pickup_job", 'No');
  180.             }
  181.             g_form.setValue("u_mr_deliver_to", $scope.data.recall.mr_deliver_to);
  182.             g_form.setValue("u_mr_date_required", $scope.data.recall.mr_date_required);
  183.             g_form.setValue("u_mr_job_name", $scope.data.recall.mr_job_name);
  184.             g_form.setValue("u_mr_description", $scope.data.recall.mr_description);
  185.  
  186.             //g_form.setValue("u_mr_gl", $scope.data.recall.mr_gl);
  187.             g_form.setValue("u_mr_gl_account", $scope.data.recall.mr_gl_account);
  188.             g_form.setValue("u_mr_gl_workorder", $scope.data.recall.mr_gl_workorder);
  189.             g_form.setValue("u_mr_gl_fund", $scope.data.recall.mr_gl_fund);
  190.             g_form.setValue("u_mr_gl_cosunit", $scope.data.recall.mr_gl_cosunit);
  191.  
  192.             g_form.setValue("u_mr_reference_yn", $scope.data.recall.mr_reference_yn);
  193.             g_form.setValue("u_mr_reference_num", $scope.data.recall.mr_reference_num);
  194.         } else {
  195.             alert("Information Recall Error: Could not find a historical request to copy from. Please submit or add the current item to the cart before using the recall button.");
  196.             //alert("Information Recall Error: Could not find a historical request to copy from. Please submit or add the current item to the cart before using the recall button. UserID: " + $scope.data.recall.uID + ".");
  197.         }
  198.     });
  199.     ///////////////////
  200.  
  201.     /////////////////////////////////////////
  202.     // B9B - function to save users submitted info
  203.   /////////////////////////////////////////
  204.     function cacheUserInfo() {
  205.         var userId = $window.NOW.user_id; //user person at the computer
  206.         //alert("UserID: " + userId);
  207.  
  208.         alert("Starting script include");
  209.         var ga = new GlideAjax('SaveMarketingCacheData');
  210.         ga.addParam('sysparm_name','SaveCacheData');
  211.         ga.addParam('param_usr',userId);
  212.         ga.addParam('param_recipient',g_form.getValue('recipient'));
  213.         ga.addParam('param_backup',g_form.getValue('u_mr_backup_name'));
  214.         ga.addParam('param_pickup',g_form.getValue('u_mr_pickup_job'));
  215.         ga.addParam('param_deliver',g_form.getValue('u_mr_deliver_to'));
  216.         ga.addParam('param_date_r',g_form.getValue('u_mr_date_required'));
  217.         ga.addParam('param_name',g_form.getValue('u_mr_job_name'));
  218.         ga.addParam('param_desc',g_form.getValue('u_mr_description'));
  219.         ga.addParam('param_gl_a',g_form.getValue('u_mr_gl_account'));
  220.         ga.addParam('param_gl_w',g_form.getValue('u_mr_gl_workorder'));
  221.         ga.addParam('param_gl_f',g_form.getValue('u_mr_gl_fund'));
  222.         ga.addParam('param_gl_u',g_form.getValue('u_mr_gl_cosunit'));
  223.         ga.getXML(doSomething);
  224.        
  225.         function doSomething(response){
  226.             var answer = response.responseXML.documentElement.getAttribute("answer");
  227.             alert("Script Include complete", answer);
  228.         }
  229.     }
  230.  
  231.     ////////////
  232.    
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement