f1lam3ntx0

TKMB2B_MultipleCCSpecProductCMPController

Sep 24th, 2020
966
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ({
  2.     doinit: function (component, event, helper) {
  3.         component.set('v.columns', [
  4.             { label: 'Name', fieldName: 'Name', type: 'text' },
  5.             { label: 'SKU', fieldName: 'ccrz__SKU__c', type: 'text' },
  6.            
  7.         ]);
  8.  
  9.  
  10.        var action = component.get('c.getAllProducts');
  11.         action.setCallback(this , function(response){
  12.                            var state = response.getState();
  13.         if(state === 'SUCCESS' || stare === 'DRAFT')
  14.         {
  15.             var responsevalue = response.getReturnValue();
  16.             component.set('v.data', responsevalue);
  17.         }
  18.                            }
  19.     },
  20.  
  21.    
  22. });
  23.  
  24. ({
  25.     doinit: function(component, event, helper) {
  26.        // alert('doinit');   // to check if doinit is working or not : seems it works but i couldn't seet the preview !!
  27.         component.set('v.columns', [
  28.             {label: 'Product Name', fieldName: 'Name', type: 'text'},
  29.             {label: 'SKU', fieldName: 'ccrz__SKU__c', type: 'text'}
  30.         ]);
  31.         var action = component.get("c.fetchAllProducts"); // this wil get the method getAllProducts form the controller(apex class:TKMB2B_Custom_CC_Spec_Product_Selection).
  32.         action.setCallback(this, function(response){
  33.             var state = response.getState();
  34.             //alert(state); // to check for the State to work !
  35.             if(state == "SUCCESS")
  36.             {
  37.                     var responsevalue = response.getReturnValue();
  38.                     component.set("v.data", responsevalue);
  39.             }
  40.            
  41.         });
  42.         $A.enqueueAction(action);
  43.     },
  44.      
  45.     doselectproduct : function(component , event, helper)   // this will give us the functionality to select the products individually
  46.     {
  47.        // alert('record element selected');
  48.         var selectedProduct = event.getParam('selectedRows');
  49.        component.set("v.clearBtn",selectedProduct );
  50.         console.log('selectedProduct', selectedProduct);
  51.     },
  52.     handleClick : function(component , event , helper)
  53.     {
  54.        
  55.         console.log(JSON.parse(JSON.stringify(component.find('productTable').getSelectedRows())));
  56.         console.log(component.get("v.recordId"));
  57.         var action  = component.get("c.updateSpec");
  58.         action.setParams({savedProducts : JSON.parse(JSON.stringify(component.find('productTable').getSelectedRows())), specId : component.get("v.recordId")});
  59.         action.setCallback(this, $A.getCallback(function (response) {
  60.             var state = response.getState();
  61.             console.log('response'+ response.getReturnValue());
  62.             var res = response.getReturnValue();
  63.             if (state === "SUCCESS")
  64.             {
  65.                 $A.get("e.force:closeQuickAction").fire();
  66.             }
  67.         }));
  68.         $A.enqueueAction(action);
  69.        
  70.     },
  71.     clearClick : function(component , event , helper)
  72.     {
  73.        
  74.         var selectedProduct =  component.get("v.clearBtn");
  75.        // var clearProduct  = event.set("v.selectedProduct", []);
  76.         debugger;
  77.         for(var i in selectedProduct ){
  78.             debugger;
  79.              var space =selectedProduct[i];
  80.             $("#"+space.Id).prop('checked', false);
  81.             alert('eachloop');
  82.         }
  83.        
  84.         console.log('clearProduct',clearProduct );
  85.     },
  86.         searchKeyChange: function(component, event, handler) {
  87.         var searchKey = component.find("searchKey").get("v.value");
  88.         console.log('searchKey:::::'+searchKey);
  89.         var action = component.get("c.findByName");
  90.         action.setParams({
  91.             "searchKey": searchKey
  92.         });
  93.         action.setCallback(this, function(a) {
  94.             component.set("v.productTable", a.getReturnValue());
  95.         });
  96.         $A.enqueueAction(action);
  97.     }   ,
  98.     Search: function(component, event, helper) {
  99.         var searchField = component.find('searchField');
  100.         var isValueMissing = searchField.get('v.validity').valueMissing;
  101.         // if value is missing show error message and focus on field
  102.         if(isValueMissing) {
  103.             searchField.showHelpMessageIfInvalid();
  104.             searchField.focus();
  105.         }else{
  106.           // else call helper function
  107.             helper.SearchHelper(component, event);
  108.         }
  109.     },
  110.     /*searchTable : function(component,event,helper) {
  111.         var allRecords = component.get("v.productTable");
  112.         alert('searchME');
  113.         var searchFilter = event.getSource().get("v.value").toUpperCase();
  114.         var tempArray = [];
  115.         var i;
  116.         for(i=0; i < allRecords.length; i++){
  117.             if((allRecords[i].Name && allRecords[i].Name.toUpperCase().indexOf(searchFilter) != -1) ||
  118.                (allRecords[i].ccrz__SKU__c && allRecords[i].ccrz__SKU__c.toUpperCase().indexOf(searchFilter) != -1 ))
  119.             {
  120.                 tempArray.push(allRecords[i]);
  121.             }
  122.     }
  123.         component.set("v.filteredData",tempArray);
  124.     },
  125.    
  126.     handleKeyUp: function (component, event) {
  127.         var isEnterKey = event.keyCode === 13;
  128.         var queryTerm = cmp.find('enter-search').get('v.value');
  129.         if (isEnterKey) {
  130.             component.set('v.issearching', true);  
  131.             setTimeout(function() {
  132.                 alert('Searched for "' + queryTerm + '"!');
  133.                 component.set('v.issearching', false);
  134.             }, 2000);
  135.         }
  136.     }
  137.     */
  138. })
RAW Paste Data