/*!@license
 * Infragistics.Web.ClientUI Grid Column Moving 14.1.20141.1020
 *
 * Copyright (c) 2011-2014 Infragistics Inc.
 *
 * http://www.infragistics.com/
 *
 * Depends on:
 *	jquery-1.4.4.js
 *	jquery.ui.core.js
 *	jquery.ui.widget.js
 *	infragistics.ui.grid.framework.js
 *	infragistics.ui.tree.js
 *	infragistics.ui.shared.js
 *	infragistics.dataSource.js
 *	infragistics.util.js
 */
if(typeof jQuery!=="function"){throw new Error("jQuery is undefined")}(function($){$.widget("ui.igGridColumnMoving",{renderInFeatureChooser:true,options:{columnSettings:[{columnKey:null,columnIndex:null,allowMoving:true}],mode:"immediate",moveType:"dom",addMovingDropdown:true,movingDialogWidth:400,movingDialogHeight:"",movingDialogAnimationDuration:200,movingAcceptanceTolerance:20,movingScrollTolerance:20,scrollSpeedMultiplier:2,scrollDelta:2,hideHeaderContentsDuringDrag:true,dragHelperOpacity:1,movingDialogCaptionButtonDesc:$.ig.ColumnMoving.locale.movingDialogCaptionButtonDesc,movingDialogCaptionButtonAsc:$.ig.ColumnMoving.locale.movingDialogCaptionButtonAsc,movingDialogCaptionText:$.ig.ColumnMoving.locale.movingDialogCaptionText,movingDialogDisplayText:$.ig.ColumnMoving.locale.movingDialogDisplayText,dropDownMoveLeftText:$.ig.ColumnMoving.locale.dropDownMoveLeftText,dropDownMoveRightText:$.ig.ColumnMoving.locale.dropDownMoveRightText,dropDownMoveFirstText:$.ig.ColumnMoving.locale.dropDownMoveFirstText,dropDownMoveLastText:$.ig.ColumnMoving.locale.dropDownMoveLastText,movingToolTipMove:$.ig.ColumnMoving.locale.movingToolTipMove,featureChooserSubmenuText:$.ig.ColumnMoving.locale.featureChooserSubmenuText},css:{headerCellMouseOver:"ui-state-hover",dropDownButton:"ui-iggrid-moving-indicator",dropDownIndicatorContainer:"ui-iggrid-indicatorcontainer",dragIndicatorTop:"ui-iggrid-columnmoving-dragtop",dragIndicatorBottom:"ui-iggrid-columnmoving-dragbottom",dropDownIconContainer:"ui-iggrid-columnmovingiconcontainer",featureChooserMovingDialogIcon:"ui-icon ui-iggrid-icon-move",featureChooserLeftIcon:"ui-iggrid-featurechooser-li-iconcontainer ui-icon ui-iggrid-icon-left",featureChooserRightIcon:"ui-iggrid-featurechooser-li-iconcontainer ui-icon ui-iggrid-icon-right",featureChooserFirstIcon:"ui-iggrid-featurechooser-li-iconcontainer ui-icon ui-iggrid-icon-first",featureChooserLastIcon:"ui-iggrid-featurechooser-li-iconcontainer ui-icon ui-iggrid-icon-last",featureChooserSubmenu:"ui-iggrid-featurechooser-list-submenu ui-menu ui-widget ui-widget-content ui-corner-all",featureChooserSubmenuItem:"ui-iggrid-featurechooser-list-submenu-item ui-state-default",featureChooserSubmenuItemMouserOver:"ui-state-hover",columnMovingDropDown:"ui-iggrid-columnmoving-dropdown-dialog ui-widget ui-widget-content ui-corner-all",columnMovingDropDownList:"ui-iggrid-columnmoving-dropdown-list ui-menu",columnMovingDropDownItem:"ui-iggrid-columnmoving-dropdown-ddlistitemicons ui-state-default",columnMovingDropDownItemHover:"ui-iggrid-columnmoving-dropdown-listitem-hover ui-state-active ui-state-hover",columnMovingDropDownItemText:"ui-iggrid-columnmoving-dropdown-ddlistitemtext",columnMovingIndicatorSelected:"ui-iggrid-hiding-indicator-selected",movingDialogItemList:"ui-iggrid-moving-dialog-columns",movingDialogListItem:"ui-widget-content",movingDialogListItemArrowUp:"ui-icon-arrowthick-1-n ui-button-icon-primary ui-icon",movingDialogListItemArrowDown:"ui-icon-arrowthick-1-s ui-button-icon-primary ui-icon",movingDialogListItemArrowButton:"ui-button ui-corner-all ui-button-icon-only ig-sorting-indicator",movingDialogListItemText:"ui-iggrid-dialog-text",movingDialogCloseButton:"ui-icon ui-icon-close"},events:{columnDragStart:"columnDragStart",columnDragEnd:"columnDragEnd",columnDragCanceled:"columnDragCanceled",columnMoving:"columnMoving",columnMoved:"columnMoved",movingDialogOpening:"movingDialogOpening",movingDialogOpened:"movingDialogOpened",movingDialogDragged:"movingDialogDragged",movingDialogClosing:"movingDialogClosing",movingDialogClosed:"movingDialogClosed",movingDialogContentsRendering:"movingDialogContentsRendering",movingDialogContentsRendered:"movingDialogContentsRendered",movingDialogMoveUpButtonPressed:"movingDialogMoveUpButtonPressed",movingDialogMoveDownButtonPressed:"movingDialogMoveDownButtonPressed",movingDialogDragColumnMoving:"movingDialogDragColumnMoving",movingDialogDragColumnMoved:"movingDialogDragColumnMoved"},_createWidget:function(options,element){this.options.columnSettings=[];$.Widget.prototype._createWidget.apply(this,arguments)},_create:function(){this._cache={};this._cKey="";this._cIdx=-1;this._tKey="";this._tIdx=-1;this._oTh=null;this._cmib=null;this._cmit=null;this._movingDialog=null;this._groupBy=null;this._ddButtons={first:{text:this.options.dropDownMoveFirstText,func:$.proxy(this._moveFirst,this),icon:this.css.featureChooserFirstIcon},left:{text:this.options.dropDownMoveLeftText,func:$.proxy(this._moveLeft,this),icon:this.css.featureChooserLeftIcon},right:{text:this.options.dropDownMoveRightText,func:$.proxy(this._moveRight,this),icon:this.css.featureChooserRightIcon},last:{text:this.options.dropDownMoveLastText,func:$.proxy(this._moveLast,this),icon:this.css.featureChooserLastIcon}};this._hscroller=null;this._scroller={on:false,delay:-1};if(this.options.mode!=="immediate"&&this.options.mode!=="deferred"){this.options.mode="immediate"}if(this.options.mode==="immediate"&&this.options.moveType==="render"){this.options.moveType="dom"}if(this.options.addMovingDropdown===false){this.renderInFeatureChooser=false}},_setOption:function(key,value){if(key==="mode"||key==="columnSettings"||key==="addMovingDropdown"){throw new Error($.ig.Grid.locale.optionChangeNotSupported+" "+key)}$.Widget.prototype._setOption.apply(this,arguments)},destroy:function(){this._unregisterEvents();this._removeMoving();$.Widget.prototype.destroy.call(this);return this},moveColumn:function(column,target,after,inDom){this._moveColumn(column,target,after,inDom,true)},_headerCellRendered:function(event,args){if(this.grid.id()!==args.owner.id()){return}this._thRendered(args.th)},_headerRendering:function(event,args){var i;for(i=0;i<this.grid.options.features.length;i++){if(this.grid.options.features[i].name==="GroupBy"){this._groupBy=this.grid.element.data("igGridGroupBy");break}}},_headerRendered:function(event,args){if(this.grid.id()!==args.owner.id()){return}this._thsRendered(args.table)},_gridFullyRendered:function(event,args){this._updateLayout()},_headerPicked:function(event,args){var $th=$(event.target).closest("th"),id=this._getIdOfTh($th),noCancel=true;args={columnKey:id,columnIndex:$th.index(),owner:this,header:$th,helper:args.helper};noCancel=this._trigger(this.events.columnDragStart,event,args);if(noCancel){if(this.grid._focusedElement){this.grid._focusedElement.blur()}this._thPicked($th,id)}return noCancel},_headerDragged:function(event,args){var left;if(this._oPos){left=this._oPos.left>args.position.left}else{left=args.originalPosition.left>args.position.left}this._oPos={left:args.position.left};if(this._thDragged(args.helper,args.offset,left)){args.originalPosition.left=args.position.left}},_headerDropped:function(event,args){var $th=$(event.target).closest("th"),id=this._getIdOfTh($th),noCancel=true;args={columnKey:id,columnIndex:$th.index(),owner:this,header:$th,helper:args.helper};noCancel=this._trigger(this.events.columnDragEnd,event,args);if(noCancel){this._thDropped()}else{this._trigger(this.events.columnDragCanceled,event,args)}return noCancel},_dialogUpPressed:function(event,args){var tar=$(event.target),item=tar.closest("li"),parent=item.parent(),idx=item.index(),iItem=idx===0?item.parent().children().last().attr("data-value"):item.prev().attr("data-value"),iDir=idx===0?true:false,col=tar.closest("span").attr("datakey"),a;a={owner:this,movingDialog:this._movingDialog,columnKey:col,columnIndex:idx,targetIndex:idx===0?parent.children().length-1:idx-1};if(idx===0){item.detach().insertAfter(parent.children("li:last"))}else{item.detach().insertBefore(parent.children("li:eq("+(idx-1)+")"))}this._cKey=col;this._cIdx=a.columnIndex;this._tIdx=a.targetIndex;this._moveColumn(col,iItem,iDir,this.options.moveType==="dom",false);this._trigger(this.events.movingDialogMoveUpButtonPressed,null,a)},_dialogDownPressed:function(event,args){var tar=$(event.target),item=tar.closest("li"),parent=item.parent(),idx=item.index(),iItem=idx===item.siblings().length?item.parent().children().first().attr("data-value"):item.next().attr("data-value"),iDir=idx===item.siblings().length?false:true,col=tar.closest("span").attr("datakey"),a;a={owner:this,movingDialog:this._movingDialog,columnKey:col,columnIndex:idx,targetIndex:idx===parent.children().length-1?0:idx+1};if(idx===item.parent().children().length-1){item.detach().insertBefore(parent.children("li:first"))}else{item.detach().insertAfter(parent.children("li:eq("+idx+")"))}this._cKey=col;this._cIdx=a.columnIndex;this._tIdx=a.targetIndex;this._moveColumn(col,iItem,iDir,this.options.moveType==="dom",false);this._trigger(this.events.movingDialogMoveDownButtonPressed,null,a)},_dialogRearranging:function(event,args){var noCancel,a,column=$(args.draggable),target=$(args.element),cid=column.attr("data-value"),tid=target.attr("data-value"),aft=$(args.element).closest("ul[data-depth=0]").data("igTree")._validationObject.dropAfter,cix=column.index(),tix=target.index();tix=tix>cix?aft?tix:tix-1:aft?tix+1:tix;a={owner:this,movingDialog:this._movingDialog,columnKey:cid,columnIndex:cix,targetIndex:tix};noCancel=this._trigger(this.events.movingDialogDragColumnMoving,null,a);if(noCancel){this._cKey=cid;this._cIdx=a.columnIndex;this._tIdx=a.targetIndex;this._moveColumn(cid,tid,aft,this.options.moveType==="dom",false);a.movingDialog.find("div.ui-state-highlight").remove();this._trigger(this.events.movingDialogDragColumnMoved,null,a);return true}return false},_dialogRearranged:function(event,args){this._bindUpDownDialogButtons(args.element.parent())},_dialogDragged:function(event,args){this._trigger(this.events.movingDialogDragged,null,{movingDialogElement:event.target,owner:this,originalPosition:args.originalPosition,position:args.position})},_dialogOpening:function(event,args){var noCancel;noCancel=this._trigger(this.events.movingDialogOpening,null,{movingDialogElement:event.target,owner:this});if(noCancel){this._renderMovingDialogContent(event,args);this._trigger(this.events.movingDialogOpened,null,{movingDialogElement:event.target,owner:this})}return noCancel},_dialogClosing:function(event,args){return this._trigger(this.events.movingDialogClosing,null,{movingDialogElement:event.target,owner:this})},_dialogClosed:function(event,args){this._trigger(this.events.movingDialogClosed,null,{movingDialogElement:event.target,owner:this})},_dropDownMouseDown:function(event,args){var ind=$(event.target);this._toggleDropDown(ind,$("div[data-moving-inddropdown='"+this.grid.id()+"']"));this._cancelEvent(event)},_dropDownKeyDown:function(event,args){var sItem,nItem,nItemB,dropdown=$("div[data-moving-inddropdown='"+this.grid.id()+"']");if(event.keyCode===$.ui.keyCode.ENTER||event.keyCode===$.ui.keyCode.SPACE){sItem=dropdown.find("ul .ui-state-hover:first");if(dropdown.is(":visible")&&sItem.length>0){sItem.trigger("mousedown")}this._toggleDropDown($(event.target),dropdown,false);this._cancelEvent(event)}else if(event.keyCode===$.ui.keyCode.ESCAPE){this._toggleDropDown($(event.target),dropdown,false);this._cancelEvent(event)}else if(event.keyCode===$.ui.keyCode.DOWN||event.keyCode===$.ui.keyCode.UP){if(dropdown.is(":visible")){sItem=dropdown.find("ul .ui-state-hover:first").closest("li");if(sItem.length===0){nItem=dropdown.find("ul li:eq(0)")}else{if(sItem.index()===0&&event.keyCode===$.ui.keyCode.UP){nItem=sItem.parent().children(":last")}else{nItem=event.keyCode===$.ui.keyCode.DOWN?sItem.next():sItem.prev()}}dropdown.find("ul .ui-state-hover").removeClass(this.css.columnMovingDropDownItemHover);nItemB=nItem.find("[role='button']");if(nItemB.length>0){nItem=nItemB}nItem.addClass(this.css.columnMovingDropDownItemHover)}this._cancelEvent(event)}},_dropDownButtonMouseOver:function(event,args){$(event.currentTarget).addClass(this.css.columnMovingDropDownItemHover)},_dropDownButtonMouseOut:function(event,args){$(event.currentTarget).removeClass(this.css.columnMovingDropDownItemHover)},_moveLeft:function(event,args){var sib=this._cache.siblings[args],cid,tid,i;for(i=0;i<sib.length;i++){cid=sib[i].key||sib[i].identifier;if(cid===args){if(i>0){this._cKey=args;this._cIdx=i;this._tIdx=i-1;tid=sib[i-1].key||sib[i-1].identifier;this._moveColumn(cid,tid,false,this.options.moveType==="dom",false)}break}}},_moveRight:function(event,args){var sib=this._cache.siblings[args],cid,tid,i;for(i=0;i<sib.length;i++){cid=sib[i].key||sib[i].identifier;if(cid===args){if(i<sib.length-1){this._cKey=args;this._cIdx=i;this._tIdx=i+1;tid=sib[i+1].key||sib[i+1].identifier;this._moveColumn(cid,tid,true,this.options.moveType==="dom",false)}break}}},_moveFirst:function(event,args){var sib=this._cache.siblings[args],cid,tid,i;for(i=0;i<sib.length;i++){cid=sib[i].key||sib[i].identifier;if(cid===args){if(i!==0){this._cKey=args;this._cIdx=i;this._tIdx=0;tid=sib[0].key||sib[0].identifier;this._moveColumn(cid,tid,false,this.options.moveType==="dom",false)}break}}},_moveLast:function(event,args){var sib=this._cache.siblings[args],cid,tid,i;for(i=0;i<sib.length;i++){cid=sib[i].key||sib[i].identifier;if(cid===args){if(i!==sib.length-1){this._cKey=args;this._cIdx=i;this._tIdx=sib.length-1;tid=sib[sib.length-1].key||sib[sib.length-1].identifier;this._moveColumn(cid,tid,true,this.options.moveType==="dom",false)}break}}},_headerMouseOver:function(event,args){$(event.target).closest("th").addClass(this.css.headerCellMouseOver)},_headerMouseOut:function(event,args){$(event.target).closest("th").removeClass(this.css.headerCellMouseOver)},_renderHelpers:function(){this._cmib=$("<div>&nbsp;</div>").attr("id",this.grid.id()+"_moving_indicator_bottom").addClass(this.css.dragIndicatorTop).css({position:"absolute","z-index":"1000000",width:"16px",height:"16px",display:"none"}).appendTo(this.grid._rootContainer());this._cmit=$("<div>&nbsp;</div>").attr("id",this.grid.id()+"_moving_indicator_top").addClass(this.css.dragIndicatorBottom).css({position:"absolute","z-index":"1000000",width:"16px",height:"16px",display:"none"}).appendTo(this.grid._rootContainer())},_renderFeatureChooser:function(col,th){var fc=this.grid.element.data("igGridFeatureChooser");if(fc){if(fc._shouldRenderInFeatureChooser(col)===true){this._addMoveButtonsInFeatureChooser(fc,col)}else{this._renderMovingDropDownIndicator(th,col);this.grid._enableHeaderCellFeature(th)}}},_renderMovingDropDownIndicator:function(th,col){var $button,$anchor,$container,self=this;$button=$("<span></span>").addClass(this.css.dropDownButton);$anchor=$("<a></a>").attr("href","#").attr("th-remove-focus","").attr("title",this.options.movingToolTipMove).attr("id",this.grid.id()+"_moving_headerButton_"+col).bind({keydown:this._dropDownKeyHandler,blur:function(e){self._toggleDropDown($(e.target),$("div[data-moving-inddropdown='"+self.grid.id()+"']"),true)},mousedown:this._dropDownButtonHandler,mouseup:this._cancelEventHandler,click:this._cancelEventHandler});$container=$("<div></div>").addClass(this.css.dropDownIndicatorContainer).appendTo(th);$button.appendTo($anchor);$anchor.appendTo($container);this._needToRenderDropDown=true},_renderMovingDialogContent:function(){var $content=this._movingDialog.igGridModalDialog("getContent"),movingDialog=this._movingDialog,$tree=$content.find("#"+this.grid.id()+"_dialog_tree"),noCancel;noCancel=this._trigger(this.events.movingDialogContentsRendering,null,{movingDialogElement:movingDialog,owner:this});if(noCancel){if($tree.length>0){$tree.igTree("option","dataSource",this._getClonedDataSource(this.grid._visibleMchColumns()||this.grid._visibleColumns()))}else{$tree=this._initializeTree($content)}this._bindUpDownDialogButtons($tree);this._trigger(this.events.movingDialogContentsRendered,null,{movingDialogElement:movingDialog,owner:this})}},_initializeTree:function(content){var self=this;return $("<ul id='"+this.grid.id()+"_dialog_tree'></ul>").appendTo(content).igTree({dataSourceType:"json",dataSource:this._getClonedDataSource(this.grid._visibleMchColumns()||this.grid._visibleColumns()),bindings:{primaryKey:"key",textKey:"headerText",valueKey:"key",childDataProperty:"group",nodeContentTemplate:this._getTreeTemplate()},dragAndDrop:true,dragAndDropSettings:{dragAndDropMode:"move",revert:true,zIndex:1000001,customDropValidation:function(col){var context=$(this),$col=$(col);if(self._isColumnMovable($col.attr("data-value"))){if(context.is("li")&&context.parent()[0]===$col.parent()[0]){return true}}return false},containment:false},nodeDropping:this._dialogRearrangingHandler,nodeDropped:this._dialogRearrangedHandler,selectionChanging:function(){return false}})},_getClonedDataSource:function(ds){return jQuery.extend(true,[],ds,this._cloneMovable(ds))},_cloneMovable:function(ds){var self=this,movableClone=[],idx=0;$.each(ds,function(){if(this.group){movableClone.push({movable:self._isColumnMovable(this.key,idx++),group:self._cloneMovable(this.group),key:this.key||this.identifier||idx})}else{movableClone.push({movable:self._isColumnMovable(this.key,idx++),key:this.key||idx})}});return movableClone},_getTreeTemplate:function(){var tmpl="",up,down,wrapper,data;data="<span>${headerText}</span>";wrapper="<span class='"+this.css.movingDialogListItemArrowButton+"'>";up=wrapper+"<span id='"+this.grid.id()+"_moving_dialog_${key}_up' title='"+this.options.movingDialogCaptionButtonAsc+"' role='button' datakey='${key}' class='"+this.css.movingDialogListItemArrowUp+"' style='"+"margin-top:-10px;'></span></span>";down=wrapper+"<span id='"+this.grid.id()+"_moving_dialog_${key}_down' title='"+this.options.movingDialogCaptionButtonDesc+"' role='button' datakey='${key}' class='"+this.css.movingDialogListItemArrowDown+"' style='"+"margin-top:-10px;'></span></span>";wrapper+="</span>";tmpl+="{{if ${movable} }}";tmpl+=up+down+data;tmpl+="{{else}}";tmpl+=wrapper+wrapper+data;tmpl+="{{/if}}";return tmpl},_renderMovingDialog:function(){var o=this.options,$captionButtonContainer,$closeButton,movingDialog=$("<div></div>").appendTo(this.grid._rootContainer()).attr("id",this.grid.id()+"_moving_movingDialog");this._movingDialog=movingDialog;movingDialog.igGridModalDialog({renderFooterButtons:false,modalDialogCaptionText:o.movingDialogCaptionText,modalDialogWidth:o.movingDialogWidth,modalDialogHeight:o.movingDialogHeight,animationDuration:o.movingDialogAnimationDuration,gridContainer:this.grid.container(),modalDialogOpening:this._dialogOpeningHandler,modalDialogMoving:this._dialogDraggedHandler,modalDialogClosing:this._dialogClosingHandler,modalDialogClosed:this._dialogClosedHandler});$captionButtonContainer=movingDialog.igGridModalDialog("getCaptionButtonContainer");$closeButton=$("<button></button>").attr("id",this.grid.id()+"_moving_movingDialog_closeButton").appendTo($captionButtonContainer);$closeButton.igButton({onlyIcons:true,icons:{primary:this.css.movingDialogCloseButton},width:"20px",height:"20px",click:this._dialogCloseButtonHandler})},_renderDropDown:function(element){var self=this,dropDown,list;dropDown=$("<div data-moving-inddropdown='"+this.grid.id()+"'></div>").css("position","absolute").css("display","none").addClass(this.css.columnMovingDropDown).appendTo(this.grid._rootContainer());list=$('<ul tabindex="0"></ul>').addClass(this.css.columnMovingDropDownList).appendTo(dropDown);$.each(this._ddButtons,function(key,val){$("<li></li>").addClass(self.css.columnMovingDropDownItem).attr("data-key",key).bind({mouseover:self._dropDownButtonMouseOverHandler,mouseout:self._dropDownButtonMouseOutHandler}).append($("<span></span>").addClass(self.css.dropDownIconContainer).append($("<span></span>").addClass(val.icon))).append($("<span></span>").addClass(self.css.columnMovingDropDownItemText).text(val.text)).appendTo(list)});$("<a></a>").appendTo($("<li></li>").appendTo(list)).igButton({labelText:this.options.movingDialogCaptionText,mousedown:function(event){if(event.target){setTimeout(function(){$(event.target).removeClass("ui-state-active")},0)}self._toggleDropDown(element,dropDown,true);self._openMovingDialog(element,dropDown,true)}});return dropDown},_toggleDropDown:function(element,dropDown,isCalledFromBlur){var th,id,isLast,offset,rOffset,left,isVisible=dropDown.is(":visible")===true,self=this;if(dropDown.data("isAnimating")===true||isVisible===false&&isCalledFromBlur===true){return}if(!isVisible){th=element.closest("th");isLast=th.parent().children().length-th.index()<=2;offset=th.offset();if(isLast){left=offset.left+th.outerWidth()-dropDown.outerWidth();left=Math.max(0,left)}else{left=offset.left}rOffset=$.ig.util.getRelativeOffset(dropDown);dropDown.css("top",offset.top+th.outerHeight()-rOffset.top);dropDown.css("left",left-rOffset.left);$.each(this._ddButtons,function(key,value){dropDown.find("li[data-key='"+key+"']").bind("mousedown.temp",function(event){self._toggleDropDown(element,dropDown,true);id=th.attr("id");if(id){id=id.replace(self.grid.id()+"_","")}else{id=th.attr("data-mch-id")}value.func(null,id);event.stopPropagation();event.preventDefault()})})}else{$.each(this._ddButtons,function(key,value){dropDown.find("li[data-key='"+key+"']").unbind("mousedown.temp")})}dropDown.data("isAnimating",true);dropDown.toggle(200,function(){if(dropDown.is(":visible")===true){th.find("a").focus();if(element){element.addClass(self.css.columnMovingIndicatorSelected);element.attr("data-indicator-selected","true")}}else{if(element){element.removeClass(self.css.columnMovingIndicatorSelected);element.removeAttr("data-indicator-selected")}}dropDown.data("isAnimating",false)})},_renderSubmenuFC:function(columnKey,$submenu){var $ul,moveColumns,moveLeft,moveRight,moveFirst,moveLast;$ul=$('<ul class="'+this.css.featureChooserSubmenu+'"></ul>').appendTo($submenu);moveColumns={name:"ColumnMovingDialog",text:this.options.movingDialogDisplayText,iconClass:this.css.featureChooserMovingDialogIcon,method:this._openMovingDialogHandler};moveLeft={name:"Left",text:this.options.dropDownMoveLeftText,iconClass:this.css.featureChooserLeftIcon,method:$.proxy(this._moveLeft,this)};moveRight={name:"Right",text:this.options.dropDownMoveRightText,iconClass:this.css.featureChooserRightIcon,method:$.proxy(this._moveRight,this)};moveFirst={name:"First",text:this.options.dropDownMoveFirstText,iconClass:this.css.featureChooserFirstIcon,method:$.proxy(this._moveFirst,this)};moveLast={name:"Last",text:this.options.dropDownMoveLastText,iconClass:this.css.featureChooserLastIcon,method:$.proxy(this._moveLast,this)};this._renderSubmenuFCItem(moveColumns,$ul,columnKey,$submenu);this._renderSubmenuFCItem(moveFirst,$ul,columnKey,$submenu);this._renderSubmenuFCItem(moveLeft,$ul,columnKey,$submenu);this._renderSubmenuFCItem(moveRight,$ul,columnKey,$submenu);this._renderSubmenuFCItem(moveLast,$ul,columnKey,$submenu)},_renderSubmenuFCItem:function(obj,$ul,columnKey,$submenu){var $li,text=obj.text,html,fnBlur,$next,css=this.css,id=this.grid.id()+"_featurechooser_dd_li_"+columnKey+"_"+obj.name,method=obj.method;fnBlur=function($e){setTimeout(function(){$e.blur()},50)};html='<li tabindex="0" data-fc-item="1" class="'+this.css.featureChooserSubmenuItem+'" id="'+id+'" title="'+text+'">'+text+"</li>";$li=$(html).appendTo($ul);$li.bind({keydown:function(event){var keyCode=event.keyCode;switch(keyCode){case $.ui.keyCode.ENTER:case $.ui.keyCode.SPACE:method(event,columnKey);fnBlur($(event.target));break;case $.ui.keyCode.DOWN:$next=$li.next();if($next.length===0){$ul.find("li:first").focus()}else{$next.focus()}break;case $.ui.keyCode.UP:$li.prev().focus();if($li.prev().length===0){$("#"+$submenu.data("buttonId")).focus()}break;case $.ui.keyCode.ESCAPE:fnBlur($(event.target));break}},mousedown:function(e,args){method(e,columnKey);fnBlur($(e.target))},mouseover:function(e,args){$(this).addClass(css.featureChooserSubmenuItemMouserOver)},mouseleave:function(e,args){$(this).removeClass(css.featureChooserSubmenuItemMouserOver)}})},_addMoveButtonsInFeatureChooser:function(fc,key){fc._renderInFeatureChooser(key,{name:"ColumnMovingDropDown",text:this.options.featureChooserSubmenuText,iconClass:"ui-iggrid-featurechooser-li-iconcontainer ui-icon ui-iggrid-icon-move",methodRenderSubmenu:$.proxy(this._renderSubmenuFC,this),order:1,groupName:"dropdown",groupOrder:4,type:"dropdown",state:"hide"})},_moveColumn:function(column,target,after,inDom,fromApi){var noCancel=true,args;if(fromApi===false){args={columnKey:this._cKey,columnIndex:this._cIdx,targetIndex:this._tIdx,owner:this};noCancel=this._trigger(this.events.columnMoving,null,args)}if(noCancel){this._movingDirty=true;this.grid.moveColumn(column,target,after,inDom);if(fromApi===false){delete args.columnIndex;delete args.targetIndex;args.oldIndex=this._cIdx;args.newIndex=this._tIdx;this._triggerColumnMovedAsync(args)}}},_thRendered:function(th){var cid=this._getIdOfTh(th),cix=th.index("not[data-skip='true']");if(this._isColumnMovable(cid,cix)===true){this._markForMoving(th);if(this.options.addMovingDropdown===true){this._renderFeatureChooser(cid,th)}}},_thsRendered:function(table){if(this.options.mode==="deferred"){this._renderHelpers()}if(this.options.addMovingDropdown===true){if(!this._movingDialog||this._movingDialog instanceof jQuery&&this._movingDialog.length===0){this._renderMovingDialog()}if($("div[data-moving-inddropdown='"+this.grid.id()+"']").length===0){this._renderDropDown()}}},_thPicked:function(th,id){this._cKey=id;this._cIdx=th.index();if(this.options.mode==="immediate"){if(this.options.hideHeaderContentsDuringDrag===true){th.children().not("div[data-hiddencolindicator]").hide()}this._oTh=th}},_thDragged:function(helper,pos,left){var siblings,targetKey,targetPosition,targetLeft,scrollLeft=0,dragX,i=0,j=0,updateEvent=false;siblings=this._cache.siblings[this._cKey];if(this._hscroller.length>0){scrollLeft=this._hscroller.scrollLeft()}dragX=left===true?pos.left:pos.left+helper.width();dragX+=scrollLeft;if(!this._gridReady()||this._movingDirty){return}while(i<=siblings.length){j=i===siblings.length?i-1:i;targetKey=siblings[j].key||siblings[j].identifier;if(targetKey===this._cKey&&this.options.mode==="immediate"){i+=2;continue}targetPosition=this._cache.columns[targetKey];targetLeft=j!==i?targetPosition.offset.left+targetPosition.dimensions.width:targetPosition.offset.left;if(dragX>targetLeft-this.options.movingAcceptanceTolerance&&dragX<targetLeft+this.options.movingAcceptanceTolerance){this._tKey=targetKey;this._tIdx=this._cIdx>j||j!==i?j:j-1;if(this.options.mode==="immediate"){this._moveColumn(this._cKey,targetKey,j!==i?true:false,true,false);updateEvent=true}else{this._last=i===siblings.length;this._showIndicators(targetLeft-scrollLeft,targetPosition.element.offset().top,targetPosition.dimensions)}break}i++}if(this._hscroller.length>0){this._checkScroll(scrollLeft,dragX,left)}return updateEvent},_thDropped:function(){if(this.options.mode==="immediate"){if(this.options.hideHeaderContentsDuringDrag===true){this._oTh.children().show()}return}this._hideIndicators();if(this._tKey&&this._cKey!==this._tKey){this._moveColumn(this._cKey,this._tKey,this._last,this.options.moveType==="dom",false)}delete this._cKey;delete this._tKey;$(".ui-draggable-dragging").hide();this._scroller.on=false},_isColumnMovable:function(col,idx){var i,cs;for(i=0;i<this.options.columnSettings.length;i++){cs=this.options.columnSettings[i];if(cs.columnIndex){if(i===idx){return cs.allowMoving}}if(cs.columnKey){if(col===cs.columnKey){return cs.allowMoving}}}return true},_isColumnGroupable:function(col){var gbColumnSetting=this._groupBy._findColumnSetting(this._getIdOfTh(col));return gbColumnSetting&&gbColumnSetting.allowGrouping},_getIdOfTh:function(th){var mchid=th.attr("data-mch-id");if(mchid){return mchid}return th.attr("id").replace(this.grid.id()+"_","")},_getThById:function(id){return $("th[data-mch-id='"+id+"'],th[id='"+this.grid.id()+"_"+id+"']")},_adjustIndicators:function(delta){var newl=parseInt(this._cmib.css("left"),10)-delta;this._cmib.css("left",newl);this._cmit.css("left",newl)},_showIndicators:function(left,top,dim){this._cmib.css("left",left-8-$.ig.util.getRelativeOffset(this._cmib).left).show();this._cmib.css("top",top-16-$.ig.util.getRelativeOffset(this._cmib).top);this._cmit.css("left",left-8-$.ig.util.getRelativeOffset(this._cmit).left).show();this._cmit.css("top",top+dim.height-$.ig.util.getRelativeOffset(this._cmit).top)},_hideIndicators:function(){this._cmib.hide();this._cmit.hide()},_markForMoving:function(col){if(col.data("draggable")||this._groupBy){if(this._isColumnGroupable(col)){col.bind("drag",this._moveHandler);col.bind("dragstop",this._dropHandler);col.bind("dragstart",this._dragHandler);return}col.attr("groupby-disabled","true")}col.draggable({containment:this.grid.container(),appendTo:this.grid.container(),distance:5,revert:"valid",helper:function(event){var th,clone;th=$(event.target).closest("th");clone=th.clone().css("overflow","hidden").css("z-index",1e4).width(th.width()).height(th.height()).addClass("ui-widget ui-iggrid").wrap($('<div class="ui-iggrid-dragMarkup"></div>').width(th.outerWidth()).height(th.outerHeight())).parent();clone.find("div[data-hiddencolindicator]").remove();return clone},opacity:this.options.dragHelperOpacity,drag:this._moveHandler,stop:this._dropHandler,start:this._dragHandler});col.unbind("mouseover.moving").bind("mouseover.moving",this._headerMouseOverHandler);col.unbind("mouseout.moving").bind("mouseout.moving",this._headerMouseOutHandler)},_updateLayout:function(){var cols,self=this;if(!this._gridReady()){setTimeout(function(){self._updateLayout()},50);return}if(this.grid._oldCols){cols=$.grep(this.grid._oldCols,this.grid._columnVisible)}else{cols=this.grid._visibleColumns()}this._hscroller=this.grid._hscrollbarcontent();this._hscroller=this._hscroller.length>0?this._hscroller:this.grid.scrollContainer();this._cache.columns={};this._cache.siblings={};this._updateLayoutPerLevel(cols);delete this._movingDirty},_updateLayoutPerLevel:function(cols){var i,id,$th,os,sl=this._hscroller.length>0?this._hscroller.scrollLeft():0;for(i=0;i<cols.length;i++){id=cols[i].key||cols[i].identifier;$th=this._getThById(id);os=$th.offset();os.left=os.left+sl;this._cache.columns[id]={};this._cache.columns[id].element=$th;this._cache.columns[id].offset=os;this._cache.columns[id].dimensions={width:$th.outerWidth(),height:$th.outerHeight()};this._cache.siblings[id]=cols}for(i=0;i<cols.length;i++){if(cols[i].group&&cols[i].hidden!==true){this._updateLayoutPerLevel($.grep(cols[i].group,this.grid._columnVisible))}}},_openMovingDialog:function(){this._movingDialog.igGridModalDialog("openModalDialog")},_closeMovingDialog:function(){this._movingDialog.igGridModalDialog("closeModalDialog")},_triggerColumnMovedAsync:function(args){var self=this;if(!this._gridReady()){setTimeout(function(){self._triggerColumnMovedAsync(args)},50);return}this._trigger(this.events.columnMoved,null,args)},_gridReady:function(){return!(this.grid._loadingIndicator&&this.grid._loadingIndicator._indicator.is(":visible"))},_bindUpDownDialogButtons:function(list){list.find("span[class='"+this.css.movingDialogListItemArrowDown+"']").unbind("mousedown",this._dialogDownHandler).bind("mousedown",this._dialogDownHandler);list.find("span[class='"+this.css.movingDialogListItemArrowUp+"']").unbind("mousedown",this._dialogUpHandler).bind("mousedown",this._dialogUpHandler)},_checkScroll:function(scrollLeft,dragX,left){var sbw=this.grid._hasVerticalScrollbar===true?this.grid._scrollbarWidth():0;if(scrollLeft>0&&left===true&&dragX-scrollLeft<this.options.movingScrollTolerance){this._updateScroller(true,dragX-scrollLeft)}else if(scrollLeft<this._hscroller[0].scrollWidth+sbw-this._hscroller.outerWidth()&&left===false&&dragX-scrollLeft>this._hscroller.outerWidth()-this.options.movingScrollTolerance){this._updateScroller(false,this._hscroller.outerWidth()-dragX+scrollLeft)}else{this._stopScroller()}},_startScroller:function(left,delta){this._scroller.on=true;this._scroller.delay=delta*this.options.scrollSpeedMultiplier;this._scroller.direction=left===true?"left":"right";this._autoScroll()},_updateScroller:function(left,delta){if(this._scroller.on===false){this._startScroller(left,delta);return}this._scroller.delay=delta},_stopScroller:function(){this._scroller.on=false},_scrollGrid:function(){var sl=this._hscroller.scrollLeft(),delta,res,sbw;
delta=this._scroller.direction==="left"?this.options.scrollDelta*-1:this.options.scrollDelta;res=sl+delta;sbw=this.grid._hasVerticalScrollbar===true?this.grid._scrollbarWidth():0;this._hscroller.scrollLeft(res);if(res<=0&&delta<0||res>=this._hscroller[0].scrollWidth+sbw-this._hscroller.outerWidth()&&delta>0){this._stopScroller()}if(this._hscroller[0].id.indexOf("_hscroller")>0){this.grid._synchronizeHScroll()}if(this.options.mode==="deferred"){this._adjustIndicators(delta)}if(this._scroller.on===true){setTimeout(this._autoScroll,this._scroller.delay)}},_cancelEvent:function(e){e.stopPropagation();e.preventDefault()},_columnMap:function(){return $.map(this.grid.options.columns,function(col,index){return{columnKey:col.key,enabled:true}})},_removeMoving:function(){var ths=this.grid.headersTable().find(">thead th"),i,th,mdl;this.grid.container().find("[id~='"+this.grid.id()+"'][id~='moving']").remove();if(this.options.addMovingDropdown===true){mdl=this._movingDialog;if(mdl&&mdl instanceof jQuery){mdl.igGridModalDialog("destroy");mdl.remove()}$("div[data-moving-inddropdown='"+this.grid.id()+"']").remove()}for(i=0;i<ths.length;++i){th=$(ths[i]);th.find(">div").find("span").unbind("mousedown",this._dropDownButtonHandler);th.find(">div").remove();th.unbind("mouseover.moving",this._headerMouseOverHandler);th.unbind("mouseout.moving",this._headerMouseOutHandler);if(!this._grpByEnabled){if(th.data&&th.data("draggable")){th.draggable("destroy")}}else{th.unbind("draggabledrag",this._moveHandler);th.unbind("draggablestop",this._dropHandler);th.unbind("draggablestart",this._dragHandler)}}},_unregisterEvents:function(){this.grid.element.unbind("iggridheadercellrendered",this._headerCellRenderedHandler);this.grid.element.unbind("iggridheaderrendering",this._headerRenderingHandler);this.grid.element.unbind("iggridheaderrendered",this._headerRenderedHandler);this.grid.element.unbind("iggridrendered",this._gridFullyRenderedHandler);this.grid.container().find("#"+this.grid.id()+(this.grid.options.fixedHeaders===true?"_headers":"")+" th").unbind("moving");this.grid.element.unbind("iggridresizingcolumnresized",this._columnStateChanged);this.grid.element.unbind("iggridcolumnscollectionmodified",this._columnStateChanged);this.grid.element.unbind("iggridpagingpagingdropdownrendered",this._columnStateChanged);this.grid.element.unbind("iggrid_columnsmoved",this._columnStateChanged)},_registerEvents:function(){this.grid.element.bind("iggridheadercellrendered",this._headerCellRenderedHandler);this.grid.element.bind("iggridheaderrendering",this._headerRenderingHandler);this.grid.element.bind("iggridheaderrendered",this._headerRenderedHandler);this.grid.element.bind("iggridrendered",this._gridFullyRenderedHandler);this.grid.element.bind("iggridresizingcolumnresized",this._columnStateChanged);this.grid.element.bind("iggridcolumnscollectionmodified",this._columnStateChanged);this.grid.element.bind("iggridpagingpagingdropdownrendered",this._columnStateChanged);this.grid.element.bind("iggrid_columnsmoved",this._columnStateChanged)},_createHandlers:function(){this._headerCellRenderedHandler=$.proxy(this._headerCellRendered,this);this._headerRenderingHandler=$.proxy(this._headerRendering,this);this._headerRenderedHandler=$.proxy(this._headerRendered,this);this._gridFullyRenderedHandler=$.proxy(this._gridFullyRendered,this);this._dragHandler=$.proxy(this._headerPicked,this);this._moveHandler=$.proxy(this._headerDragged,this);this._dropHandler=$.proxy(this._headerDropped,this);this._headerMouseOverHandler=$.proxy(this._headerMouseOver,this);this._headerMouseOutHandler=$.proxy(this._headerMouseOut,this);this._dropDownButtonHandler=$.proxy(this._dropDownMouseDown,this);this._dropDownKeyHandler=$.proxy(this._dropDownKeyDown,this);this._openMovingDialogHandler=$.proxy(this._openMovingDialog,this);this._dropDownButtonMouseOverHandler=$.proxy(this._dropDownButtonMouseOver,this);this._dropDownButtonMouseOutHandler=$.proxy(this._dropDownButtonMouseOut,this);this._dialogOpeningHandler=$.proxy(this._dialogOpening,this);this._dialogDraggedHandler=$.proxy(this._dialogDragged,this);this._dialogClosingHandler=$.proxy(this._dialogClosing,this);this._dialogClosedHandler=$.proxy(this._dialogClosed,this);this._dialogCloseButtonHandler=$.proxy(this._closeMovingDialog,this);this._dialogUpHandler=$.proxy(this._dialogUpPressed,this);this._dialogDownHandler=$.proxy(this._dialogDownPressed,this);this._dialogRearrangingHandler=$.proxy(this._dialogRearranging,this);this._dialogRearrangedHandler=$.proxy(this._dialogRearranged,this);this._columnStateChanged=$.proxy(this._updateLayout,this);this._cancelEventHandler=$.proxy(this._cancelEvent,this);this._autoScroll=$.proxy(this._scrollGrid,this)},_injectGrid:function(gridInstance,isRebind){this.grid=gridInstance;if(isRebind===true){return}if(this.grid.element.igGridFeatureChooser!==undefined){this.grid.element.igGridFeatureChooser()}else{throw new Error($.ig.ColumnMoving.locale.featureChooserNotReferenced)}this._createHandlers();this._unregisterEvents();this._registerEvents()}});$.extend($.ui.igGridColumnMoving,{version:"14.1.20141.1020"})})(jQuery);(function($){$(document).ready(function(){var wm=$("#__ig_wm__").length>0?$("#__ig_wm__"):$('<div id="__ig_wm__"></div>').appendTo(document.body);wm.css({position:"fixed",bottom:0,right:0,zIndex:1e3}).addClass("ui-igtrialwatermark")})})(jQuery);