[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/pkg/vtiger/modules/RecycleBin/templates/resources/ -> List.js (source)

   1  /*+***********************************************************************************
   2   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   3   * ("License"); You may not use this file except in compliance with the License
   4   * The Original Code is:  vtiger CRM Open Source
   5   * The Initial Developer of the Original Code is vtiger.
   6   * Portions created by vtiger are Copyright (C) vtiger.
   7   * All Rights Reserved.
   8   *************************************************************************************/
   9  
  10  Vtiger_List_Js("RecycleBin_List_Js", {
  11      emptyRecycleBin: function(url) {
  12          var message = app.vtranslate('JS_MSG_EMPTY_RB_CONFIRMATION');
  13          Vtiger_Helper_Js.showConfirmationBox({'message': message}).then(
  14                  function(e) {
  15                      var deleteURL = url + '&mode=emptyRecycleBin';
  16                      var instance = new RecycleBin_List_Js();
  17                      AppConnector.request(deleteURL).then(
  18                              function(data) {
  19                                  if (data) {
  20                                      //fix for EmptyRecycle bin 
  21                                      jQuery(".clearRecycleBin").attr('disabled','disabled'); 
  22                                      instance.recycleBinActionPostOperations(data);
  23                                  }
  24                              }
  25                      );
  26                  },
  27                  function(error, err) {
  28                  })
  29      },
  30      deleteRecords: function(url) {
  31          var listInstance = Vtiger_List_Js.getInstance();
  32          var validationResult = listInstance.checkListRecordSelected();
  33          if (validationResult != true) {
  34              var selectedIds = listInstance.readSelectedIds(true);
  35              var cvId = listInstance.getCurrentCvId();
  36              var message = app.vtranslate('LBL_MASS_DELETE_CONFIRMATION');
  37              Vtiger_Helper_Js.showConfirmationBox({'message': message}).then(
  38                      function(e) {
  39                          var sourceModule = jQuery('#customFilter').val();
  40                          var deleteURL = url + '&viewname=' + cvId + '&selected_ids=' + selectedIds + '&mode=deleteRecords&sourceModule=' + sourceModule;
  41                          var deleteMessage = app.vtranslate('JS_RECORDS_ARE_GETTING_DELETED');
  42                          var progressIndicatorElement = jQuery.progressIndicator({
  43                              'message': deleteMessage,
  44                              'position': 'html',
  45                              'blockInfo': {
  46                                  'enabled': true
  47                              }
  48                          });
  49                          AppConnector.request(deleteURL).then(
  50                                  function(data) {
  51                                      if (data) {
  52                                          progressIndicatorElement.progressIndicator({
  53                                              'mode': 'hide'
  54                                          })
  55                                          var instance = new RecycleBin_List_Js();
  56                                          instance.recycleBinActionPostOperations(data);
  57                                      }
  58                                  }
  59                          );
  60                      },
  61                      function(error, err) {
  62                      })
  63          } else {
  64              listInstance.noRecordSelectedAlert();
  65          }
  66  
  67      },
  68      restoreRecords: function(url) {
  69          var listInstance = Vtiger_List_Js.getInstance();
  70          var validationResult = listInstance.checkListRecordSelected();
  71          if (validationResult != true) {
  72              var selectedIds = listInstance.readSelectedIds(true);
  73              var excludedIds = listInstance.readExcludedIds(true);
  74              var cvId = listInstance.getCurrentCvId();
  75              var message = app.vtranslate('JS_LBL_RESTORE_RECORDS_CONFIRMATION');
  76              Vtiger_Helper_Js.showConfirmationBox({'message': message}).then(
  77                      function(e) {
  78                          var sourceModule = jQuery('#customFilter').val();
  79                          var deleteURL = url + '&viewname=' + cvId + '&selected_ids=' + selectedIds + '&excluded_ids=' + excludedIds + '&mode=restoreRecords&sourceModule=' + sourceModule;
  80                          var restoreMessage = app.vtranslate('JS_RESTORING_RECORDS');
  81                          var progressIndicatorElement = jQuery.progressIndicator({
  82                              'message': restoreMessage,
  83                              'position': 'html',
  84                              'blockInfo': {
  85                                  'enabled': true
  86                              }
  87                          });
  88                          AppConnector.request(deleteURL).then(
  89                                  function(data) {
  90                                      if (data) {
  91                                          progressIndicatorElement.progressIndicator({
  92                                              'mode': 'hide'
  93                                          })
  94                                          var instance = new RecycleBin_List_Js();
  95                                          instance.recycleBinActionPostOperations(data);
  96                                      }
  97                                  }
  98                          );
  99                      },
 100                      function(error, err) {
 101                      })
 102          } else {
 103              listInstance.noRecordSelectedAlert();
 104          }
 105      },
 106      
 107      /**
 108       * Function to convert id into json string
 109       * @param <integer> id
 110       * @return <string> json string
 111       */
 112      convertToJsonString : function(id) {
 113          var jsonObject = [];
 114          jsonObject.push(id);
 115          return JSON.stringify(jsonObject);
 116      },
 117  
 118         
 119      /**
 120       * Function to delete a record
 121       */
 122      deleteRecord : function(recordId) {
 123          var recordId = RecycleBin_List_Js.convertToJsonString(recordId);
 124          var listInstance = Vtiger_List_Js.getInstance();
 125          var message = app.vtranslate('LBL_DELETE_CONFIRMATION');
 126          var sourceModule = jQuery('#customFilter').val();
 127          var cvId = listInstance.getCurrentCvId();
 128          Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then(
 129              function(e) {
 130                  var module = app.getModuleName();
 131                  var postData = {
 132                      "module": module,
 133                      "viewname": cvId,
 134                      "selected_ids": recordId,
 135                      "action": "RecycleBinAjax",
 136                      "sourceModule": sourceModule,
 137                      "mode": "deleteRecords"
 138                  }
 139                  var deleteMessage = app.vtranslate('JS_RECORD_GETTING_DELETED');
 140                  var progressIndicatorElement = jQuery.progressIndicator({
 141                      'message' : deleteMessage,
 142                      'position' : 'html',
 143                      'blockInfo' : {
 144                          'enabled' : true
 145                      }
 146                  });
 147                  AppConnector.request(postData).then(
 148                      function(data) {
 149                          if(data){
 150                              progressIndicatorElement.progressIndicator({
 151                                  'mode' : 'hide'
 152                              })
 153                              var instance = new RecycleBin_List_Js();
 154                              instance.recycleBinActionPostOperations(data);
 155                          }
 156                      }
 157                  );
 158              },
 159              function(error, err){
 160              });
 161      },
 162      
 163      /**
 164      * Function to restore a record
 165      */
 166      restoreRecord : function(recordId){
 167          var recordId = RecycleBin_List_Js.convertToJsonString(recordId);
 168          var listInstance = Vtiger_List_Js.getInstance();
 169          var sourceModule = jQuery('#customFilter').val();
 170          var cvId = listInstance.getCurrentCvId();
 171          var message = app.vtranslate('JS_LBL_RESTORE_RECORD_CONFIRMATION');
 172          Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then(
 173              function(e) {
 174                  var module = app.getModuleName();
 175                  var postData = {
 176                      "module": module,
 177                      "action": "RecycleBinAjax",
 178                      "viewname": cvId,
 179                      "selected_ids": recordId,
 180                      "mode": "restoreRecords",
 181                      "sourceModule": sourceModule
 182                  }
 183                  var restoreMessage = app.vtranslate('JS_RESTORING_RECORD');
 184                  var progressIndicatorElement = jQuery.progressIndicator({
 185                      'message' : restoreMessage,
 186                      'position' : 'html',
 187                      'blockInfo' : {
 188                          'enabled' : true
 189                      }
 190                  });
 191                  AppConnector.request(postData).then(
 192                      function(data) {
 193                          if(data){
 194                              progressIndicatorElement.progressIndicator({
 195                                  'mode' : 'hide'
 196                              })
 197                              var instance = new RecycleBin_List_Js();
 198                              instance.recycleBinActionPostOperations(data);
 199                          }
 200                      }
 201                  );
 202              },
 203              function(error, err){
 204              });
 205      }
 206  
 207  }, { 
 208      
 209      
 210          //Fix for empty Recycle bin
 211          //Change Button State ("Enable or Dissable") 
 212         ListViewPostOperation: function() {
 213               if(parseInt(jQuery('#deletedRecordsTotalCount').val()) == 0){ 
 214                  jQuery(".clearRecycleBin").attr('disabled','disabled'); 
 215              }else{ 
 216                      jQuery(".clearRecycleBin").removeAttr('disabled'); 
 217              }
 218         },
 219         
 220      getDefaultParams : function() {
 221          var pageNumber = jQuery('#pageNumber').val();
 222          var module = app.getModuleName();
 223          var parent = app.getParentModuleName();
 224          var cvId = this.getCurrentCvId();
 225          var orderBy = jQuery('#orderBy').val();
 226          var sortOrder = jQuery("#sortOrder").val();
 227          var params = {
 228              'module': module,
 229              'parent' : parent,
 230              'page' : pageNumber,
 231              'view' : "List",
 232              'orderby' : orderBy,
 233              'sortorder' : sortOrder,
 234              'sourceModule' : jQuery('#customFilter').val()
 235          }
 236          return params;
 237      },
 238      /*
 239       * Function to perform the operations after the Empty RecycleBin
 240       */
 241      recycleBinActionPostOperations : function(data){
 242          jQuery('#recordsCount').val('');
 243          jQuery('#totalPageCount').text('');
 244          var thisInstance = this;
 245          var cvId = this.getCurrentCvId();
 246          if(data.success){
 247              var module = app.getModuleName();
 248              var params = thisInstance.getDefaultParams();
 249              AppConnector.request(params).then(
 250                  function(data) {
 251                      app.hideModalWindow();
 252                      var listViewContainer = thisInstance.getListViewContentContainer();
 253                      listViewContainer.html(data);
 254                      jQuery('#deSelectAllMsg').trigger('click');
 255                                          thisInstance.ListViewPostOperation();
 256                      thisInstance.calculatePages().then(function(){
 257                          thisInstance.updatePagination();                    
 258                      });
 259                  });
 260          } else {
 261              app.hideModalWindow();
 262              var params = {
 263                  title : app.vtranslate('JS_LBL_PERMISSION'),
 264                  text : data.error.message
 265              }
 266              Vtiger_Helper_Js.showPnotify(params);
 267          }
 268      },
 269      
 270      getRecordsCount : function(){
 271          var aDeferred = jQuery.Deferred();
 272          var recordCountVal = jQuery("#recordsCount").val();
 273          if(recordCountVal != ''){
 274              aDeferred.resolve(recordCountVal);
 275          } else {
 276              var count = '';
 277              var module = app.getModuleName();
 278              var sourceModule = jQuery('#customFilter').val();
 279              var postData = {
 280                  "module": module,
 281                  "sourceModule": sourceModule,
 282                  "view": "ListAjax",
 283                  "mode": "getRecordsCount"
 284              }
 285  
 286              AppConnector.request(postData).then(
 287                  function(data) {
 288                      var response = JSON.parse(data);
 289                      jQuery("#recordsCount").val(response['result']['count']);
 290                      count =  response['result']['count'];
 291                      aDeferred.resolve(count);
 292                  },
 293                  function(error,err){
 294  
 295                  }
 296              );
 297          }
 298  
 299          return aDeferred.promise();
 300      },
 301      
 302      /**
 303       * Function to get Page Jump Params
 304       */
 305      getPageJumpParams : function(){
 306          var module = app.getModuleName();
 307          var cvId = this.getCurrentCvId();
 308          var pageCountParams = {
 309              'module' : module,
 310              'view' : "ListAjax",
 311              'mode' : "getPageCount",
 312              'sourceModule': jQuery('#sourceModule').val()
 313          }
 314          return pageCountParams;
 315      },
 316      
 317      /*
 318       * Function to register the list view delete record click event
 319       */
 320      registerDeleteRecordClickEvent: function(){
 321          var thisInstance = this;
 322          var listViewContentDiv = this.getListViewContentContainer();
 323          listViewContentDiv.on('click','.deleteRecordButton',function(e){
 324              var elem = jQuery(e.currentTarget);
 325              var recordId = elem.closest('tr').data('id');
 326              RecycleBin_List_Js.deleteRecord(recordId);
 327              e.stopPropagation();
 328          });
 329      }, 
 330      
 331       /*
 332       * Function to register the list view restore record click event
 333       */
 334      registerRestoreRecordClickEvent: function(){
 335          var thisInstance = this;
 336          var listViewContentDiv = this.getListViewContentContainer();
 337          listViewContentDiv.on('click','.restoreRecordButton',function(e){
 338              var elem = jQuery(e.currentTarget);
 339              var recordId = elem.closest('tr').data('id');
 340              RecycleBin_List_Js.restoreRecord(recordId);
 341              e.stopPropagation();
 342          });
 343      },
 344      
 345      registerEvents : function() {
 346          this._super();
 347          this.registerRestoreRecordClickEvent();
 348      }
 349  });


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1