[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/resources/ -> Field.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("Vtiger_Field_Js",{
  10  
  11      /**
  12       * Function to get Instance of the class based on moduleName
  13       * @param data,data to set
  14       * @param moduleName module for which Instance should be created
  15       * @return Instance of field class
  16       */
  17      getInstance : function(data,moduleName){
  18          if(typeof moduleName == 'undefined'){
  19              var moduleName = app.getModuleName();
  20          }
  21          var moduleField = moduleName+"_Field_Js";
  22          var moduleFieldObj = window[moduleField];
  23          if (typeof moduleFieldObj != 'undefined'){
  24               var fieldClass = moduleFieldObj;
  25          }else{
  26              var fieldClass = Vtiger_Field_Js;
  27          }
  28          var fieldObj = new fieldClass();
  29  
  30          if(typeof data == 'undefined'){
  31              data = {};
  32          }
  33          fieldObj.setData(data);
  34          return fieldObj;
  35      }
  36  },{
  37      data : {},
  38      /**
  39       * Function to check whether field is mandatory or not
  40       * @return true if feld is madatory
  41       * @return false if field is not mandatory
  42       */
  43      isMandatory : function(){
  44          return this.get('mandatory');
  45      },
  46  
  47  
  48      /**
  49       * Function to get the value of particular key in object
  50       * @return value for the passed key
  51       */
  52  
  53      get : function(key){
  54          if(key in this.data){
  55              return this.data[key];
  56          }
  57          return '';
  58      },
  59  
  60  
  61      /**
  62       * Function to get type attribute of the object
  63       * @return type attribute of the object
  64       */
  65      getType : function(){
  66          return this.get('type');
  67      },
  68  
  69      /**
  70       * Function to get name of the field
  71       * @return <String> name of the field
  72       */
  73      getName : function() {
  74          return this.get('name');
  75      },
  76  
  77      /**
  78       * Function to get value of the field
  79       * @return <Object> value of the field or empty of there is not value
  80       */
  81      getValue : function() {
  82          if('value' in this.getData()){
  83              return this.get('value');
  84          } else if('defaultValue' in this.getData()){
  85              return this.get('defaultValue');
  86          }
  87          return '';
  88      },
  89  
  90      /**
  91       * Function to get the whole data
  92       * @return <object>
  93       */
  94      getData : function() {
  95          return this.data;
  96      },
  97  
  98      /**
  99       * Function to set data attribute of the class
 100       * @return Instance of the class
 101       */
 102      setData : function(fieldInfo){
 103          this.data = fieldInfo;
 104          return this;
 105      },
 106      
 107      getModuleName : function() {
 108          return app.getModuleName();
 109      },
 110  
 111      /**
 112       * Function to get the ui type specific model
 113       */
 114      getUiTypeModel : function() {
 115          var currentModule = this.getModuleName();
 116  
 117          var type = this.getType();
 118          var typeClassName = type.charAt(0).toUpperCase() + type.slice(1).toLowerCase();
 119  
 120          var moduleUiTypeClassName = window[currentModule + "_" + typeClassName+"_Field_Js"];
 121          var BasicUiTypeClassName = window["Vtiger_"+ typeClassName + "_Field_Js"];
 122  
 123          if(typeof moduleUiTypeClassName != 'undefined') {
 124              var instance =  new moduleUiTypeClassName();
 125              return instance.setData(this.getData());
 126          }else if (typeof BasicUiTypeClassName != 'undefined') {
 127              var instance =  new BasicUiTypeClassName();
 128              return instance.setData(this.getData());
 129          }
 130          return this;
 131      },
 132  
 133      /**
 134       * Funtion to get the ui for the field  - generally this will be extend by the child classes to
 135       * give ui type specific ui
 136       * return <String or Jquery> it can return either plain html or jquery object
 137       */
 138      getUi : function() {
 139          var html = '<input type="text" name="'+ this.getName() +'"  />';
 140          html = jQuery(html).val(app.htmlDecode(this.getValue()));
 141          return this.addValidationToElement(html);
 142      },
 143  
 144      /**
 145       * Function to get the ui for a field depending on the ui type
 146       * this will get the specific ui depending on the field type
 147       * return <String or Jquery> it can return either plain html or jquery object
 148       */
 149      getUiTypeSpecificHtml : function() {
 150          var uiTypeModel = this.getUiTypeModel();
 151          return uiTypeModel.getUi();
 152      },
 153  
 154      /**
 155       * Function to add the validation for the element
 156       */
 157      addValidationToElement : function(element) {
 158          var element = jQuery(element);
 159          var addValidationToElement = element;
 160          var elementInStructure = element.find('[name="'+this.getName()+'"]'); 
 161          if(elementInStructure.length > 0){ 
 162              addValidationToElement = elementInStructure; 
 163          }
 164          var validationHandler = 'validate[';
 165          if(this.isMandatory()) {
 166              validationHandler +="required,";
 167          }
 168          validationHandler +="funcCall[Vtiger_Base_Validator_Js.invokeValidation]]";
 169          addValidationToElement.attr('data-validation-engine', validationHandler).attr('data-fieldinfo',JSON.stringify(this.getData())).attr('data-validator',JSON.stringify(this.getData().specialValidator));
 170          return element;
 171      }
 172  })
 173  
 174  
 175  Vtiger_Field_Js('Vtiger_Picklist_Field_Js',{},{
 176  
 177      /**
 178       * Function to get the pick list values
 179       * @return <object> key value pair of options
 180       */
 181      getPickListValues : function() {
 182          return this.get('picklistvalues');
 183      },
 184  
 185      /**
 186       * Function to get the ui
 187       * @return - select element and chosen element
 188       */
 189      getUi : function() {
 190          var html = '<select class="row-fluid chzn-select" name="'+ this.getName() +'">';
 191          var pickListValues = this.getPickListValues();
 192          var selectedOption = app.htmlDecode(this.getValue());
 193          for(var option in pickListValues) {
 194              html += '<option value="'+option+'" ';
 195              if(option == selectedOption) {
 196                  html += ' selected ';
 197              }
 198              html += '>'+pickListValues[option]+'</option>';
 199          }
 200          html +='</select>';
 201          var selectContainer = jQuery(html);
 202          this.addValidationToElement(selectContainer);
 203          return selectContainer;
 204      }
 205  });
 206  
 207  Vtiger_Field_Js('Vtiger_Multipicklist_Field_Js',{},{
 208      /**
 209       * Function to get the pick list values
 210       * @return <object> key value pair of options
 211       */
 212      getPickListValues : function() {
 213          return this.get('picklistvalues');
 214      },
 215      
 216      /**
 217       * Function to get the ui
 218       * @return - select element and chosen element
 219       */
 220      getUi : function() {
 221          var html = '<select class="select2" multiple name="'+ this.getName() +'[]">';
 222          var pickListValues = this.getPickListValues();
 223          var selectedOption = app.htmlDecode(this.getValue());
 224          var selectedOptionsArray = selectedOption.split(',')
 225          for(var option in pickListValues) {
 226              html += '<option value="'+option+'" ';
 227              if(jQuery.inArray(option,selectedOptionsArray) != -1){
 228                  html += ' selected ';
 229              }
 230              html += '>'+pickListValues[option]+'</option>';
 231          }
 232          html +='</select>';
 233          var selectContainer = jQuery(html);
 234          this.addValidationToElement(selectContainer);
 235          return selectContainer;
 236      }
 237  }),
 238  
 239  Vtiger_Field_Js('Vtiger_Boolean_Field_Js',{},{
 240  
 241      /**
 242       * Function to check whether the field is checked or not
 243       * @return <Boolean>
 244       */
 245      isChecked : function() {
 246          var value = this.getValue();
 247          if(value==1 || value == '1' || value.toLowerCase() == 'on'){
 248              return true;
 249          }
 250          return false;
 251      },
 252  
 253      /**
 254       * Function to get the ui
 255       * @return - checkbox element
 256       */
 257      getUi : function() {
 258          var    html = '<input type="hidden" name="'+this.getName() +'" value="0"/><input type="checkbox" name="'+ this.getName() +'" ';
 259          if(this.isChecked()) {
 260              html += 'checked';
 261          }
 262          html += ' />'
 263          return this.addValidationToElement(html);
 264      }
 265  });
 266  
 267  
 268  Vtiger_Field_Js('Vtiger_Date_Field_Js',{},{
 269  
 270      /**
 271       * Function to get the user date format
 272       */
 273      getDateFormat : function(){
 274          return this.get('date-format');
 275      },
 276  
 277      /**
 278       * Function to get the ui
 279       * @return - input text field
 280       */
 281      getUi : function() {
 282          var html = '<div class="input-append">'+
 283                          '<div class="date">'+
 284                              '<input class="dateField" type="text" name="'+ this.getName() +'"  data-date-format="'+ this.getDateFormat() +'"  value="'+  this.getValue() + '" />'+
 285                              '<span class="add-on"><i class="icon-calendar"></i></span>'+
 286                          '</div>'+
 287                      '</div>';
 288          var element = jQuery(html);
 289          return this.addValidationToElement(element);
 290      }
 291  });
 292  
 293  Vtiger_Field_Js('Vtiger_Currency_Field_Js',{},{
 294  
 295      /**
 296       * get the currency symbol configured for the user
 297       */
 298      getCurrencySymbol : function() {
 299          return this.get('currency_symbol');
 300      },
 301  
 302      getUi : function() {
 303          var html = '<div class="input-prepend row-fluid">'+
 304                                      '<span class="add-on">'+ this.getCurrencySymbol()+'</span>'+
 305                                      '<input type="text" name="'+ this.getName() +'" value="'+  this.getValue() + '"  />'+
 306                      '</div>';
 307          var element = jQuery(html);
 308          return this.addValidationToElement(element);
 309      }
 310  });
 311  
 312  
 313  Vtiger_Field_Js('Vtiger_Owner_Field_Js',{},{
 314  
 315      /**
 316       * Function to get the picklist values
 317       */
 318      getPickListValues : function() {
 319          return this.get('picklistvalues');
 320      },
 321  
 322      getUi : function() {
 323          var html = '<select class="row-fluid chzn-select" name="'+ this.getName() +'">';
 324          var pickListValues = this.getPickListValues();
 325          var selectedOption = this.getValue();
 326          for(var optGroup in pickListValues){
 327              html += '<optgroup label="'+ optGroup +'">'
 328              var optionGroupValues = pickListValues[optGroup];
 329              for(var option in optionGroupValues) {
 330                  html += '<option value="'+option+'" ';
 331                  //comparing with the value instead of key , because saved value is giving username instead of id.
 332                  if(optionGroupValues[option] == selectedOption) {
 333                      html += ' selected ';
 334                  }
 335                  html += '>'+optionGroupValues[option]+'</option>';
 336              }
 337              html += '</optgroup>'
 338          }
 339  
 340          html +='</select>';
 341          var selectContainer = jQuery(html);
 342          this.addValidationToElement(selectContainer);
 343          return selectContainer;
 344      }
 345  })
 346  
 347  
 348  Vtiger_Date_Field_Js('Vtiger_Datetime_Field_Js',{},{
 349  
 350  });
 351  
 352  Vtiger_Field_Js('Vtiger_Time_Field_Js',{},{
 353      
 354      /**
 355       * Function to get the user date format
 356       */
 357      getTimeFormat : function(){
 358          return this.get('time-format');
 359      },
 360  
 361      /**
 362       * Function to get the ui
 363       * @return - input text field
 364       */
 365      getUi : function() {
 366          var html = '<div class="input-append time">'+
 367                              '<input class="timepicker-default" type="text" data-format="'+ this.getTimeFormat() +'" name="'+ this.getName() +'"  value="'+  this.getValue() + '" />'+
 368                              '<span class="add-on"><i class="icon-time"></i></span>'+
 369                      '</div>';
 370          var element = jQuery(html);
 371          return this.addValidationToElement(element);
 372      }
 373  });
 374  
 375  Vtiger_Field_Js('Vtiger_Text_Field_Js',{},{
 376  
 377      /**
 378       * Function to get the ui
 379       * @return - input text field
 380       */
 381      getUi : function() {
 382          var html = '<textarea class="input-xxlarge" name="'+ this.getName() +'"  value="'+  this.getValue() + '" style="width:100%">'+  this.getValue() + '</textarea>';
 383          var element = jQuery(html);
 384          return this.addValidationToElement(element);
 385      }
 386  });
 387  
 388  Vtiger_Field_Js('Vtiger_Percentage_Field_Js',{},{
 389  
 390      /**
 391       * Function to get the ui
 392       * @return - input percentage field
 393       */
 394      getUi : function() {
 395          var html = '<div class="input-append row-fluid">'+
 396                                      '<input type="number" class="input-medium" min="0" max="100" name="'+this.getName() +'" value="'+  this.getValue() + '" step="any"/>'+
 397                                      '<span class="add-on">%</span>'+
 398                      '</div>';
 399          var element = jQuery(html);
 400          return this.addValidationToElement(element);
 401      }
 402  });
 403  Vtiger_Field_Js('Vtiger_Recurrence_Field_Js',{},{
 404  
 405      /**
 406       * Function to get the pick list values
 407       * @return <object> key value pair of options
 408       */
 409      getPickListValues : function() {
 410          return this.get('picklistvalues');
 411      },
 412  
 413      /**
 414       * Function to get the ui
 415       * @return - select element and chosen element
 416       */
 417      getUi : function() {
 418          var html = '<select class="row-fluid chzn-select" name="'+ this.getName() +'">';
 419          var pickListValues = this.getPickListValues();
 420          var selectedOption = app.htmlDecode(this.getValue());
 421          for(var option in pickListValues) {
 422              html += '<option value="'+option+'" ';
 423              if(option == selectedOption) {
 424                  html += ' selected ';
 425              }
 426              html += '>'+pickListValues[option]+'</option>';
 427          }
 428          html +='</select>';
 429          var selectContainer = jQuery(html);
 430          this.addValidationToElement(selectContainer);
 431          return selectContainer;
 432      }
 433  });


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