[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Leads/resources/ -> Detail.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_Detail_Js("Leads_Detail_Js",{
  11      
  12      //cache will store the convert lead data(Model)
  13      cache : {},
  14      
  15      //Holds detail view instance
  16      detailCurrentInstance : false,
  17      
  18      /*
  19       * function to trigger Convert Lead action
  20       * @param: Convert Lead url, currentElement.
  21       */
  22      convertLead : function(convertLeadUrl, buttonElement) {
  23          var instance = Leads_Detail_Js.detailCurrentInstance;
  24          //Initially clear the elements to overwtite earliear cache
  25          instance.convertLeadContainer = false;
  26          instance.convertLeadForm = false;
  27          instance.convertLeadModules = false;
  28          if(jQuery.isEmptyObject(Leads_Detail_Js.cache)) {
  29              AppConnector.request(convertLeadUrl).then(
  30                  function(data) {
  31                      if(data) {
  32                          Leads_Detail_Js.cache = data;
  33                          instance.displayConvertLeadModel(data, buttonElement);
  34                      }
  35                  },
  36                  function(error,err){
  37  
  38                  }
  39              );
  40          } else {
  41              instance.displayConvertLeadModel(Leads_Detail_Js.cache, buttonElement);
  42          }
  43      }
  44      
  45  },{
  46      //Contains the convert lead form
  47      convertLeadForm : false,
  48      
  49      //contains the convert lead container
  50      convertLeadContainer : false,
  51      
  52      //contains all the checkbox elements of modules
  53      convertLeadModules : false,
  54      
  55      //constructor
  56      init : function() {
  57          this._super();
  58          Leads_Detail_Js.detailCurrentInstance = this;
  59      },
  60      
  61      /*
  62       * function to disable the Convert Lead button
  63       */
  64      disableConvertLeadButton : function(button) {
  65          jQuery(button).attr('disabled','disabled');
  66      },
  67      
  68      /*
  69       * function to enable the Convert Lead button
  70       */
  71      enableConvertLeadButton : function(button) {
  72          jQuery(button).removeAttr('disabled');
  73      },
  74      
  75      /*
  76       * function to enable all the input and textarea elements
  77       */
  78      removeDisableAttr : function(moduleBlock) {
  79          moduleBlock.find('input,textarea,select').removeAttr('disabled');
  80      },
  81      
  82      /*
  83       * function to disable all the input and textarea elements
  84       */
  85      addDisableAttr : function(moduleBlock) {
  86          moduleBlock.find('input,textarea,select').attr('disabled', 'disabled');
  87      },
  88      
  89      /*
  90       * function to display the convert lead model
  91       * @param: data used to show the model, currentElement.
  92       */
  93      displayConvertLeadModel : function(data, buttonElement) {
  94          var instance = this;
  95          var errorElement = jQuery(data).find('#convertLeadError');
  96          if(errorElement.length != '0') {
  97              var errorMsg = errorElement.val();
  98              var errorTitle = jQuery(data).find('#convertLeadErrorTitle').val();
  99              var params = {
 100                  title: errorTitle,
 101                  text: errorMsg,
 102                  addclass: "convertLeadNotify",
 103                  width: '35%',
 104                  pnotify_after_open: function(){
 105                      instance.disableConvertLeadButton(buttonElement);
 106                  },
 107                  pnotify_after_close: function(){
 108                      instance.enableConvertLeadButton(buttonElement);
 109                  }
 110              }
 111              Vtiger_Helper_Js.showPnotify(params);
 112          } else {
 113              var callBackFunction = function(data){
 114                  var editViewObj = Vtiger_Edit_Js.getInstance();
 115                  jQuery(data).find('.fieldInfo').collapse({
 116                      'parent': '#leadAccordion',
 117                      'toggle' : false
 118                  });
 119                  app.showScrollBar(jQuery(data).find('#leadAccordion'), {'height':'350px'});
 120                  editViewObj.registerBasicEvents(data);
 121                  var checkBoxElements = instance.getConvertLeadModules();
 122                  jQuery.each(checkBoxElements, function(index, element){
 123                      instance.checkingModuleSelection(element);
 124                  });
 125                  instance.registerForReferenceField();
 126                  instance.registerForDisableCheckEvent();
 127                  instance.registerConvertLeadEvents();
 128                  instance.getConvertLeadForm().validationEngine(app.validationEngineOptions);
 129                  instance.registerConvertLeadSubmit();
 130              }
 131              app.showModalWindow(data,function(data){
 132                  if(typeof callBackFunction == 'function'){
 133                      callBackFunction(data);
 134                  }
 135              },{
 136                  'text-align' : 'left'
 137              });
 138          }
 139      },
 140      
 141      /*
 142       * function to check which module is selected 
 143       * to disable or enable all the elements with in the block
 144       */
 145      checkingModuleSelection : function(element) {
 146          var instance = this;
 147          var module = jQuery(element).val();
 148          var moduleBlock = jQuery(element).closest('.accordion-group').find('#'+module+'_FieldInfo');
 149          if(jQuery(element).is(':checked')) {
 150              instance.removeDisableAttr(moduleBlock);
 151          } else {
 152              instance.addDisableAttr(moduleBlock);
 153          }
 154      },
 155  
 156      registerForReferenceField : function() {
 157          var container = this.getConvertLeadContainer();
 158          var referenceField = jQuery('.reference', container);
 159          if(referenceField.length > 0) {
 160              jQuery('#AccountsModule').attr('readonly', 'readonly');
 161          }
 162      },
 163      registerForDisableCheckEvent : function() {
 164          var instance = this;
 165          var container = this.getConvertLeadContainer();
 166          var referenceField = jQuery('.reference', container);
 167          var oppAccMandatory = jQuery('#oppAccMandatory').val();
 168          var oppConMandatory = jQuery('#oppConMandatory').val();
 169          var conAccMandatory = jQuery('#conAccMandatory').val();
 170          
 171          jQuery('#PotentialsModule').on('click',function(){
 172              if((jQuery('#PotentialsModule').is(':checked')) && oppAccMandatory) {
 173                  jQuery('#AccountsModule').attr({'disabled':'disabled','checked':'checked'});
 174              }else if(!conAccMandatory || !jQuery('#ContactsModule').is(':checked')) {
 175                  jQuery('#AccountsModule').removeAttr('disabled');
 176              }
 177              if((jQuery('#PotentialsModule').is(':checked')) && oppConMandatory) {
 178                  jQuery('#ContactsModule').attr({'disabled':'disabled','checked':'checked'});
 179              }else {
 180                  jQuery('#ContactsModule').removeAttr('disabled');
 181              } 
 182          });
 183          jQuery('#ContactsModule').on('click',function(){
 184              if((jQuery('#ContactsModule').is(':checked')) && conAccMandatory) {
 185                  jQuery('#AccountsModule').attr({'disabled':'disabled','checked':'checked'});
 186              }else if(!oppAccMandatory || !jQuery('#PotentialsModule').is(':checked')) {
 187                  jQuery('#AccountsModule').removeAttr('disabled');
 188              } 
 189          });
 190      },
 191  
 192      /*
 193       * function to register Convert Lead Events
 194       */
 195      registerConvertLeadEvents : function() {
 196          var container = this.getConvertLeadContainer();
 197          var instance = this;
 198          
 199          //Trigger Event to change the icon while shown and hidden the accordion body 
 200          container.on('hidden', '.accordion-body', function(e){
 201              var currentTarget = jQuery(e.currentTarget);
 202              currentTarget.closest('.convertLeadModules').find('.iconArrow').removeClass('icon-chevron-up').addClass('icon-chevron-down');
 203          }).on('shown', '.accordion-body', function(e){
 204              var currentTarget = jQuery(e.currentTarget);
 205              currentTarget.closest('.convertLeadModules').find('.iconArrow').removeClass('icon-chevron-down').addClass('icon-chevron-up');
 206          });
 207          
 208          //Trigger Event on click of Transfer related records modules
 209          container.on('click', '.transferModule', function(e){
 210              var currentTarget = jQuery(e.currentTarget);
 211              var module = currentTarget.val();
 212              var moduleBlock = jQuery('#'+module+'_FieldInfo');
 213              if(currentTarget.is(':checked')) {
 214                  jQuery('#'+module+'Module').attr('checked','checked');
 215                  moduleBlock.collapse('show');
 216                  instance.removeDisableAttr(moduleBlock);
 217              }
 218          });
 219          
 220          //Trigger Event on click of the Modules selection to convert the lead 
 221          container.on('click','.convertLeadModuleSelection', function(e){
 222              var currentTarget = jQuery(e.currentTarget);
 223              var currentModuleName = currentTarget.val();
 224              var moduleBlock = currentTarget.closest('.accordion-group').find('#'+currentModuleName+'_FieldInfo');
 225              var currentTransferModuleElement = jQuery('#transfer'+currentModuleName);
 226              var otherTransferModuleElement = jQuery('input[name="transferModule"]').not(currentTransferModuleElement);
 227              var otherTransferModuleValue = jQuery(otherTransferModuleElement).val();
 228              var otherModuleElement = jQuery('#'+otherTransferModuleValue+'Module');
 229              
 230              if(currentTarget.is(':checked')) {
 231                  moduleBlock.collapse('show');
 232                  instance.removeDisableAttr(moduleBlock);
 233                  if(!otherModuleElement.is(':checked')) {
 234                      jQuery(currentTransferModuleElement).attr('checked', 'checked');
 235                  }
 236              } else {
 237                  moduleBlock.collapse('hide');
 238                  instance.addDisableAttr(moduleBlock);
 239                  jQuery(currentTransferModuleElement).removeAttr('checked');
 240                  if(otherModuleElement.is(':checked')) {
 241                      jQuery(otherTransferModuleElement).attr('checked','checked');
 242                  }
 243              }
 244              e.stopImmediatePropagation();
 245          });
 246      },
 247      
 248      /*
 249       * function to register Convert Lead Submit Event
 250       */
 251      registerConvertLeadSubmit : function() {
 252          var thisInstance = this;
 253          var formElement = this.getConvertLeadForm();
 254          
 255          formElement.on('jqv.form.validating', function(e){
 256              var jQv = jQuery(e.currentTarget).data('jqv');
 257              //Remove the earlier validated fields from history so that it wont count disabled fields 
 258              jQv.InvalidFields = [];
 259          });
 260          
 261          //Convert Lead Form Submission
 262          formElement.on('submit',function(e) {
 263              var convertLeadModuleElements = thisInstance.getConvertLeadModules();
 264              var moduleArray = [];
 265              var contactModel = formElement.find('#ContactsModule');
 266              var accountModel = formElement.find('#AccountsModule');
 267              
 268              //If the validation fails in the hidden Block, we should show that Block with error.
 269              var invalidFields = formElement.data('jqv').InvalidFields;
 270              if(invalidFields.length > 0) {
 271                  var fieldElement = invalidFields[0];
 272                  var moduleBlock = jQuery(fieldElement).closest('div.accordion-body');
 273                  moduleBlock.collapse('show');
 274                  e.preventDefault();
 275                  return;
 276              }
 277              
 278              jQuery.each(convertLeadModuleElements, function(index, element) {
 279                  if(jQuery(element).is(':checked')) {
 280                      moduleArray.push(jQuery(element).val());
 281                  }
 282              });
 283              formElement.find('input[name="modules"]').val(JSON.stringify(moduleArray));
 284              
 285              var contactElement = contactModel.length;
 286              var organizationElement = accountModel.length;
 287              
 288              if(contactElement != '0' && organizationElement != '0') {
 289                  if(jQuery.inArray('Accounts',moduleArray) == -1 && jQuery.inArray('Contacts',moduleArray) == -1) {
 290                      alert(app.vtranslate('JS_SELECT_ORGANIZATION_OR_CONTACT_TO_CONVERT_LEAD'));
 291                      e.preventDefault();
 292                  } 
 293              } else if(organizationElement != '0') {
 294                  if(jQuery.inArray('Accounts',moduleArray) == -1) {
 295                      alert(app.vtranslate('JS_SELECT_ORGANIZATION'));
 296                      e.preventDefault();
 297                  }
 298              } else if(contactElement != '0') {
 299                  if(jQuery.inArray('Contacts',moduleArray) == -1) {
 300                      alert(app.vtranslate('JS_SELECT_CONTACTS'));
 301                      e.preventDefault();
 302                  }
 303              }
 304          });
 305      },
 306      
 307      /*
 308       * function to get all the checkboxes which are representing the modules selection
 309       */
 310      getConvertLeadModules : function() {
 311          var container = this.getConvertLeadContainer();
 312          if(this.convertLeadModules == false) {
 313              this.convertLeadModules = jQuery('.convertLeadModuleSelection', container);
 314          }
 315          return this.convertLeadModules;
 316      },
 317      
 318      /*
 319       * function to get Convert Lead Form
 320       */
 321      getConvertLeadForm : function() {
 322          if(this.convertLeadForm == false) {
 323              this.convertLeadForm = jQuery('#convertLeadForm');
 324          }
 325          return this.convertLeadForm;
 326      },
 327      
 328      /*
 329       * function to get Convert Lead Container
 330       */
 331      getConvertLeadContainer : function() {
 332          if(this.convertLeadContainer == false) {
 333              this.convertLeadContainer = jQuery('#leadAccordion');
 334          }
 335          return this.convertLeadContainer;
 336      }
 337      
 338  });


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