[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Settings/Currency/resources/ -> Currency.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  jQuery.Class('Settings_Currency_Js', {
  10      
  11      //holds the currency instance
  12      currencyInstance : false,
  13      
  14      /**
  15       * This function used to triggerAdd Currency
  16       */
  17      triggerAdd : function(event) {
  18          event.stopPropagation();
  19          var instance = Settings_Currency_Js.currencyInstance;
  20          instance.showEditView();
  21      },
  22      
  23      /**
  24       * This function used to trigger Edit Currency
  25       */
  26      triggerEdit : function(event, id) {
  27          event.stopPropagation();
  28          var instance = Settings_Currency_Js.currencyInstance;
  29          instance.showEditView(id);
  30      },
  31      
  32      /**
  33       * This function used to trigger Delete Currency
  34       */
  35      triggerDelete : function(event, id) {
  36          event.stopPropagation();
  37          var currentTarget = jQuery(event.currentTarget);
  38          var currentTrEle = currentTarget.closest('tr');
  39          var instance = Settings_Currency_Js.currencyInstance;
  40          instance.transformEdit(id).then(
  41              function(data) {
  42                  var callBackFunction = function(data) {
  43                      var form = jQuery('#transformCurrency');
  44                      
  45                      //register all select2 Elements
  46                      app.showSelect2ElementView(form.find('select.select2'));
  47                      
  48                      form.submit(function(e) {
  49                          e.preventDefault();
  50                          var transferCurrencyEle = form.find('select[name="transform_to_id"]');
  51                          instance.deleteCurrency(id, transferCurrencyEle, currentTrEle);
  52                      })
  53                  }
  54                  
  55                  app.showModalWindow(data,function(data){
  56                      if(typeof callBackFunction == 'function'){
  57                          callBackFunction(data);
  58                      }
  59                  }, {'width':'500px'});
  60              }, function(error, err) {
  61                  
  62              }
  63          );
  64      }
  65      
  66  }, {
  67      
  68      //constructor
  69      init : function() {
  70          Settings_Currency_Js.currencyInstance = this;
  71      },
  72      
  73      /*
  74       * function to show editView for Add/Edit Currency
  75       * @params: id - currencyId
  76       */
  77      showEditView : function(id) {
  78          var thisInstance = this;
  79          var aDeferred = jQuery.Deferred();
  80          
  81          var progressIndicatorElement = jQuery.progressIndicator({
  82              'position' : 'html',
  83              'blockInfo' : {
  84                  'enabled' : true
  85              }
  86          });
  87          
  88          var params = {};
  89          params['module'] = app.getModuleName();
  90          params['parent'] = app.getParentModuleName();
  91          params['view'] = 'EditAjax';
  92          params['record'] = id;
  93          
  94          AppConnector.request(params).then(
  95              function(data) {
  96                  var callBackFunction = function(data) {
  97                      var form = jQuery('#editCurrency');
  98                      var record = form.find('[name="record"]').val();
  99                      
 100                      //register all select2 Elements
 101                      app.showSelect2ElementView(form.find('select.select2'));
 102                      var currencyStatus = form.find('[name="currency_status"]').is(':checked');
 103                      if(record != '' && currencyStatus) {
 104                          //While editing currency, register the status change event
 105                          thisInstance.registerCurrencyStatusChangeEvent(form);
 106                      }
 107                      //If we change the currency name, change the code and symbol for that currency
 108                      thisInstance.registerCurrencyNameChangeEvent(form);
 109                      
 110                      var params = app.validationEngineOptions;
 111                      params.onValidationComplete = function(form, valid){
 112                          if(valid) {
 113                              thisInstance.saveCurrencyDetails(form);
 114                              return valid;
 115                          }
 116                      }
 117                      form.validationEngine(params);
 118                      
 119                      form.submit(function(e) {
 120                          e.preventDefault();
 121                      })
 122                  }
 123                  
 124                  progressIndicatorElement.progressIndicator({'mode' : 'hide'});
 125                  app.showModalWindow(data,function(data){
 126                      if(typeof callBackFunction == 'function'){
 127                          callBackFunction(data);
 128                      }
 129                  }, {'width':'600px'});
 130              },
 131              function(error) {
 132                  progressIndicatorElement.progressIndicator({'mode' : 'hide'});
 133                  //TODO : Handle error
 134                  aDeferred.reject(error);
 135              }
 136          );
 137          return aDeferred.promise();
 138      },
 139      
 140      /**
 141       * Register Change event for currency status
 142       */
 143      registerCurrencyStatusChangeEvent : function(form) {
 144          /*If the status changed to Inactive while editing currency, 
 145          currency should transfer to other existing currencies */
 146          form.find('[name="currency_status"]').on('change', function(e) {
 147              var currentTarget = jQuery(e.currentTarget);
 148              if(currentTarget.is(':checked')) {
 149                  form.find('div.transferCurrency').addClass('hide');
 150              } else {
 151                  form.find('div.transferCurrency').removeClass('hide');
 152              }
 153          })
 154      },
 155      
 156      /**
 157       * Register Change event for currency Name
 158       */
 159      registerCurrencyNameChangeEvent : function(form) {
 160          var currencyNameEle = form.find('select[name="currency_name"]');
 161          //on change of currencyName, update the currency code & symbol
 162          currencyNameEle.on('change', function() {
 163              var selectedCurrencyOption = currencyNameEle.find('option:selected');
 164              form.find('[name="currency_code"]').val(selectedCurrencyOption.data('code'));
 165              form.find('[name="currency_symbol"]').val(selectedCurrencyOption.data('symbol'));
 166          })
 167      },
 168      
 169      /**
 170       * This function will save the currency details
 171       */
 172      saveCurrencyDetails : function(form) {
 173          var thisInstance = this;
 174          var progressIndicatorElement = jQuery.progressIndicator({
 175              'position' : 'html',
 176              'blockInfo' : {
 177                  'enabled' : true
 178              }
 179          });
 180          
 181          var data = form.serializeFormData();
 182          data['module'] = app.getModuleName();
 183          data['parent'] = app.getParentModuleName();
 184          data['action'] = 'SaveAjax';
 185          
 186          AppConnector.request(data).then(
 187              function(data) {
 188                  if(data['success']) {
 189                      progressIndicatorElement.progressIndicator({'mode' : 'hide'});
 190                      app.hideModalWindow();
 191                      var params = {};
 192                      params.text = app.vtranslate('JS_CURRENCY_DETAILS_SAVED');
 193                      Settings_Vtiger_Index_Js.showMessage(params);
 194                      thisInstance.loadListViewContents();
 195                  }
 196              },
 197              function(error) {
 198                  progressIndicatorElement.progressIndicator({'mode' : 'hide'});
 199                  //TODO : Handle error
 200              }
 201          );
 202      },
 203      
 204      /**
 205       * This function will load the listView contents after Add/Edit currency
 206       */
 207      loadListViewContents : function() {
 208          var thisInstance = this;
 209          var progressIndicatorElement = jQuery.progressIndicator({
 210              'position' : 'html',
 211              'blockInfo' : {
 212                  'enabled' : true
 213              }
 214          });
 215          
 216          var params = {};
 217          params['module'] = app.getModuleName();
 218          params['parent'] = app.getParentModuleName();
 219          params['view'] = 'List';
 220          
 221          AppConnector.request(params).then(
 222              function(data) {
 223                  progressIndicatorElement.progressIndicator({'mode' : 'hide'});
 224                  //replace the new list view contents
 225                  jQuery('#listViewContents').html(data);
 226                  //thisInstance.triggerDisplayTypeEvent();
 227              }, function(error, err) {
 228                  progressIndicatorElement.progressIndicator({'mode' : 'hide'});
 229              }
 230          );
 231      },
 232      
 233      /**
 234       * This function will show the Transform Currency view while delete the currency
 235       */
 236      transformEdit : function(id) {
 237          var aDeferred = jQuery.Deferred();
 238          
 239          var params = {};
 240          params['module'] = app.getModuleName();
 241          params['parent'] = app.getParentModuleName();
 242          params['view'] = 'TransformEditAjax';
 243          params['record'] = id;
 244          
 245          AppConnector.request(params).then(
 246              function(data) {
 247                  aDeferred.resolve(data);
 248              }, function(error, err) {
 249                  aDeferred.reject();
 250              });
 251          return aDeferred.promise();
 252      },
 253      
 254      /**
 255       * This function will delete the currency and save the transferCurrency details
 256       */
 257      deleteCurrency : function(id, transferCurrencyEle, currentTrEle) {
 258          var transferCurrencyId = transferCurrencyEle.find('option:selected').val();
 259          var params = {};
 260          params['module'] = app.getModuleName();
 261          params['parent'] = app.getParentModuleName();
 262          params['action'] = 'DeleteAjax';
 263          params['record'] = id;
 264          params['transform_to_id'] = transferCurrencyId;
 265          
 266          AppConnector.request(params).then(
 267              function(data) {
 268                  app.hideModalWindow();
 269                  var params = {};
 270                  params.text = app.vtranslate('JS_CURRENCY_DELETED_SUEESSFULLY');
 271                  Settings_Vtiger_Index_Js.showMessage(params);
 272                  currentTrEle.fadeOut('slow').remove();
 273              }, function(error, err) {
 274                  
 275              });
 276      },
 277      
 278      triggerDisplayTypeEvent : function() {
 279          var widthType = app.cacheGet('widthType', 'narrowWidthType');
 280          if(widthType) {
 281              var elements = jQuery('.listViewEntriesTable').find('td,th');
 282              elements.attr('class', widthType);
 283          }
 284      },
 285      
 286      registerRowClick : function() {
 287        var thisInstance = this;
 288        jQuery('#listViewContents').on('click','.listViewEntries',function(e) {
 289            var currentRow = jQuery(e.currentTarget);
 290            if(currentRow.find('.icon-pencil ').length <= 0) {
 291                return;
 292            } 
 293            thisInstance.showEditView(currentRow.data('id'));
 294        })  
 295      },
 296      
 297      registerEvents : function() {
 298          this.registerRowClick();
 299      }
 300      
 301  });
 302  
 303  jQuery(document).ready(function(){
 304      var currencyInstance = new Settings_Currency_Js();
 305      currencyInstance.registerEvents();
 306  })


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