[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Settings/Workflows/resources/ -> Edit.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  Settings_Vtiger_Edit_Js("Settings_Workflows_Edit_Js",{
  10      
  11      instance : {}
  12      
  13  },{
  14      
  15      currentInstance : false,
  16      
  17      workFlowsContainer : false,
  18      
  19      init : function() {
  20          this.initiate();
  21      },
  22      /**
  23       * Function to get the container which holds all the workflow elements
  24       * @return jQuery object
  25       */
  26      getContainer : function() {
  27          return this.workFlowsContainer;
  28      },
  29  
  30      /**
  31       * Function to set the reports container
  32       * @params : element - which represents the workflow container
  33       * @return : current instance
  34       */
  35      setContainer : function(element) {
  36          this.workFlowsContainer = element;
  37          return this;
  38      },
  39      
  40      
  41      /*
  42       * Function to return the instance based on the step of the Workflow
  43       */
  44      getInstance : function(step) {
  45          if(step in Settings_Workflows_Edit_Js.instance ){
  46              return Settings_Workflows_Edit_Js.instance[step];
  47          } else {
  48              var moduleClassName = 'Settings_Workflows_Edit'+step+'_Js' ;
  49              Settings_Workflows_Edit_Js.instance[step] =  new window[moduleClassName]();
  50              return Settings_Workflows_Edit_Js.instance[step]
  51          }
  52      },
  53      
  54      /*
  55       * Function to get the value of the step 
  56       * returns 1 or 2 or 3
  57       */
  58      getStepValue : function(){
  59          var container = this.currentInstance.getContainer(); 
  60          return jQuery('.step',container).val();
  61      },
  62      
  63      /*
  64       * Function to initiate the step 1 instance
  65       */
  66      initiate : function(container){
  67          if(typeof container == 'undefined') {
  68              container = jQuery('.workFlowContents');
  69          }
  70          if(container.is('.workFlowContents')) {
  71              this.setContainer(container);
  72          }else{
  73              this.setContainer(jQuery('.workFlowContents',container));
  74          }
  75          this.initiateStep('1');
  76          this.currentInstance.registerEvents();
  77      },
  78      /*
  79       * Function to initiate all the operations for a step
  80       * @params step value
  81       */
  82      initiateStep : function(stepVal) {
  83          var step = 'step'+stepVal;
  84          this.activateHeader(step);
  85          var currentInstance = this.getInstance(stepVal);
  86          this.currentInstance = currentInstance;
  87      },
  88      
  89      /*
  90       * Function to activate the header based on the class
  91       * @params class name
  92       */
  93      activateHeader : function(step) {
  94          var headersContainer = jQuery('.crumbs ');
  95          headersContainer.find('.active').removeClass('active');
  96          jQuery('#'+step,headersContainer).addClass('active');
  97      },
  98      /*
  99       * Function to register the click event for next button
 100       */
 101      registerFormSubmitEvent : function(form) {
 102          var thisInstance = this;
 103          if(jQuery.isFunction(thisInstance.currentInstance.submit)){
 104              form.on('submit',function(e){
 105                  var form = jQuery(e.currentTarget);
 106                  var specialValidation = true;
 107                  if(jQuery.isFunction(thisInstance.currentInstance.isFormValidate)){
 108                      var specialValidation =  thisInstance.currentInstance.isFormValidate();
 109                  }
 110                  if ( form.validationEngine('validate') && specialValidation) {
 111                          thisInstance.currentInstance.submit().then(function(data){
 112                              thisInstance.getContainer().append(data);
 113                              var stepVal = thisInstance.getStepValue();
 114                              var nextStepVal = parseInt(stepVal) + 1;
 115                              thisInstance.initiateStep(nextStepVal);
 116                              thisInstance.currentInstance.initialize();
 117                              var container = thisInstance.currentInstance.getContainer();
 118                              thisInstance.registerFormSubmitEvent(container);
 119                              thisInstance.currentInstance.registerEvents();
 120                          });
 121  
 122                  }
 123                  e.preventDefault();
 124              })        
 125          }
 126      },
 127      
 128      back : function(){
 129          var step = this.getStepValue();
 130          var prevStep = parseInt(step) - 1;
 131          this.currentInstance.initialize();
 132          var container = this.currentInstance.getContainer();
 133          var workflowRecordElement = jQuery('[name="record"]',container);
 134          var workFlowId = workflowRecordElement.val();
 135          container.remove();
 136          this.initiateStep(prevStep);
 137          var currentContainer = this.currentInstance.getContainer();
 138          currentContainer.show();
 139          jQuery('[name="record"]',currentContainer).val(workFlowId);
 140          var modulesList = jQuery('#moduleName',currentContainer);
 141          if(modulesList.length > 0 && workFlowId != '') {
 142              modulesList.attr('disabled','disabled').trigger('liszt:updated');
 143          }
 144      },
 145      
 146      getPopUp : function(container) {
 147          var thisInstance = this;
 148          if(typeof container == 'undefined') {
 149              container = thisInstance.getContainer();
 150          }
 151          container.on('click','.getPopupUi',function(e) {
 152              var fieldValueElement = jQuery(e.currentTarget);
 153              var fieldValue = fieldValueElement.val();
 154              var fieldUiHolder  = fieldValueElement.closest('.fieldUiHolder');
 155              var valueType = fieldUiHolder.find('[name="valuetype"]').val();
 156              if(valueType == '') {
 157                  valueType = 'rawtext';
 158              }
 159              var conditionsContainer = fieldValueElement.closest('.conditionsContainer');
 160              var conditionRow = fieldValueElement.closest('.conditionRow');
 161              
 162              var clonedPopupUi = conditionsContainer.find('.popupUi').clone(true,true).removeClass('popupUi').addClass('clonedPopupUi')
 163              clonedPopupUi.find('select').addClass('chzn-select');
 164              clonedPopupUi.find('.fieldValue').val(fieldValue);
 165              if(fieldValueElement.hasClass('date')){
 166                  clonedPopupUi.find('.textType').find('option[value="rawtext"]').attr('data-ui','input');
 167                  var dataFormat = fieldValueElement.data('date-format');
 168                  if(valueType == 'rawtext') {
 169                      var value = fieldValueElement.val();
 170                  } else {
 171                      value = '';
 172                  }
 173                  var clonedDateElement = '<input type="text" class="row-fluid dateField fieldValue span4" value="'+value+'" data-date-format="'+dataFormat+'" data-input="true" >'
 174                  clonedPopupUi.find('.fieldValueContainer').prepend(clonedDateElement);
 175              } else if(fieldValueElement.hasClass('time')) {
 176                  clonedPopupUi.find('.textType').find('option[value="rawtext"]').attr('data-ui','input');
 177                  if(valueType == 'rawtext') {
 178                      var value = fieldValueElement.val();
 179                  } else {
 180                      value = '';
 181                  }
 182                  var clonedTimeElement = '<input type="text" class="row-fluid timepicker-default fieldValue span4" value="'+value+'" data-input="true" >'
 183                  clonedPopupUi.find('.fieldValueContainer').prepend(clonedTimeElement);
 184              } else if(fieldValueElement.hasClass('boolean')) {
 185                  clonedPopupUi.find('.textType').find('option[value="rawtext"]').attr('data-ui','input');
 186                  if(valueType == 'rawtext') {
 187                      var value = fieldValueElement.val();
 188                  } else {
 189                      value = '';
 190                  }
 191                  var clonedBooleanElement = '<input type="checkbox" class="row-fluid fieldValue span4" value="'+value+'" data-input="true" >';
 192                  clonedPopupUi.find('.fieldValueContainer').prepend(clonedBooleanElement);
 193                  
 194                  var fieldValue = clonedPopupUi.find('.fieldValueContainer input').val();
 195                  if(value == 'true:boolean' || value == '') {
 196                      clonedPopupUi.find('.fieldValueContainer input').attr('checked', 'checked');
 197                  } else {
 198                      clonedPopupUi.find('.fieldValueContainer input').removeAttr('checked');
 199                  }
 200              }
 201              var callBackFunction = function(data) {
 202                  data.find('.clonedPopupUi').removeClass('hide');
 203                  var moduleNameElement = conditionRow.find('[name="modulename"]');
 204                  if(moduleNameElement.length > 0){
 205                      var moduleName = moduleNameElement.val();
 206                      data.find('.useFieldElement').addClass('hide');
 207                      data.find('[name="'+moduleName+'"]').removeClass('hide');
 208                  }
 209                  app.changeSelectElementView(data);
 210                  app.registerEventForDatePickerFields(data);
 211                  app.registerEventForTimeFields(data);
 212                  thisInstance.postShowModalAction(data,valueType);
 213                  thisInstance.registerChangeFieldEvent(data);
 214                  thisInstance.registerSelectOptionEvent(data);
 215                  thisInstance.registerPopUpSaveEvent(data,fieldUiHolder);
 216                  thisInstance.registerRemoveModalEvent(data);
 217                  data.find('.fieldValue').filter(':visible').trigger('focus');
 218              }
 219              conditionsContainer.find('.clonedPopUp').html(clonedPopupUi);
 220              jQuery('.clonedPopupUi').on('shown', function () {
 221                  if(typeof callBackFunction == 'function'){
 222                      callBackFunction(jQuery('.clonedPopupUi',conditionsContainer));
 223                  }
 224              });
 225              jQuery('.clonedPopUp',conditionsContainer).find('.clonedPopupUi').modal();
 226          });
 227      },
 228      
 229      registerRemoveModalEvent : function(data) {
 230          data.on('click','.closeModal',function(e) {
 231              data.modal('hide');
 232          });
 233      },
 234      
 235      
 236      registerPopUpSaveEvent : function(data,fieldUiHolder) {
 237          jQuery('[name="saveButton"]',data).on('click',function(e){
 238              var valueType = jQuery('.textType',data).val();
 239              
 240              fieldUiHolder.find('[name="valuetype"]').val(valueType);
 241              var fieldValueElement = fieldUiHolder.find('.getPopupUi');
 242              if(valueType != 'rawtext'){
 243                  fieldValueElement.removeAttr('data-validation-engine');
 244                  fieldValueElement.removeClass('validate[funcCall[Vtiger_Base_Validator_Js.invokeValidation]]');
 245              }else{
 246                  fieldValueElement.addClass('validate[funcCall[Vtiger_Base_Validator_Js.invokeValidation]]');
 247                  fieldValueElement.attr('data-validation-engine','validate[funcCall[Vtiger_Base_Validator_Js.invokeValidation]]');
 248              }
 249              var fieldType = data.find('.fieldValue').filter(':visible').attr('type');
 250              var fieldValue = data.find('.fieldValue').filter(':visible').val();
 251              //For checkbox field type, handling fieldValue
 252              if(fieldType == 'checkbox'){
 253                  if(data.find('.fieldValue').filter(':visible').is(':checked')) {
 254                      fieldValue = 'true:boolean';
 255                  } else {
 256                      fieldValue = 'false:boolean';
 257                  }
 258              }
 259              fieldValueElement.val(fieldValue);
 260              data.modal('hide');
 261              fieldValueElement.validationEngine('hide');
 262          });
 263      },
 264      
 265      registerSelectOptionEvent : function(data) {
 266          jQuery('.useField,.useFunction',data).on('change',function(e){
 267              var currentElement = jQuery(e.currentTarget);
 268              var newValue = currentElement.val();
 269              var oldValue  = data.find('.fieldValue').filter(':visible').val();
 270              if(currentElement.hasClass('useField')){
 271                  if(oldValue != ''){
 272                      var concatenatedValue = oldValue+' '+newValue;
 273                  } else {
 274                      concatenatedValue = newValue;
 275                  }
 276              } else {
 277                  concatenatedValue = oldValue+newValue;
 278              }
 279              data.find('.fieldValue').val(concatenatedValue);
 280              currentElement.val('').trigger('liszt:updated');
 281          });
 282      },
 283      
 284      registerChangeFieldEvent : function(data) {
 285          jQuery('.textType',data).on('change',function(e){
 286              var valueType =  jQuery(e.currentTarget).val();
 287              var useFieldContainer = jQuery('.useFieldContainer',data);
 288              var useFunctionContainer = jQuery('.useFunctionContainer',data);
 289              var uiType = jQuery(e.currentTarget).find('option:selected').data('ui');
 290              jQuery('.fieldValue',data).hide();
 291              jQuery('[data-'+uiType+']',data).show();
 292              if(valueType == 'fieldname') {
 293                  useFieldContainer.removeClass('hide');
 294                  useFunctionContainer.addClass('hide');
 295              } else if(valueType == 'expression') {
 296                  useFieldContainer.removeClass('hide');
 297                  useFunctionContainer.removeClass('hide');
 298              } else {
 299                  useFieldContainer.addClass('hide');
 300                  useFunctionContainer.addClass('hide');
 301              }
 302              jQuery('.helpmessagebox',data).addClass('hide');
 303              jQuery('#'+valueType+'_help',data).removeClass('hide');
 304              data.find('.fieldValue').val('');
 305          });
 306      },
 307      
 308      postShowModalAction : function(data,valueType) {
 309          if(valueType == 'fieldname') {
 310              jQuery('.useFieldContainer',data).removeClass('hide');
 311              jQuery('.textType',data).val(valueType).trigger('liszt:updated');
 312          } else if(valueType == 'expression') {
 313              jQuery('.useFieldContainer',data).removeClass('hide');
 314              jQuery('.useFunctionContainer',data).removeClass('hide');
 315              jQuery('.textType',data).val(valueType).trigger('liszt:updated');
 316          }
 317          jQuery('#'+valueType+'_help',data).removeClass('hide');
 318          var uiType = jQuery('.textType',data).find('option:selected').data('ui');
 319          jQuery('.fieldValue',data).hide();
 320          jQuery('[data-'+uiType+']',data).show();
 321      },
 322      
 323      /*
 324       * Function to register the click event for back step 
 325       */
 326      registerBackStepClickEvent : function(){
 327          var thisInstance = this;
 328          var container = this.getContainer();
 329          container.on('click','.backStep',function(e){
 330              thisInstance.back();
 331          });
 332      },
 333      
 334      registerEvents : function(){
 335          var form = this.currentInstance.getContainer();
 336          this.registerFormSubmitEvent(form);
 337          this.registerBackStepClickEvent();
 338      }
 339  });
 340  


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