//ALTER TABLE `navigation` ADD `nIconPath` VARCHAR( 255 ) NULL DEFAULT NULL 

    var treeMenuGCDAssign = new Ext.menu.Menu({
        items: [{
          id: 'mnu_item-delete',
          text: 'Remove User (Un-Assign)'
        }],
        listeners: {
          itemclick: function(item) {
            var n = item.parentMenu.contextNode;
            switch (item.id) {                    
              case 'mnu_item-delete':
                var params = {ID:n.attributes.uid, gcdID:n.gcdID, pt:n.pt};
                Ext.Ajax.request({
                   url: '/ajax/siteconfig/gcd/deleteGCDUser.cfm',
                   method: 'GET',
                   'params': params,
                   reader : new Ext.data.JsonReader({
                    success : '@success'
                   }),
                   success: function(response, opts) {
                      n.remove();
                   },
                   failure: function(response, opts) {
                   }
                });     
                break;
            }
          }
        }
      });

    windowGCDUserAssign = function(_settings){
        var _self = this;
        this._settings = _settings;
        this.gcdID = _settings.attributes.gcd_id;
        this.gcdType = _settings.attributes.gcd_type;
        this.perType = 'entire_day';
        this.perNum = null;
        
        if (!canEdit)
          return false;
        
        this.tree2 = new Ext.tree.TreePanel({
              id : 'mainGCDUserList_adder',
              useArrows:true,
              autoScroll:true,
              animate:true,
              region: 'center',
              enableDD:true,
              //tbar: [{text: 'Add'},{text: 'Rename'},{text: 'Delete'}],
              containerScroll: true,
              rootVisible: false,
              root: { nodeType: 'async', allowDrop: false},
              dataUrl : '/ajax/login/getUserTree.cfm',
              listeners: {
                checkchange: function(node, checked){
                  if(checked){
                    node.getUI().addClass('complete');
                  }else{
                    node.getUI().removeClass('complete');
                  }
                }
              }
          });
                   
        this.tree = new Ext.tree.TreePanel({                    
              useArrows:true,
              id: 'mainGCDUserEditor',
              autoScroll:true,
              animate:true,
              region: 'center',
              enableDD:true,
              containerScroll: true,
              rootVisible: true,
              root: { nodeType: 'async', text: 'Allowed Users'},
              dataUrl : '/ajax/siteconfig/gcd/getGCDUsersJson.cfm?id='+this.gcdID+'&pt=',
              listeners: {
              
                load: function(node){
                  Ext.Msg.hide();
                },
                contextmenu: function(node, e) {
                  node.select();
                  node.gcdID = _self.gcdID;
                  node.pt = _self.period;
                  var c = treeMenuGCDAssign;
                  c.contextNode = node;
                  c.showAt(e.getXY());
                },              
                beforenodedrop: function(e){

                  if(e.target.getDepth() > 1){
                    e.cancel=true;
                    return false;
                  }
                  if (e.source.tree.id!=e.tree.id){
                    if(e.target.getOwnerTree().getRootNode().findChild('uid', e.dropNode.attributes.uid)){
                      e.cancel=true;
                      return false;                      
                    }else{
                      var newEl = e.dropNode.clone();
                      newEl.getUI().toggleCheck(true);                    
                      e.dropNode = newEl;
                      
                      var params = {ID:e.dropNode.attributes.uid, gcdID:_self.gcdID, pt:_self.period};
                      Ext.Ajax.request({
                         url: '/ajax/siteconfig/gcd/addGCDUser.cfm',
                         method: 'GET',
                         'params': params,
                         reader : new Ext.data.JsonReader({
                          success : '@success'
                         }),
                         success: function(response, opts) {
                         
                         },
                         failure: function(response, opts) {
                            newEl.remove();
                         }
                      });                      
                    }                    
                  }
                }
              }
          });

        this.period='';        
        this.treeLeft = new Ext.Panel({
            border: false,
            region: 'center',
            layout: 'border',
            items:[
                    {
                      region: 'north',
                      margins:'0 0 -1 0',
                      cmargins:'3 3 3 3',
                      height: 50,
                      border: true,
                      layout: 'border',
                      items: [
                                {
                                  region: 'north',
                                  border: false,
                                  bodyStyle: 'padding: 5px; text-align: center;',
                                  html: '<strong>Currently Assigned Users</strong>'
                                }, 
                                new Ext.FormPanel({
                                  region: 'center',
                                  border: false,
                                  labelWidth: 50,
                                  frame:false,
                                  bodyStyle:'padding: 0 5px 5px',
                                  defaults: {anchor: '0'},
                                  items: new Ext.form.ComboBox({
                                            id: 'periodSelector',
                                            store: new Ext.data.Store({
                                              autoLoad: true,
                                              url: '/ajax/siteconfig/gcd/getGCDPeriodsJson.cfm?id='+this.gcdID,
                                              reader : new Ext.data.JsonReader({
                                                  root : 'periods'                           
                                                },[
                                                  {name: 'id', mapping: 'id'},
                                                  {name: 'name', mapping: 'name'}
                                                ]
                                              ),
                                              listeners: {
                                                load: function(s,r,o){
                                                  if (r[0].data.id == "error_no_periods"){
																										var n = _self._settings;
                                                    var winName = 'gcd_edit';
                                                    var switchTabToPeriod = function(){
                                                      Ext.getCmp('editPanel_tabs_'+winName).activate(1);
                                                    }
                                                    Ext.Msg.show({
                                                       title:'Setup Error',
                                                       msg: 'There are no periods defined. The properties for this location will now open so you can specify them.',
                                                       buttons: Ext.Msg.OK,
                                                       fn: function(){
                                                        _self.winNavEdit.close();
                                                        if (n.parentNode) {
                                                          if (n.attributes.data_type=='department'){
                                                                setTimeout(function(){
                                                                  callEditor({navigationContextNode: n, afterFn: switchTabToPeriod, 'winName': winName, editorDataID: n.attributes.gcd_id, editorType: 'Department', editorModal: true});
                                                                }, 100);
                                                          }else if (n.attributes.data_type=='class'){
                                                              setTimeout(function(){
                                                                callEditor({navigationContextNode: n, afterFn: switchTabToPeriod, 'winName': winName, editorDataID: n.attributes.gcd_id, editorType: 'Class', editorModal: true});
                                                              }, 100);
                                                          }
                                                        }
                                                       },
                                                       icon: Ext.MessageBox.ALERT
                                                    });
                                                    return false;
                                                  }
                                                  Ext.Msg.wait('Loading users...', 'Please wait');
                                                  var rID = 0;
                                                  _self.period=r[rID].data.id;
                                                  Ext.getCmp('periodSelector').setValue(r[rID].data.name);
                                                  _self.tree.getLoader().dataUrl = '/ajax/siteconfig/gcd/getGCDUsersJson.cfm?id='+_self.gcdID+'&pt='+r[rID].data.id;
                                                  _self.tree.getRootNode().reload();
                                                }
                                              }
                                            }),
                                            displayField:'name',
                                            typeAhead: true,
                                            mode: 'local',
                                            fieldLabel:'Period',
                                            forceSelection: true,
                                            triggerAction: 'all',
                                            selectOnFocus:true,
                                            listeners: {
                                              select: function(c,r,i){
                                                _self.period=r.data.id;
                                                Ext.Msg.wait('Loading users...', 'Please wait');
                                                _self.tree.getLoader().dataUrl = '/ajax/siteconfig/gcd/getGCDUsersJson.cfm?id='+_self.gcdID+'&pt='+r.data.id;
                                                _self.tree.getRootNode().reload();
                                              }
                                            }
                                          })
                                        })
                              ]

                    },
                    this.tree
                  ]
          });
          
        this.treeRight = new Ext.Panel({
            border: false,
            region: 'east',
            layout: 'border',
            margins:'0 0 0 5',
            cmargins:'3 3 3 3',
            width: 230,
            items: [
              {
                region: 'north', 
                margins:'0 0 -1 0',
                bodyStyle: 'padding: 5px; text-align: center;',
                cmargins:'3 3 3 3', 
                border: true, 
                html: '<strong>Available Users</strong>'
              },{
                region: 'south', 
                margins:'10 10 10 10',
                cmargins:'3 3 3 3',
                baseCls: 'x-plain', 
                border: true, 
                html: '<strong>Drag & Drop above users</strong> to the left to assign them to this area.'
              },this.tree2]
          });
          
        this.treeHolder = new Ext.Panel({
            border: false,          
            layout: 'border',
            id: 'tabGCDUserEditor',
            items: [
              {
                region: 'north', 
                margins:'10 10 10 10',
                cmargins:'3 3 3 3',
                baseCls: 'x-plain',
                border: true,
                html: '&bull; <strong>Right-click</strong> to delete a user.<br /><br /><strong>Changes are saved automatically. Simply close this window when done assigning users.</strong>'
              },
              this.treeLeft,
              this.treeRight,
              {
                region: 'south', 
                margins:'4 4 4 4',
                cmargins:'3 3 3 3',
                baseCls: 'x-plain', 
                border: true, 
                bodyStyle: 'font-size: 9px; color: #666; text-align: center',
                html: 'This module is still under construction. More features will be enabled shortly.'
              }]
          });
        
        this.getTab = function(){
            return Ext.apply(treeHolder, {title: 'Assign Users'});
          };
          
        this.saveTree = function(){
            var tmpSerial = new Ext.tree.JsonTreeSerializer(this.tree, { nodeFilter: function(node) {
              //node.attributes.linkURL = encodeURIComponent(decodeURI(decodeURI(decodeURI(decodeURI(decodeURI(node.attributes.linkURL))))));
              return true;
            }});
            Ext.Msg.wait('Saving your navigation configuration. This may take a few seconds.', 'Please wait...');
            new Ajax.Request('/ajax/siteconfig/gcd/updateGCDUser.cfm?gcd='+this.gcdID+'&pt='+this.perType+'&p='+this.perNum, {
              postBody: 'assignedUsers=' + Base64.encode(tmpSerial.toString()),
              onSuccess: function(transport){
                //Ext.Msg.updateText('Reloading the page...');
                //winNavEdit.close();
                //window.location.reload(true);
              }
            });
          };
          
        this.closeMe = function(){
            _self.winNavEdit.close();
          };
          
        this.winNavEdit = new Ext.Window({
              width:500,
              height:550,
              title: 'Assign Users',
              layout:'fit',
              closeAction:'close',
              modal:true,
              closable:true,
              border:false,
              maximizable:true,
              items: this.treeHolder
          });
          
        this.show = function(){
          this.tree.getRootNode().expand(true);
          this.tree2.getRootNode().expand(true);
          this.winNavEdit.show(this);
          Ext.Msg.wait('Initializing...', 'Please wait');
        };

        return this;        
      }
      
reportingIn('gcdUserAssignDlg');