/***
 * Contains basic SlickGrid editors.
 * @module Editors
 * @namespace Slick
 */
var timerGridAjaxCall;
(function ($) {
  // register namespace
  $.extend(true, window, {
    "Slick": {
      "Editors": {
        "Text": TextEditor,
        "Integer": IntegerEditor,
        "Float": FloatEditor,
        "Date": DateEditor,
        "YesNoSelect": YesNoSelectEditor,
        "Checkbox": CheckboxEditor,
        "Selectbox": Select2Editor,
        "PercentComplete": PercentCompleteEditor,
        "LongText": LongTextEditor,
        "DateTime": DateTimeEditor,
        "Time": TimeEditor,
        "CheckBoxField": CheckBoxEditor,
        "SelectboxMultiple":SelectboxMultipleEditor,
		"SelectboxSingle": SelectboxSingleEditor,
		"jsColorPicker":jsColorPicker
      }
    }
  });
function jsColorPicker(args) {
    var $input;
    var defaultValue;
    var scope = this;

    this.init = function () {
     
      $input = $("<input type='text' class='basic' id ='stateColor' name='stateColor' value='"+args.item.color+"'/>")
          .appendTo(args.container);
		  $input.spectrum({
			change: function(color) {
				$input.val(color.toHexString())
				return false;
			}
		});
    };

    this.destroy = function () {
      
    };

    this.focus = function () {
      
    };

    this.getValue = function () {
      
    };

    this.setValue = function (val) {
      
    };

    this.loadValue = function (item) {
   
      $input.val(item.color);
    };

    this.serializeValue = function () {
      return $input.val();
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      
    };

    this.validate = function () {
     if($(".sp-container").is(":visible")==false){
      return {
        valid: true,
        msg: null
      };
	 }else{
		 return {
        valid: false,
        msg: null
      };
	 }
    };
    this.init();
  }
  function TextEditor(args) {
    var $input;
    var defaultValue;
    var scope = this;
    var colType="";
    
    this.init = function () {
        
      var customField = getAdditionalFieldElementAttributes( args , "Textbox" );
      var dataAttributes = "";
        var dataAttributes2 = "";
      if ( customField.macroId != null && customField.macroId != undefined )
      {
          dataAttributes = " data-macroId=\""+customField.macroId+"\" ";
      }
      if ( customField.fieldId != null && customField.fieldId != undefined )
      {
          dataAttributes = dataAttributes +" data-fieldId=\""+customField.fieldId+"\" ";
      }
      if ( customField.fieldName != null && customField.fieldName != undefined )
      {
          dataAttributes = dataAttributes +" data-attribute=\""+customField.fieldName+"\" ";
      }
      
      if(customField.columnType!==null && customField.columnType !== undefined && (customField.columnType==="number" || customField.columnType==="float")){
        colType=customField.columnType;
        dataAttributes = dataAttributes +" onkeypress='return isNumberKey(event,\""+colType+"\",\""+customField.elementId+"\");' ";
      }
      if(args.column.isMandatory==true){
          dataAttributes2= "data-mandatory=true";
      }
      $input = $("<INPUT type=\"text\" class='editor-text "+customField.elementId+"' id=\""+customField.elementId+"\" "+dataAttributes+" "+dataAttributes2+" autocomplete='off' />")
          .appendTo(args.container)
          .on("keydown.nav", function (e) {
            if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT ) {
              e.stopImmediatePropagation();
            }
          })
          .focus()
          .select();
    };

    this.destroy = function () {
      $input.remove();
    };

    this.focus = function () {
      $input.focus();
    };

    this.getValue = function () {
      return $input.val();
    };

    this.setValue = function (val) {
      $input.val(val);
    };

    this.loadValue = function (item) {
      defaultValue = item[args.column.field] || "";
      $input.val(defaultValue);
      $input[0].defaultValue = defaultValue;
      $input.select();
    };

    this.serializeValue = function () {
      return $input.val();
    };

    this.applyValue = function (item, state) {
        
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
    };

    this.validate = function () {
        if (colType === "number" || colType === "float") {
            if(isNaN($input.val())){
               return {
                    valid: false
                };  
            }
        }
        if (colType === "number") {
            if (($input.val() % 1) !== 0) {
                return {
                    valid: false
                };
            }
        }
       
      if (args.column.validator) {
        var validationResults = args.column.validator($input.val());
        if (!validationResults.valid) {
          return validationResults;
        }
      }

      return {
        valid: true,
        msg: null
      };
    };
    this.init();
  }
  
  
  function SelectCellEditor(args) {
        var $select;
        var defaultValue;
        var scope = this;
        var opt_values;
        var option_str;
        
        this.init = function() {
            
            if(args.column.options){
              opt_values = args.column.options.split(',');
            }else{
              opt_values ="yes,no".split(',');
            }
            option_str = ""
            for( i in opt_values ){
              v = opt_values[i];
              option_str += "<OPTION value='"+v+"'>"+v+"</OPTION>";
            }
            $select = $("<SELECT id='"+args.column.id+"' tabIndex='0' class='editor-select'>"+ option_str +"</SELECT>");
            $select.appendTo(args.container);
            $select.focus();
            $select.multipleSelect({
                single: true,
                filter: false,
                onOpen: function () 
                {
                    var fieldId = args.column.id.replace ( "CUSTOMFIELD","" );
                    loadAdditionalFieldSelectBox( fieldId, "" , 1);
                }
            });
        };

        this.destroy = function() {
            $select.remove();
        };

        this.focus = function() {
            $select.focus();
        };

        this.loadValue = function(item) {
            defaultValue = item[args.column.field];
            $select.val(defaultValue);
        };

        this.serializeValue = function() {
            if(args.column.options){
              return $select.val();
            }else{
              return ($select.val() == "yes");
            }
        };

        this.applyValue = function(item,state) {
            item[args.column.field] = state;
        };

        this.isValueChanged = function() {
            return ($select.val() != defaultValue);
        };

        this.validate = function() {
         
            return {
                valid: true,
                msg: null
            };
        };
        
         
        this.init();
        
    }
    
     function Select2Editor(args) {
         
        var $input;
        var defaultValue;
        var scope = this;
        var calendarOpen = false;
        this.keyCaptureList = [ Slick.keyCode.UP, Slick.keyCode.DOWN, Slick.keyCode.ENTER ];
        
        
        var customField = getAdditionalFieldElementAttributes( args , "Textbox" );
        var dataAttributes = "";
        if ( customField.macroId != null && customField.macroId != undefined )
        {
            dataAttributes = ' data-macroId="'+customField.macroId+'" ';
        }
        if ( customField.fieldId != null && customField.fieldId != undefined )
        {
            dataAttributes = dataAttributes +' data-fieldId="'+customField.fieldId+'" ';
        }
        if ( customField.fieldType != null && customField.fieldType != undefined )
        {
            dataAttributes = dataAttributes +' data-fieldType="'+customField.fieldType+'" ';
        }
        if ( customField.value != null && customField.value != undefined )
        {
            dataAttributes = dataAttributes +' value="'+customField.value+'" ';
        }
        if ( customField.fieldName != null && customField.fieldName != undefined )
        {
            dataAttributes = dataAttributes +" data-attribute=\""+customField.fieldName+"\" ";
        }
        if(customField.elementId != null && customField.elementId != undefined){
            var gridId = customField.elementId;
            if(gridId.indexOf("LifeCycleCONFIG") != -1){
               dataAttributes = dataAttributes +' data-lifeCyleField="1" ';  
            }
        }
        
        this.init = function () {
            var defValue = customField.value;
            if(defValue !== ""){
                args.column.dataSource = [{"text": defValue, "value": defValue}];
            }
                $input = $('<select class="'+customField.elementId+'" id=\"'+customField.elementId+'\" '+dataAttributes+' ></select>');
            $input.width(args.container.clientWidth + 3);
            PopulateSelect($input[0], args.column.dataSource, true);
            $input.appendTo(args.container);
            $input.focus().select();
            
            if ( defValue == undefined || defValue == "" )
            {
                defValue = "--choose--";
            }
            else
            {
                $input.val(defValue);
            }
            $input.select2({
                placeholder: defValue,
		allowClear: false
            });
        };
        
        
        this.destroy = function () {
            $input.select2('destroy');
            $input.remove();
        };
        this.show = function () {
        };
        this.hide = function () {
            $input.select2('results_hide');
        };
        this.position = function (position) {
        };
        this.focus = function () {
            $input.select2('input_focus');
        };
        this.loadValue = function (item) {
            defaultValue = item[args.column.field];
            $input.val(defaultValue);
            $input[0].defaultValue = defaultValue;
            $input.trigger("change.select2");
        };
        this.serializeValue = function () {
            return $input.val();
        };
        this.applyValue = function (item, state) {
            item[args.column.field] = state;
        };
        this.isValueChanged = function () {
            return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
        };
        this.validate = function () {
            
               
            if (args.column.validator) {
            var validationResults = args.column.validator($input.val());
            if (!validationResults.valid) {
                $input.parent("slick-cell").addClass("invalid");
              return validationResults;
            }
          }
            return {
                valid: true,
                msg: null
            };
        };
        this.init();
        $input.on("select2:open", function() 
        {
            
            var fieldId = $(this).attr("data-fieldId");
            if ( $(this).attr('data-isLoaded') == undefined )
            {
                loadGridAdditionalFieldSelectBox( fieldId, "", this, customField.value  );
            }
            else
            {
            }
           
        });
        var currentObj = $input;
        $(document).on("keyup","input.select2-search__field", function(e){
            if (timerGridAjaxCall) {
                clearTimeout(timerGridAjaxCall);
        }
         var fieldId = $($input).attr("data-fieldId");
         timerGridAjaxCall = setTimeout(function(){
            loadGridAdditionalFieldSelectBox( fieldId, $(e.target)[0].value, $input, customField.value  );
        },1500);
        });
    }
	
    function Select2Formatter(row, cell, value, columnDef, dataContext) {
        return columnDef.dataSource[value] || '-';
    }	


    
    function PopulateSelect(select, dataSource, addBlank) {
        var index, len, newOption;
        if (addBlank) {
            select.appendChild(new Option('', ''));
        }
        $.each(dataSource, function (value, OptionData) {
            newOption = new Option(OptionData.text, OptionData.value);
            select.appendChild(newOption);
        });
    }
  function IntegerEditor(args) {
    var $input;
    var defaultValue;
    var scope = this;

    this.init = function () {
      $input = $("<INPUT type=text class='editor-text' />");

      $input.on("keydown.nav", function (e) {
        if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT) {
          e.stopImmediatePropagation();
        }
      });

      $input.appendTo(args.container);
      $input.focus().select();
    };

    this.destroy = function () {
      $input.remove();
    };

    this.focus = function () {
      $input.focus();
    };

    this.loadValue = function (item) {
      defaultValue = item[args.column.field];
      $input.val(defaultValue);
      $input[0].defaultValue = defaultValue;
      $input.select();
    };

    this.serializeValue = function () {
      return parseInt($input.val(), 10) || 0;
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
    };

    this.validate = function () {
      if (isNaN($input.val())) {
        return {
          valid: false,
          msg: "Please enter a valid integer"
        };
      }

      if (args.column.validator) {
        var validationResults = args.column.validator($input.val());
        if (!validationResults.valid) {
          return validationResults;
        }
      }

      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }

  function FloatEditor(args) {
    var $input;
    var defaultValue;
    var scope = this;

    this.init = function () {
      $input = $("<INPUT type=text class='editor-text' />");

      $input.on("keydown.nav", function (e) {
        if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT) {
          e.stopImmediatePropagation();
        }
      });

      $input.appendTo(args.container);
      $input.focus().select();
    };

    this.destroy = function () {
      $input.remove();
    };

    this.focus = function () {
      $input.focus();
    };

    function getDecimalPlaces() {
        // returns the number of fixed decimal places or null
        var rtn = args.column.editorFixedDecimalPlaces;
        if (typeof rtn == 'undefined') {
            rtn = FloatEditor.DefaultDecimalPlaces;
        }
        return (!rtn && rtn!==0 ? null : rtn);
    }

    this.loadValue = function (item) {
      defaultValue = item[args.column.field];

      var decPlaces = getDecimalPlaces();
      if (decPlaces !== null
      && (defaultValue || defaultValue===0)
      && defaultValue.toFixed) {
        defaultValue = defaultValue.toFixed(decPlaces);
      }

      $input.val(defaultValue);
      $input[0].defaultValue = defaultValue;
      $input.select();
    };

    this.serializeValue = function () {
      var rtn = parseFloat($input.val());
      if (FloatEditor.AllowEmptyValue) {
        if (!rtn && rtn !==0) { rtn = ''; }
      } else {
        rtn = rtn || 0;
      }
      
      var decPlaces = getDecimalPlaces();
      if (decPlaces !== null
      && (rtn || rtn===0)
      && rtn.toFixed) {
        rtn = parseFloat(rtn.toFixed(decPlaces));
      }

      return rtn;
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
    };

    this.validate = function () {
      if (isNaN($input.val())) {
        return {
          valid: false,
          msg: "Please enter a valid number"
        };
      }

      if (args.column.validator) {
        var validationResults = args.column.validator($input.val());
        if (!validationResults.valid) {
          return validationResults;
        }
      }

      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }

  FloatEditor.DefaultDecimalPlaces = null;
  FloatEditor.AllowEmptyValue = false;

  function DateEditor(args) { 
    var customField = getAdditionalFieldElementAttributes( args , "Textbox" );
    var dataAttributes = "";
    if ( customField.macroId != null && customField.macroId != undefined )
    {
        dataAttributes = " data-macroId=\""+customField.macroId+"\" ";
    }
    if ( customField.fieldId != null && customField.fieldId != undefined )
    {
        dataAttributes = dataAttributes +" data-fieldId=\""+customField.fieldId+"\" ";
    }
    if ( customField.fieldName != null && customField.fieldName != undefined )
    {
        dataAttributes = dataAttributes +" data-attribute=\""+customField.fieldName+"\" ";
    }
    var userDateOnlyFormatJs = 'Y-m-d';
    if ( customField.userDateOnlyJs != null && customField.userDateOnlyJs != undefined && customField.userDateOnlyJs != "")
    {
        userDateOnlyFormatJs = customField.userDateOnlyJs;
    }
    var $input;
    var defaultValue;
    var scope = this;
    var calendarOpen = false;

    this.init = function () {
      $input = $("<INPUT type=text class='editor-text dateFld "+customField.elementId+"' id=\""+customField.elementId+"\" "+dataAttributes+" autocomplete='off' />");
      $input.appendTo(args.container);
  //    $input.focus().select();
//      .on("keydown.nav", function (e) {
//        if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT ) {
//          e.stopImmediatePropagation();
//        }
//      });
            $input.datetimepicker({step: 5, timepicker: false, format: userDateOnlyFormatJs,
                onSelectDate:function(ct,$i){
                    
                    var funcName = "cmdbonSelectfunction"+customField.elementId
                    if (typeof window[funcName] =='function'){
                        eval(funcName+"()");
                    }
					if($("#"+customField.elementId).closest("#additionalFieldDiv").length==1||$("#"+customField.elementId).parents("#viewWithMenu").length==1||$("#"+customField.elementId).parents("#submitTicketParent").length==1){
						var  itsmFuncName = "newUIAdditionalFieldScriptContent"+customField.fieldId;
						 if (typeof window[itsmFuncName] == 'function'){
							$(".xdsoft_datetimepicker").remove();
							$("#"+customField.elementId).parents(".gridParentClass").data("gridInstance1").getEditorLock().commitCurrentEdit();
							eval(itsmFuncName+"()");
						}	
					}
                    }});
      $("#"+customField.elementId).select().focus();
//      $input.datepicker({
//        showOn: "button",
//        buttonImageOnly: true,
//         beforeShow: function () {
//          calendarOpen = true
//        },
//        onClose: function () {
//          calendarOpen = false
//        }
//      });
      $input.width($input.width() - 18);
    };

    this.destroy = function () {
      $.datepicker.dpDiv.stop(true, true);
      $input.datepicker("hide");
      $input.datepicker("destroy");
      $input.remove();
     
    };

    this.show = function () {
      if (calendarOpen) {
        $.datepicker.dpDiv.stop(true, true).show();
      }
    };

    this.hide = function () {
      if (calendarOpen) {
        $.datepicker.dpDiv.stop(true, true).hide();
      }
    };

    this.position = function (position) {
      if (!calendarOpen) {
        return;
      }
      $.datepicker.dpDiv
          .css("top", position.top + 30)
          .css("left", position.left);
    };

    this.focus = function () {
      $input.focus();
        $input.datetimepicker("destroy");
        $input.datetimepicker({step: 5, timepicker: false, format: userDateOnlyFormatJs,
            onSelectDate:function(ct,$i){
                var funcName = "cmdbonSelectfunction"+customField.elementId
                if (typeof window[funcName] =='function'){
                    eval(funcName+"()");
                }
            }});
    };

    this.loadValue = function (item) {
      defaultValue = item[args.column.field];
      $input.val(defaultValue);
      $input[0].defaultValue = defaultValue;
      $input.select();
    };

    this.serializeValue = function () {
      return $input.val();
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
    };

    this.validate = function () {
	
      if (args.column.validator) {
        var validationResults = args.column.validator($input.val());
        if (!validationResults.valid) {
          return validationResults;
        }
      }

      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }
  
  function DateTimeEditor(args) { 
    var customField = getAdditionalFieldElementAttributes( args , "Textbox" );
    var dataAttributes = "";
    if ( customField.macroId != null && customField.macroId != undefined )
    {
        dataAttributes = " data-macroId=\""+customField.macroId+"\" ";
    }
    if ( customField.fieldId != null && customField.fieldId != undefined )
    {
        dataAttributes = dataAttributes +" data-fieldId=\""+customField.fieldId+"\" ";
    }
    var userFormatJs = 'Y-m-d H:i';
    if ( customField.userDateTimeJs != null && customField.userDateTimeJs != undefined && customField.userDateTimeJs != "")
    {
        userFormatJs = customField.userDateTimeJs;
    }
    if ( customField.fieldName != null && customField.fieldName != undefined )
    {
        dataAttributes = dataAttributes +" data-attribute=\""+customField.fieldName+"\" ";
    }
    var $input;
    var defaultValue;
    var scope = this;
    var calendarOpen = false;

    this.init = function () {
      $input = $("<INPUT type=text class='editor-text dateFld "+customField.elementId+"' id=\""+customField.elementId+"\" "+dataAttributes+" autocomplete='off' />");
      $input.appendTo(args.container);
//      $input.focus().select()
//      .on("keydown.nav", function (e) {
//        if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT ) {
//          e.stopImmediatePropagation();
//        }
//      });
            $input.datetimepicker({step: 5, format: userFormatJs,
                onSelectDate:function(ct,$i){                    
                    var funcName = "cmdbonSelectfunction"+customField.elementId
                    if (typeof window[funcName] == 'function'){
                        eval(funcName+"()");
                    }
					if($("#"+customField.elementId).closest("#additionalFieldDiv").length==1||$("#"+customField.elementId).parents("#viewWithMenu").length==1||$("#"+customField.elementId).parents("#submitTicketParent").length==1){
						var  itsmFuncName = "newUIAdditionalFieldScriptContent"+customField.fieldId;
						 if (typeof window[itsmFuncName] == 'function'){
							$(".xdsoft_datetimepicker").remove();
							$("#"+customField.elementId).parents(".gridParentClass").data("gridInstance1").getEditorLock().commitCurrentEdit();
							eval(itsmFuncName+"()");
						}	
					}
                },onSelectTime: function(ct, $i) {                   
                    var funcName = "cmdbonSelectfunction" + customField.elementId;
                    if (typeof window[funcName]== 'function') {
                        eval(funcName + "()")
                    }
					if($("#"+customField.elementId).closest("#additionalFieldDiv").length==1||$("#"+customField.elementId).parents("#viewWithMenu").length==1||$("#"+customField.elementId).parents("#submitTicketParent").length==1){
						var  itsmFuncName = "newUIAdditionalFieldScriptContent"+customField.fieldId;
						 if (typeof window[itsmFuncName] == 'function'){
							$(".xdsoft_datetimepicker").remove();
							$("#"+customField.elementId).parents(".gridParentClass").data("gridInstance1").getEditorLock().commitCurrentEdit();
							eval(itsmFuncName+"()");
						}	
					}					
                }
            });
      $("#"+customField.elementId).select().focus();
//      $input.datepicker({
//        showOn: "button",
//        buttonImageOnly: true,
//         beforeShow: function () {
//          calendarOpen = true
//        },
//        onClose: function () {
//          calendarOpen = false
//        }
//      });
      $input.width($input.width() - 18);
    };

    this.destroy = function () {
      $.datepicker.dpDiv.stop(true, true);
      $input.datepicker("hide");
      $input.datepicker("destroy");
      $input.remove();
      
    };

    this.show = function () {
      if (calendarOpen) {
        $.datepicker.dpDiv.stop(true, true).show();
      }
    };

    this.hide = function () {
      if (calendarOpen) {
        $.datepicker.dpDiv.stop(true, true).hide();
      }
    };

    this.position = function (position) {
      if (!calendarOpen) {
        return;
      }
      $.datepicker.dpDiv
          .css("top", position.top + 30)
          .css("left", position.left);
    };

    this.focus = function () {
      $input.focus();
        $input.datetimepicker("destroy");
        $input.datetimepicker({step: 5, format: userFormatJs,
            onSelectDate:function(ct,$i){
                var funcName = "cmdbonSelectfunction"+customField.elementId
                if (typeof window[funcName] == 'function'){
                    eval(funcName+"()");
                }
            },onSelectTime: function(ct, $i) {
                var funcName = "cmdbonSelectfunction" + customField.elementId;
                if (typeof window[funcName]== 'function') {
                    eval(funcName + "()")
                }
            }
        });
    };

    this.loadValue = function (item) {
      defaultValue = item[args.column.field];
      $input.val(defaultValue);
      $input[0].defaultValue = defaultValue;
      $input.select();
    };

    this.serializeValue = function () {
      return $input.val();
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
    };

    this.validate = function () {
		
      if (args.column.validator) {
        var validationResults = args.column.validator($input.val());
        if (!validationResults.valid) {
          return validationResults;
        }
      }

      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }
  
  function TimeEditor(args) { 
    var customField = getAdditionalFieldElementAttributes( args , "Textbox" );
    var dataAttributes = "";
    if ( customField.macroId != null && customField.macroId != undefined )
    {
        dataAttributes = " data-macroId=\""+customField.macroId+"\" ";
    }
    if ( customField.fieldId != null && customField.fieldId != undefined )
    {
        dataAttributes = dataAttributes +" data-fieldId=\""+customField.fieldId+"\" ";
    }
    if ( customField.fieldName != null && customField.fieldName != undefined )
    {
        dataAttributes = dataAttributes +" data-attribute=\""+customField.fieldName+"\" ";
    }
    var userTimeOnlyFormatJs = 'H:i';
    if ( customField.userTimeOnlyJs != null && customField.userTimeOnlyJs != undefined && customField.userTimeOnlyJs != "")
    {
        userTimeOnlyFormatJs = customField.userTimeOnlyJs;
    }
    var $input;
    var defaultValue;
    var scope = this;
    var calendarOpen = false;

    this.init = function () {
      $input = $("<INPUT type=text class='editor-text dateFld "+customField.elementId+"' id=\""+customField.elementId+"\" "+dataAttributes+" autocomplete='off'/>");
      $input.appendTo(args.container);
//      $input.focus().select()
//      .on("keydown.nav", function (e) {
//        if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT ) {
//          e.stopImmediatePropagation();
//        }
//      });
      $input.datetimepicker({step: 5,datepicker: false, format: userTimeOnlyFormatJs,
	    onSelectTime: function(ct, $i) {
			if($("#"+customField.elementId).closest("#additionalFieldDiv").length==1||$("#"+customField.elementId).parents("#viewWithMenu").length==1||$("#"+customField.elementId).parents("#submitTicketParent").length==1){
			var  itsmFuncName = "newUIAdditionalFieldScriptContent"+customField.fieldId;
			 if (typeof window[itsmFuncName] == 'function'){
				$(".xdsoft_datetimepicker").remove();
				$("#"+customField.elementId).parents(".gridParentClass").data("gridInstance1").getEditorLock().commitCurrentEdit();
				eval(itsmFuncName+"()");
			 }	
			}
		}
	  });
      $("#"+customField.elementId).select().focus();
//      $input.datepicker({
//        showOn: "button",
//        buttonImageOnly: true,
//         beforeShow: function () {
//          calendarOpen = true
//        },
//        onClose: function () {
//          calendarOpen = false
//        }
//      });
      $input.width($input.width() - 18);
    };

    this.destroy = function () {
      $.datepicker.dpDiv.stop(true, true);
      $input.datepicker("hide");
      $input.datepicker("destroy");
      $input.remove();
      $(".xdsoft_datetimepicker").remove();
    };

    this.show = function () {
      if (calendarOpen) {
        $.datepicker.dpDiv.stop(true, true).show();
      }
    };

    this.hide = function () {
      if (calendarOpen) {
        $.datepicker.dpDiv.stop(true, true).hide();
      }
    };

    this.position = function (position) {
      if (!calendarOpen) {
        return;
      }
      $.datepicker.dpDiv
          .css("top", position.top + 30)
          .css("left", position.left);
    };

    this.focus = function () {
      $input.focus();
    };

    this.loadValue = function (item) {
      defaultValue = item[args.column.field];
      $input.val(defaultValue);
      $input[0].defaultValue = defaultValue;
      $input.select();
    };

    this.serializeValue = function () {
      return $input.val();
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
    };

    this.validate = function () {
        if (args.column.validator) {
        var validationResults = args.column.validator($input.val());
        if (!validationResults.valid) {
          return validationResults;
        }
      }

      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }
  function YesNoSelectEditor(args) {
    var $select;
    var defaultValue;
    var scope = this;

    this.init = function () {
      $select = $("<SELECT tabIndex='0' class='editor-yesno'><OPTION value='yes'>Yes</OPTION><OPTION value='no'>No</OPTION></SELECT>");
      $select.appendTo(args.container);
      $select.focus();
    };
    
    
        $select.multipleSelect({
            single: true,
            filter: false
        });
    this.destroy = function () {
      $select.remove();
    };

    this.focus = function () {
      $select.focus();
    };

    this.loadValue = function (item) {
      $select.val((defaultValue = item[args.column.field]) ? "yes" : "no");
      $select.select();
    };

    this.serializeValue = function () {
      return ($select.val() == "yes");
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return ($select.val() != defaultValue);
    };

    this.validate = function () {
      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }

  function CheckboxEditor(args) {
    var $select;
    var defaultValue;
    var scope = this;
    var customField = getAdditionalFieldElementAttributes( args , "Checkbox" );
    var dataAttributes = "";
    if ( customField.fieldName != null && customField.fieldName != undefined )
    {
        dataAttributes = " data-attribute='"+customField.fieldName+"' ";
    }
    this.init = function () {
      $select = $("<INPUT type='checkbox' id='"+args.column.id+"' "+dataAttributes+" value='true' class='editor-checkbox "+args.column.id+"' hideFocus> <label for='"+args.column.id+"'></label>");
      $select.appendTo(args.container);
      $select.focus();
    };

    this.destroy = function () {
      $select.remove();
    };

    this.focus = function () {
      $select.focus();
    };

    this.loadValue = function (item) {
      defaultValue = !!item[args.column.field].value;
      if (defaultValue) {
        $select.prop('checked', true);
      } else {
        $select.prop('checked', false);
      }
    };

    this.preClick = function () {
        $select.prop('checked', !$select.prop('checked'));
    };

    this.serializeValue = function () {
      return $select.prop('checked');
    };

    this.applyValue = function (item, state) {
      item[args.column.field].value = state;
    };

    this.isValueChanged = function () {
      return (this.serializeValue() !== defaultValue);
    };

    this.validate = function () {
      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }
    function CheckBoxEditor(args) {
        var $radio;
        var defaultValue;
        var scope = this;
        var customField = getAdditionalFieldElementAttributes( args , "Checkbox" );
        var dataAttributes = "";
        this.init = function () {
            $radio = $("<INPUT type='checkbox' id='"+args.column.id+"' name='"+args.column.id+"' value='true' class='editor-checkbox "+args.column.id+"' hideFocus> <label for='"+args.column.id+"'></label>");
            $radio.appendTo(args.container);
            $radio.focus();
        };

        this.destroy = function () {
            $radio.remove();
        };

        this.focus = function () {
            $radio.focus();
        };

        this.loadValue = function (item) {
            defaultValue = !!item[args.column.field];
            if(item[args.column.field]=="No"){
                defaultValue=false;
            }
            if(item[args.column.field]=="Yes"){
                defaultValue=true;
            }
            if (defaultValue) {
                $radio.prop('checked', true);
            } else {
                $radio.prop('checked', false);
            }
        };

        this.preClick = function () {
            $radio.prop('checked', !$radio.prop('checked'));
        };

        this.serializeValue = function () {
            return $radio.prop('checked');
        };

        this.applyValue = function (item, state) {
            item[args.column.field] = state;
        };

        this.isValueChanged = function () {
            return (this.serializeValue() !== defaultValue);
        };

        this.validate = function () {
            return {
                valid: true,
                msg: null
            };
        };

        this.init();
    }
  function PercentCompleteEditor(args) {
    var $input, $picker;
    var defaultValue;
    var scope = this;

    this.init = function () {
      $input = $("<INPUT type=text class='editor-percentcomplete' />");
      $input.width($(args.container).innerWidth() - 25);
      $input.appendTo(args.container);

      $picker = $("<div class='editor-percentcomplete-picker' />").appendTo(args.container);
      $picker.append("<div class='editor-percentcomplete-helper'><div class='editor-percentcomplete-wrapper'><div class='editor-percentcomplete-slider' /><div class='editor-percentcomplete-buttons' /></div></div>");

      $picker.find(".editor-percentcomplete-buttons").append("<button val=0>Not started</button><br/><button val=50>In Progress</button><br/><button val=100>Complete</button>");

      $input.focus().select();

      $picker.find(".editor-percentcomplete-slider").slider({
        orientation: "vertical",
        range: "min",
        value: defaultValue,
        slide: function (event, ui) {
          $input.val(ui.value)
        }
      });

      $picker.find(".editor-percentcomplete-buttons button").on("click", function (e) {
        $input.val($(this).attr("val"));
        $picker.find(".editor-percentcomplete-slider").slider("value", $(this).attr("val"));
      })
    };

    this.destroy = function () {
      $input.remove();
      $picker.remove();
    };

    this.focus = function () {
      $input.focus();
    };

    this.loadValue = function (item) {
      $input.val(defaultValue = item[args.column.field]);
      $input.select();
    };

    this.serializeValue = function () {
      return parseInt($input.val(), 10) || 0;
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return (!($input.val() == "" && defaultValue == null)) && ((parseInt($input.val(), 10) || 0) != defaultValue);
    };

    this.validate = function () {
      if (isNaN(parseInt($input.val(), 10))) {
        return {
          valid: false,
          msg: "Please enter a valid positive number"
        };
      }

      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }

  /*
   * An example of a "detached" editor.
   * The UI is added onto document BODY and .position(), .show() and .hide() are implemented.
   * KeyDown events are also handled to provide handling for Tab, Shift-Tab, Esc and Ctrl-Enter.
   */
  function LongTextEditor(args) {
    var $input, $wrapper;
    var defaultValue;
    var scope = this;

    this.init = function () {
      var $container = $("body");

      $wrapper = $("<DIV class='longTextContainer' style='z-index:10000;position:absolute;background:white;padding:5px;'/>")
          .appendTo($container);

      $input = $("<TEXTAREA hidefocus rows=5 style='background:white;width:250px;height:80px;border:0;outline:0'>")
          .appendTo($wrapper);

      $("<DIV class='longTextContainer_footer' style='text-align:right'><BUTTON class='longTextSaveBtn'>Save</BUTTON><BUTTON class='longTextCancelBtn'>Cancel</BUTTON></DIV>")
          .appendTo($wrapper);

      $wrapper.find("button:first").on("click", this.save);
      $wrapper.find("button:last").on("click", this.cancel);
      $input.on("keydown", this.handleKeyDown);

      scope.position(args.position);
      $input.focus().select();
    };

    this.handleKeyDown = function (e) {
      if (e.which == $.ui.keyCode.ENTER && e.ctrlKey) {
        scope.save();
      } else if (e.which == $.ui.keyCode.ESCAPE) {
        e.preventDefault();
        scope.cancel();
      } else if (e.which == $.ui.keyCode.TAB && e.shiftKey) {
        e.preventDefault();
        args.grid.navigatePrev();
      } else if (e.which == $.ui.keyCode.TAB) {
        e.preventDefault();
        args.grid.navigateNext();
      }
    };

    this.save = function () {
      args.commitChanges();
    };

    this.cancel = function () {
      $input.val(defaultValue);
      args.cancelChanges();
    };

    this.hide = function () {
      $wrapper.hide();
    };

    this.show = function () {
      $wrapper.show();
    };

    this.position = function (position) {
      $wrapper
          .css("top", position.top - 5)
          .css("left", position.left - 5)
    };

    this.destroy = function () {
      $wrapper.remove();
    };

    this.focus = function () {
      $input.focus();
    };

    this.loadValue = function (item) {
      $input.val(defaultValue = item[args.column.field]);
      $input.select();
    };

    this.serializeValue = function () {
      return $input.val();
    };

    this.applyValue = function (item, state) {
      item[args.column.field] = state;
    };

    this.isValueChanged = function () {
      return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
    };

    this.validate = function () {
      if (args.column.validator) {
        var validationResults = args.column.validator($input.val());
        if (!validationResults.valid) {
          return validationResults;
        }
      }

      return {
        valid: true,
        msg: null
      };
    };

    this.init();
  }
  selectPluginAppled=false;
    function SelectboxMultipleEditor(args) {

        var $input;
        var defaultValue;

        var customField = getAdditionalFieldElementAttributes( args , "Textbox" );

        this.init = function () {
            var defValue = customField.value;
            if(defValue !== ""){
                args.column.dataSource = [{"text": defValue, "value": defValue}];
            }
          
                $input = $('<select multiple class="' + customField.elementId + '" id=\"' + customField.elementId + '\"></select>');
            
            PopulateSelect($input[0], args.column.dataSource, true);
            $input.appendTo(args.container);
            if(args.column.cssClass=="selectCell wgSelectCell" && args.column.field =="location"){              
    var grid = $('#listingGrid').data("gridInstance1");
    var row = grid.getActiveCell().row;
    var locationSelecteddata = grid.getData()[row].location;
    var selectedIds=[];
    var selectedList = locationSelecteddata.split(",");
    $.ajax({
        url: "getLocationList.do",
        type: "POST",
        dataType: "json",
        async: false,
        data: "projectId=" + projectId,
        success: function (result) {
            var optionsHtml = "";
            $.each(result, function (key, value) {
              var selected = "";
                if (selectedList.includes(value.locationName)) {
                    selected = "selected";                    
                    selectedIds.push(value.locationId);
            }
                optionsHtml += "<option value='" + value.locationId + "' " + selected + ">" + value.locationName + "</option>";
            });
            $input.html(optionsHtml);
        },
        complete: function () {
            $input.appendTo(args.container);
            if ($input.hasClass('select2-hidden-accessible')) {
                $input.select2('destroy');
            }
            setTimeout(function () {
                $input.select2({
                    placeholder: defValue,
                    allowClear: false,
                    closeOnSelect: false,
                    minimumResultsForSearch: 0,
                    ajax: null
                });
                $input.val(selectedIds).trigger("change.select2");
            }, 0);
        }
    });
  }
             if (args.column.cssClass == "selectCell wgSelectCell" && args.column.field == "workgroupUsers") {
    var projectId = $("#projectId").val();
    var grid = $('#listingGrid').data("gridInstance1");
    var row = grid.getActiveCell().row;
    var workgroupUsersSelecteddata = grid.getData()[row].workgroupUsers;
    var selectedIds=[];
     var selectedList = workgroupUsersSelecteddata.split(",");
    $.ajax({
        url: "getWorkgroupUsersList.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data: "projectId=" + projectId,
        success: function (result) {
            var optionsHtml = "";
            $.each(result, function (key, value) {
               var selected = "";
                if (selectedList.includes(value.usersName)) {
    selected = "selected";
     selectedIds.push(value.usersId);
}
                optionsHtml += "<option value='" + value.usersId + "' " + selected + ">" + value.usersName + "</option>";
            });
            $input.html(optionsHtml);
        },
        complete: function () {
            $input.appendTo(args.container);
            if ($input.hasClass('select2-hidden-accessible')) {
                $input.select2('destroy');
            }
            setTimeout(function () {
                $input.select2({
                    placeholder: defValue,
                    allowClear: false,
                    closeOnSelect: false,
                    minimumResultsForSearch: 0,
                    ajax: null
                });
                $input.val(selectedIds).trigger("change.select2");
            }, 0);
        }
    });
}

            $input.select();
            if ( defValue == undefined || defValue == "" )
            {
                defValue = "--choose--";
            }
            else
            {
                $input.val(defValue);
            }
            if (args.column.cssClass != "selectCell wgSelectCell" && args.column.field != "workgroupUsers" && args.column.field != "location") {
            $input.select2({
                placeholder: defValue,
                allowClear: false,
                closeOnSelect: false
            });
            }
             if (($("#WorkGroupGridBlock").is(":visible")||$("#WorkflowGridBlock").is(":visible")) && args.column.cssClass == "selectCell wgSelectCell" && args.column.field != "workgroupUsers" && args.column.field != "location") {
            $input.select2({
                placeholder: defValue,
                allowClear: false,
                closeOnSelect: false
            });
            }
            var $dropdownScroll = null;
            $input.on('select2:open', function () {
              $dropdownScroll = $('.select2-results__options');
            });
            function saveScrollPosition() {
              if ($dropdownScroll && $dropdownScroll.length) {
                $input.data('scrollTop', $dropdownScroll.scrollTop());
              }
            }
            function restoreScrollPosition() {
              requestAnimationFrame(function () {
                var $newDropdownScroll = $('.select2-results__options');
                var savedScroll = $input.data('scrollTop') || 0;
                if ($newDropdownScroll.length) {
                  $newDropdownScroll.scrollTop(savedScroll);
                }
              });
            }
            $input.on('select2:selecting', saveScrollPosition);
            $input.on('select2:select', restoreScrollPosition);
            $input.on('select2:unselecting', saveScrollPosition);
            $input.on('select2:unselect', restoreScrollPosition);
        };
        this.destroy = function () {
            $input.select2('destroy');
            $input.remove();
          selectPluginAppled=false;
        };
        this.show = function () {
        };
        this.hide = function () {
        };
        this.focus = function () {
        };
        this.loadValue = function (item) {
            defaultValue = item[args.column.field];
            $input.val(defaultValue);
            $input[0].defaultValue = defaultValue;
        };
        this.serializeValue = function () {
            return $input.val();
        };
        this.applyValue = function (item, state) {
            item[args.column.field] = state;
        };
        this.isValueChanged = function () {
            return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
        };
        this.validate = function () {
            if (args.column.validator) {
                var validationResults = args.column.validator($input.val());
                if (!validationResults.valid) {
                    $input.parent("slick-cell").addClass("invalid");
                    return validationResults;
                }
            }
            return {
                valid: true,
                msg: null
            };
        };
        this.init();
        $input.on("select2:open", function()
        {
           if(args.column.field=="parentService" && selectPluginAppled==false){
                var projectId=$("#projectId").val();
                var selecteddata = args.item.parentService;
				$('#commonValidAlert').remove();
                $.ajax({
                    url: "getParentServicesList.do",
                    type: "POST",
                    dataType: 'json',
                    async: false,
                    data:"projectId="+projectId,
                    success: function (result) {
                       // $(".select2-results__options").empty();
                        $input.empty();
                        var isAllSelected="";
                        if(selecteddata=="All"){
                          isAllSelected="selected";
                        }
						$input.append("<option id='all' value='All' "+isAllSelected+">All</option>");
                        for(var i=0;i<result.length;i++){
                            var selected = "";
                            if((","+selecteddata+",").indexOf(result[i].serviceName) != -1){
                                selected = "selected";
                            }
                            $input.append("<option value='"+result[i].serviceId+"' "+selected+">"+result[i].serviceName+"</option>").trigger('change');
                        }
                        selectPluginAppled=true;
						$input.off("select2:select").on("select2:select", function (e) {
    var selectedVal = e.params.data.id;
    var currentValues = $(this).val() || [];
    if (selectedVal === "All") {
        $(this).val(["All"]).trigger("change.select2");
        setTimeout(function () {
            $('.select2-results__option[aria-selected="true"]').each(function () {
                if ($(this).text() !== "All") {
                    $(this).attr('aria-selected', 'false');
                }
            });
        }, 0);
							  }else{
        var filtered = [];
        for (var i = 0; i < currentValues.length; i++) {
            if (currentValues[i] !== "All") {
                filtered.push(currentValues[i]);
							  }
        }
        $(this).val(filtered).trigger("change.select2");
        setTimeout(function () {
            $('.select2-results__option').each(function () {
                if ($(this).text() === "All") {
                    $(this).attr('aria-selected', 'false');
                }
						});
        }, 0);
    }
});

                    },complete:function(){
                        $("#requiredField").remove();
                        $("#requiredField").remove();
                    }
                })
            }
            if(args.column.field=="serviceName"  && selectPluginAppled==false){
                var projectId=$("#projectId").val();
                var selecteddata = args.item.serviceName;
				$('#commonValidAlert').remove();
                $.ajax({
                    url: "getParentServicesList.do",
                    type: "POST",
                    dataType: 'json',
                    async: false,
                    data:"projectId="+projectId,
                    success: function (result) {
                       // $(".select2-results__options").empty();
                        $input.empty();
                        for(var i=0;i<result.length;i++){
                            var selected = "";
                            if((","+selecteddata+",").indexOf(result[i].serviceName) != -1){
                                selected = "selected";
                            }
                            $input.append("<option value='"+result[i].serviceId+"' "+selected+">"+result[i].serviceName+"</option>");
                        }
                    },complete:function(){
                        $("#requiredField").remove();
                        selectPluginAppled=true;
                    }
                });
            }
            if(args.column.field=="serviceList"  && selectPluginAppled==false){
                var projectId=$("#projectId").val();
                var selecteddata = args.item.serviceList;
				$('#commonValidAlert').remove();
                $.ajax({
                    url: "getParentServicesList.do",
                    type: "POST",
                    dataType: 'json',
                    async: false,
                    data:"projectId="+projectId,
                    success: function (result) {
                     //   $(".select2-results__options").empty();
                        $input.empty();
                        for(var i=0;i<result.length;i++){
                            var selected = "";
                            if((","+selecteddata+",").indexOf(result[i].serviceName) != -1){
                                selected = "selected";
                            }
                            $input.append("<option value='"+result[i].serviceId+"' "+selected+">"+result[i].serviceName+"</option>");
                        }
                    },complete:function(){
                        $("#requiredField").remove();
                        selectPluginAppled=true;
                    }
                });
            }
            if($("#WorkGroupGridBlock").is(":visible")==true &&args.column.cssClass=="selectCell wgSelectCell" && (args.column.field!="location" && args.column.field!="workgroupUsers") && selectPluginAppled==false){
                loadWorkGroupMultipleSelect(args.column.field);
            }
			if((args.column.field=="serviceNames" || args.column.field=="subCategory"|| args.column.field=="group") && selectPluginAppled==false){
				loadWorkFlowMultipleSelect(args.column.field);
        selectPluginAppled=true;
			}
            if( args.column.field=="service"  && args.column.cssClass=="selectCell subCategService" && selectPluginAppled==false){
                loadCategorySelectCell(args.column.field);
                selectPluginAppled=true;
            } else if((args.column.field=="service"||args.column.field=="subCategories"||args.column.field=="derivedFld1Name"||args.column.field=="derivedFld2Name") && selectPluginAppled==false){
        loadSubCategoryMultipleSelect(args.column.field);
        selectPluginAppled=true;
      }
        });
    }
	    function SelectboxSingleEditor(args) {

        var $input;
        var defaultValue;

        var customField = getAdditionalFieldElementAttributes( args , "Textbox" );
        var isSingleSelectOpened=false;
        this.init = function () {
			isSingleSelectOpened=false;
            var defValue = customField.value;
            if(defValue !== ""){
                args.column.dataSource = [{"text": defValue, "value": defValue}];
            }
            if(args.column.cssClass=="selectCell priorityMatix"){
              $input = $('<select class="' + customField.elementId + '" id=\"priority' +args.item[args.column.id][0].urgencyKey + args.item[args.column.id][0].impactKey+ '\"></select>');
            }else{
               $input = $('<select class="' + customField.elementId + '" id=\"' + customField.elementId + '\"></select>');
            }
            PopulateSelect($input[0], args.column.dataSource, true);
            $input.appendTo(args.container);
            $input.focus().select();
            if ( defValue == undefined || defValue == "" )
            {
                defValue = "--choose--";
            }
            else
            {
                $input.val(defValue);
            }
            $input.select2({
                placeholder: defValue,
                allowClear: false,
                closeOnSelect: true
            });
        };
        this.destroy = function () {
            $input.select2('destroy');
            $input.remove();
            selectPluginAppled=false;
        };
        this.show = function () {
        };
        this.hide = function () {
        };
        this.focus = function () {
        };
        this.loadValue = function (item) {
            defaultValue = item[args.column.field];
            $input.val(defaultValue);
            $input[0].defaultValue = defaultValue;
        };
        this.serializeValue = function () {
			if($(".gridViewPort--main").attr("id")=="PriorityMatrixGridBlock"){
				return $input.find("option:selected").text();
			}else{
				return $input.val();
			}
        };
        this.applyValue = function (item, state) {
			if($(".gridViewPort--main").attr("id")=="PriorityMatrixGridBlock"){
				item[args.column.field][0].selectedPriority = state;
			}else{
            item[args.column.field] = state;
			}
        };
        this.isValueChanged = function () {
            return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
        };
        this.validate = function () {
            if (args.column.validator) {
                var validationResults = args.column.validator($input.val());
                if (!validationResults.valid) {
                    $input.parent("slick-cell").addClass("invalid");
                    return validationResults;
                }
            }
            return {
                valid: true,
                msg: null
            };
        };
        this.init();
        $input.on("select2:open", function()
        {
          if(isSingleSelectOpened==false){
            isSingleSelectOpened=true;
          if(args.column.cssClass=="selectCell priorityMatix"){
            loadPrioritySelectCell('priority'+args.item[args.column.id][0].urgencyKey + args.item[args.column.id][0].impactKey);
          }else if((args.column.field=="category" || args.column.field=="service" ) && selectPluginAppled==false){
            loadCategorySelectCell(args.column.field);
			selectPluginAppled=true;
           }
			else if(args.column.field=="possibleState"||args.column.field=="presentState" && selectPluginAppled==false){
				loadStateSelectCell(args.column.field);
				selectPluginAppled=true;
			}else{
			if(selectPluginAppled==false){
            loadSingleSelectOption(args.column.field);
			selectPluginAppled=true;
			}
    }
    }
        });
    }
})(jQuery);

function getAdditionalFieldElementAttributes( gridData , fieldType )
{
   
    if (gridData.item == "" )
    {
        return false;
    }
    var customFieldElementAttributes = new Object();
     if (gridData.column.field != null && gridData.column.field != undefined)
        customFieldElementAttributes ["elementId"] = gridData.column.field;

    if (gridData.column.columnAttributes != null && gridData.column.columnAttributes != undefined)
        customFieldElementAttributes ["macroId"] = gridData.column.columnAttributes.columnMacroId;
    
    if (gridData.column.columnAttributes != null && gridData.column.columnAttributes != undefined)
        customFieldElementAttributes ["fieldType"] = gridData.column.columnAttributes.columnHtmlType;

    if (gridData.column.columnAttributes != null && gridData.column.columnAttributes != undefined)
        customFieldElementAttributes ["fieldId"] = gridData.column.columnAttributes.fieldId;

    if (gridData.column.columnAttributes != null && gridData.column.columnAttributes != undefined)
        customFieldElementAttributes ["value"] = gridData.column.columnAttributes.columnValue;
    
    if(gridData.column.columnAttributes != null && gridData.column.columnAttributes.columnType!=undefined)
        customFieldElementAttributes ["columnType"] = gridData.column.columnAttributes.columnType;
    
    if (gridData.column.columnAttributes != undefined && gridData.column.columnAttributes.fieldId != undefined)
    {
        if( gridData.item != undefined && gridData.item["CUSTOMFIELD"+gridData.column.columnAttributes.fieldId] != null && gridData.item["CUSTOMFIELD"+gridData.column.columnAttributes.fieldId] != undefined )
        customFieldElementAttributes ["value"] = gridData.item["CUSTOMFIELD"+gridData.column.columnAttributes.fieldId];
        else  if( gridData.item != undefined && gridData.item["LifeCycleCONFIG_"+gridData.column.columnAttributes.fieldId] != null && gridData.item["LifeCycleCONFIG_"+gridData.column.columnAttributes.fieldId] != undefined )
            customFieldElementAttributes ["value"] = gridData.item["LifeCycleCONFIG_"+gridData.column.columnAttributes.fieldId];
    }
        
    if (gridData.column.columnAttributes != null && gridData.column.columnAttributes != undefined)
        customFieldElementAttributes ["fieldName"] = gridData.column.columnAttributes.fieldName;
    
    if (gridData.column.columnAttributes != undefined && gridData.column.columnAttributes.userDateTimeJs != undefined)
    {
        customFieldElementAttributes ["userDateTimeJs"] = gridData.column.columnAttributes.userDateTimeJs;
    }
    if (gridData.column.columnAttributes != undefined && gridData.column.columnAttributes.userDateJs != undefined)
    {
        customFieldElementAttributes ["userDateOnlyJs"] = gridData.column.columnAttributes.userDateJs;
    }
    if (gridData.column.columnAttributes != undefined && gridData.column.columnAttributes.userTimeJs != undefined)
    {
        customFieldElementAttributes ["userTimeOnlyJs"] = gridData.column.columnAttributes.userTimeJs;
    }
    
    switch ( fieldType )
    {
        case "Textbox" :
            break;
        case "Selectbox" :
            break;
        case "Checkbox" :
            break;
        case "Datefield" :
            break;
    }
    return customFieldElementAttributes;
}

function isNumberKey(evt, colType, colValue)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode;
     if (colType==="number" && (charCode > 31 && (charCode < 48 || charCode > 57))){
         return false;
     }else if(colType==="float" && (charCode > 31 && (charCode < 48 || charCode > 57))){
         if(charCode!==46){
             return false;
         }
     }
     if(colType==="float" && charCode===46 && colValue.indexOf('.')!==-1){
         return false;
     }
    return true;
}
