[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Reports/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  Vtiger_Edit_Js("Reports_Edit_Js",{
  10  
  11      instance : {}
  12  
  13  },{
  14  
  15      currentInstance : false,
  16  
  17      reportsContainer : false,
  18  
  19      init : function() {
  20          var statusToProceed = this.proceedRegisterEvents();
  21          if(!statusToProceed){
  22              return;
  23          }
  24          this.initiate();
  25      },
  26      /**
  27       * Function to get the container which holds all the reports elements
  28       * @return jQuery object
  29       */
  30      getContainer : function() {
  31          return this.reportsContainer;
  32      },
  33  
  34      /**
  35       * Function to set the reports container
  36       * @params : element - which represents the reports container
  37       * @return : current instance
  38       */
  39      setContainer : function(element) {
  40          this.reportsContainer = element;
  41          return this;
  42      },
  43  
  44  
  45      /*
  46       * Function to return the instance based on the step of the report
  47       */
  48      getInstance : function(step) {
  49          if(step in Reports_Edit_Js.instance ){
  50              return Reports_Edit_Js.instance[step];
  51          } else {
  52              var view = app.getViewName();
  53              var moduleClassName = app.getModuleName()+"_"+view+step+"_Js";
  54              Reports_Edit_Js.instance[step] =  new window[moduleClassName]();
  55              return Reports_Edit_Js.instance[step]
  56          }
  57      },
  58  
  59      /*
  60       * Function to get the value of the step
  61       * returns 1 or 2 or 3
  62       */
  63      getStepValue : function(){
  64          var container = this.currentInstance.getContainer();
  65          return jQuery('.step',container).val();
  66      },
  67  
  68      /*
  69       * Function to initiate the step 1 instance
  70       */
  71      initiate : function(container){
  72          if(typeof container == 'undefined') {
  73              container = jQuery('.reportContents');
  74          }
  75          if(container.is('.reportContents')) {
  76              this.setContainer(container);
  77          }else{
  78              this.setContainer(jQuery('.reportContents',container));
  79          }
  80          this.initiateStep('1');
  81          this.currentInstance.registerEvents();
  82      },
  83      /*
  84       * Function to initiate all the operations for a step
  85       * @params step value
  86       */
  87      initiateStep : function(stepVal) {
  88          var step = 'step'+stepVal;
  89          this.activateHeader(step);
  90          var currentInstance = this.getInstance(stepVal);
  91          this.currentInstance = currentInstance;
  92      },
  93  
  94      /*
  95       * Function to activate the header based on the class
  96       * @params class name
  97       */
  98      activateHeader : function(step) {
  99          var headersContainer = jQuery('.crumbs');
 100          headersContainer.find('.active').removeClass('active');
 101          jQuery('#'+step,headersContainer).addClass('active');
 102      },
 103      /*
 104       * Function to register the click event for next button
 105       */
 106      registerFormSubmitEvent : function(form) {
 107          var thisInstance = this;
 108          if(jQuery.isFunction(thisInstance.currentInstance.submit)){
 109              form.on('submit',function(e){
 110                  var form = jQuery(e.currentTarget);
 111                  var specialValidation = true;
 112                  if(jQuery.isFunction(thisInstance.currentInstance.isFormValidate)){
 113                      var specialValidation =  thisInstance.currentInstance.isFormValidate();
 114                  }
 115                  if (form.validationEngine('validate') && specialValidation) {
 116                      thisInstance.currentInstance.submit().then(function(data){
 117                          thisInstance.getContainer().append(data);
 118                          var stepVal = thisInstance.getStepValue();
 119                          var nextStepVal = parseInt(stepVal) + 1;
 120                          thisInstance.initiateStep(nextStepVal);
 121                          thisInstance.currentInstance.initialize();
 122                          var container = thisInstance.currentInstance.getContainer();
 123                          thisInstance.registerFormSubmitEvent(container);
 124                          thisInstance.currentInstance.registerEvents();
 125                      });
 126                  }
 127                  e.preventDefault();
 128              })
 129          }
 130      },
 131  
 132      back : function(){
 133          var step = this.getStepValue();
 134          var prevStep = parseInt(step) - 1;
 135          this.currentInstance.initialize();
 136          var container = this.currentInstance.getContainer();
 137          container.remove();
 138          this.initiateStep(prevStep);
 139          this.currentInstance.getContainer().show();
 140      },
 141  
 142      /*
 143       * Function to register the click event for back step
 144       */
 145      registerBackStepClickEvent : function(){
 146          var thisInstance = this;
 147          var container = this.getContainer();
 148          container.on('click','.backStep',function(e){
 149              thisInstance.back();
 150          });
 151      },
 152  
 153      registerEvents : function(){
 154          var statusToProceed = this.proceedRegisterEvents();
 155          if(!statusToProceed){
 156              return;
 157          }
 158          var form = this.currentInstance.getContainer();
 159          this.registerFormSubmitEvent(form);
 160          this.registerBackStepClickEvent();
 161      }
 162  });
 163  


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