Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ($scope, $http, spUtil, nowAttachmentHandler, $rootScope, $sanitize, $window, $sce, i18n) {
- var c = this;
- c.quantity = 1;
- $scope.data.sc_cat_item.description = $sce.trustAsHtml($scope.data.sc_cat_item.description);
- c.widget._debugContextMenu = [
- [ i18n.getMessage("Open") + " sc_cat_item", function(){
- var item = c.data.sc_cat_item;
- $window.open("/$sp.do?id=form&table=" + item.table + "&sys_id=" + item.sys_id); }]
- ];
- c.showAddCartBtn = function() {
- return c.options.show_add_cart_button &&
- c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
- !c.data.sc_cat_item.no_cart;
- }
- c.showQuantitySelector = function() {
- return c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
- !c.data.sc_cat_item.no_quantity;
- }
- $scope.$on('dialog.upload_too_large.show', function(e){
- console.log($scope.m.largeAttachmentMsg);
- spUtil.addErrorMessage($scope.m.largeAttachmentMsg);
- });
- $scope.m = $scope.data.msgs;
- $scope.submitButtonMsg = $scope.m.submitMsg;
- var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function() {});
- ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * 24);
- function setAttachments(attachments, action) {
- $scope.attachments = attachments;
- }
- $scope.attachmentHandler.getAttachmentList();
- $scope.confirmDeleteAttachment = function(attachment, $event) {
- $rootScope.$broadcast("dialog.delete_attachment.show", {
- parms: {
- ok: function() {
- $scope.attachmentHandler.deleteAttachment(attachment);
- $rootScope.$broadcast("dialog.delete_attachment.close");
- },
- cancel: function() {
- $rootScope.$broadcast("dialog.delete_attachment.close");
- },
- details: attachment.name
- }
- })
- }
- // Breadcrumbs
- if ($scope.data.sc_cat_item) {
- var bc = [{label: $scope.page.title, url: '?id=' + $scope.data.sc_catalog_page}];
- if ($scope.data.category)
- bc[bc.length] = {label: $scope.data.category.name, url: $scope.data.category.url};
- bc[bc.length] = {label: $scope.data.sc_cat_item.name, url: '#'};
- $rootScope.$broadcast('sp.update.breadcrumbs', bc);
- spUtil.setSearchPage('sc');
- }
- var g_form;
- $scope.$on('spModel.gForm.initialized', function(e, gFormInstance){
- g_form = gFormInstance;
- // This runs after all onSubmit scripts have executed
- g_form.$private.events.on('submitted', function(){
- if ($scope.data.sc_cat_item.item_action === "order")
- getOne();
- else if ($scope.data.sc_cat_item.item_action === "add_to_cart")
- addToCart();
- });
- });
- $scope.triggerAddToCart = function() {
- $scope.data.sc_cat_item.item_action = "add_to_cart";
- $scope.data.sc_cat_item.quantity = c.quantity;
- if (g_form)
- g_form.submit();
- }
- $scope.triggerOnSubmit = function(){
- //alert("Submit pressed")
- $scope.data.sc_cat_item.item_action = "order";
- $scope.data.sc_cat_item.quantity = c.quantity;
- //if (g_form)
- //g_form.submit();
- cacheUserInfo();
- }
- // order / create request
- function getOne() {
- postCatalogFormRequest().success(function(response) {
- var a = response.answer;
- var n = a.number;
- $scope.$emit("$$uiNotification", response.$$uiNotification);
- $scope.$emit("$sp.sc_cat_item.submitted", a);
- if (n)
- issueMessage(n, a.table, a.sys_id);
- $scope.submitting = false;
- $scope.submitButtonMsg = $scope.m.submittedMsg;
- });
- }
- function addToCart() {
- postCatalogFormRequest().success(function(response) {
- $rootScope.$broadcast("$sp.service_catalog.cart.add_item");
- $rootScope.$broadcast("$sp.service_catalog.cart.update");
- //spUtil.addInfoMessage("Added item to shopping cart");
- $scope.submitting = false;
- });
- }
- function postCatalogFormRequest() {
- setFieldsReadonly();
- $scope.submitted = true;
- $scope.submitting = true;
- var t = $scope.data.sc_cat_item;
- t._attachmentGUID = $scope.data._attachmentGUID;
- // calls into SPCatalogForm.getItem()
- return $http.post(spUtil.getURL('sc_cat_item'), t);
- }
- // spModel populates mandatory - hasMandatory is called by the submit button
- $scope.hasMandatory = function(mandatory) {
- return mandatory && mandatory.length > 0;
- };
- // switch catalog items
- var unregister = $scope.$on('$sp.list.click', onListClick);
- $scope.$on("$destroy", function() {
- unregister();
- });
- function onListClick(evt, arg) {
- $scope.data.sys_id = arg.sys_id;
- spUtil.update($scope);
- }
- function setFieldsReadonly(){
- var allFields = g_form.getFieldNames();
- for(var fieldName in allFields){
- g_form.setReadOnly(allFields[fieldName], true);
- }
- }
- function issueMessage(n, table, sys_id) {
- var page = table == 'sc_request' ? 'sc_request' : 'ticket';
- if (c.options.page) {page = c.options.page;}
- if (c.options.table) {table = c.options.table;}
- var url = spUtil.format(c.options.url, {page: page, table: table, sys_id: sys_id});
- if (c.options.auto_redirect == "true") {
- $window.location.href = url;
- return;
- }
- var t = $scope.m.createdMsg + " " + n + " - ";
- t += $scope.m.trackMsg;
- t += ' <a href="' + url + '">' + $scope.m.clickMsg + '</a>';
- spUtil.addInfoMessage(t);
- }
- /////////////////////////////////////////////////////////////////////////////////////
- // B9B - remote widget recall button code - place the data from the cache table on the form
- /////////////////////////////////////////////////////////////////////////////////////
- $rootScope.$on('customEvent', function(event,obj) {
- //alert("Recall triggered");
- //alert("Found value: " + $scope.data.recall.found);
- if ($scope.data.recall.found==true) {
- //alert("User history found. UserID: " + $scope.data.recall.uID);
- g_form.setValue("u_mr_recipient", $scope.data.recall.mr_recipient);
- g_form.setValue("u_mr_backup_name", $scope.data.recall.mr_backup_name);
- //alert("Pick up job: " + $scope.data.recall.mr_pickup_job);
- if ($scope.data.recall.mr_pickup_job=='true') {
- g_form.setValue("u_mr_pickup_job", 'Yes');
- } else {
- g_form.setValue("u_mr_pickup_job", 'No');
- }
- g_form.setValue("u_mr_deliver_to", $scope.data.recall.mr_deliver_to);
- g_form.setValue("u_mr_date_required", $scope.data.recall.mr_date_required);
- g_form.setValue("u_mr_job_name", $scope.data.recall.mr_job_name);
- g_form.setValue("u_mr_description", $scope.data.recall.mr_description);
- //g_form.setValue("u_mr_gl", $scope.data.recall.mr_gl);
- g_form.setValue("u_mr_gl_account", $scope.data.recall.mr_gl_account);
- g_form.setValue("u_mr_gl_workorder", $scope.data.recall.mr_gl_workorder);
- g_form.setValue("u_mr_gl_fund", $scope.data.recall.mr_gl_fund);
- g_form.setValue("u_mr_gl_cosunit", $scope.data.recall.mr_gl_cosunit);
- g_form.setValue("u_mr_reference_yn", $scope.data.recall.mr_reference_yn);
- g_form.setValue("u_mr_reference_num", $scope.data.recall.mr_reference_num);
- } else {
- 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.");
- //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 + ".");
- }
- });
- ///////////////////
- /////////////////////////////////////////
- // B9B - function to save users submitted info
- /////////////////////////////////////////
- function cacheUserInfo() {
- var userId = $window.NOW.user_id; //user person at the computer
- //alert("UserID: " + userId);
- alert("Starting script include");
- var ga = new GlideAjax('SaveMarketingCacheData');
- ga.addParam('sysparm_name','SaveCacheData');
- ga.addParam('param_usr',userId);
- ga.addParam('param_recipient',g_form.getValue('recipient'));
- ga.addParam('param_backup',g_form.getValue('u_mr_backup_name'));
- ga.addParam('param_pickup',g_form.getValue('u_mr_pickup_job'));
- ga.addParam('param_deliver',g_form.getValue('u_mr_deliver_to'));
- ga.addParam('param_date_r',g_form.getValue('u_mr_date_required'));
- ga.addParam('param_name',g_form.getValue('u_mr_job_name'));
- ga.addParam('param_desc',g_form.getValue('u_mr_description'));
- ga.addParam('param_gl_a',g_form.getValue('u_mr_gl_account'));
- ga.addParam('param_gl_w',g_form.getValue('u_mr_gl_workorder'));
- ga.addParam('param_gl_f',g_form.getValue('u_mr_gl_fund'));
- ga.addParam('param_gl_u',g_form.getValue('u_mr_gl_cosunit'));
- ga.getXML(doSomething);
- function doSomething(response){
- var answer = response.responseXML.documentElement.getAttribute("answer");
- alert("Script Include complete", answer);
- }
- }
- ////////////
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement