
      function windowLDAPEditor(initOptions){
        var _self = this;
        this._settings = {};
        Ext.apply(this._settings, initOptions);
        var loadMode = this._settings.loadMode;
        var schoolID = this._settings.schoolID;
        var treenode = this._settings.treenode;

        if (!canEdit)
          return false;       
        
        function saveSchoolForm(){
          //alert(Ext.getCmp('winSchoolSettingsEditor').getForm().getValues().toSource());
          //return false;
          var thisForm = this.formPanel.getForm();
          thisForm.submit({
            clientValidation: true,            
            url:'/ajax/siteconfig/login/submitLoginConfig.cfm',
            waitMsg:'Saving settings...',
            params: {schoolID: schoolID},
            errorReader : new Ext.data.JsonReader({
                root:'errors',
                successProperty:'success'
            }, ['id', 'msg']),
            success: function(form, action) {
              //if(action.result.data_id)

              //this._settings.sc.triggerReload();
              this.win.close();              
              window.location.reload(true);
              return true;
            },
            failure: function(form, action) {
              switch (action.failureType) {
                case Ext.form.Action.CLIENT_INVALID:
                  Ext.Msg.alert('Failure', 'Please verify all form fields are correct.');
                  break;
                case Ext.form.Action.CONNECT_FAILURE:
                  Ext.Msg.alert('Failure', 'Ajax communication failed');
                  break;
                case Ext.form.Action.SERVER_INVALID:
                default:
                  Ext.Msg.alert('Failure', action.result.msg);
              }
              Ext.Msg.hide();
              return false;
            }
          });
        }
        
        
        var xmlCols = [];
        xmlCols.push({name: 'current_school_id', mapping: 'id'});
        xmlCols.push({name: 'login_mode', mapping: 'login/@mode'});
        xmlCols.push({name: 'login_google', mapping: 'login/@google'});
        xmlCols.push({name: 'ldap_default_domain', mapping: 'ldap/general/DefaultDomain'});
        xmlCols.push({name: 'ldap_change_domain', mapping: 'ldap/general/UserChangeDomain'});
        xmlCols.push({name: 'ldap_server_host', mapping: 'ldap/server/Host'});
        xmlCols.push({name: 'ldap_server_port', mapping: 'ldap/server/Port'});
        xmlCols.push({name: 'ldap_admin_user', mapping: 'ldap/admin/User'});
        xmlCols.push({name: 'ldap_admin_pass', mapping: 'ldap/admin/Pass'});
        xmlCols.push({name: 'ldap_server_filter', mapping: 'ldap/server/Filter'});
    
        var navInfo = 'Changes will be applied when you click \'Save\' below.';

        var ldap_Tab = new Ext.Panel({ 
                      title: 'LDAP',
                      padding: 5,
                      items: [{
                                xtype:'fieldset',
                                title: 'General Settings',
                                autoHeight:true,
                                defaultType: 'textfield',
                                items :[{
                                            xtype: 'displayfield',
                                            hideLabel: true,
                                            style: {
                                              marginBottom: '10px'
                                            },
                                            html: 'LDAP usually requires it\'s users to specify the domain to login to, here you can specify the default.'
                                        },{
                                            fieldLabel: 'FQDN',
                                            name: 'ldap_default_domain',
                                            width: 150
                                        },{
                                            xtype: 'checkbox',
                                            name: 'ldap_change_domain',
                                            boxLabel: 'Allow user to change Domain from Login Box'
                                        }]
                              },{
                                xtype:'fieldset',
                                title: 'Active Directory Server',
                                autoHeight:true,
                                defaultType: 'textfield',
                                items :[
                                        {
                                            xtype: 'displayfield',
                                            hideLabel: true,
                                            style: {
                                              marginBottom: '10px'
                                            },
                                            html: 'Please specify how to connect to your Active Directory Server. If you would like to securely connect your server or bypass corporate firewalls ask us about <a href="https://secure.logmein.com/products/hamachi2/">Hamachi VPN</a>.'
                                        },{
                                            fieldLabel: 'Hostname or IP',
                                            width: 200,
                                            name: 'ldap_server_host',
                                            allowBlank:false
                                        },{
                                            fieldLabel: 'Port',
                                            width: 75,
                                            name: 'ldap_server_port'
                                        },{
                                            fieldLabel: 'Filter',
                                            width: 200,
                                            name: 'ldap_server_filter',
                                            allowBlank:false
                                        }/*,{
                                            fieldLabel: 'FQDN',
                                            hidden: true,
                                            anchor: '0'
                                        }*/
                                      ]
                              },{
                                xtype:'fieldset',
                                title: 'Administrative Roles',
                                autoHeight:true,
                                defaultType: 'textfield',
                                items :[
                                        {
                                            xtype: 'displayfield',
                                            hideLabel: true,
                                            style: {
                                              marginBottom: '10px'
                                            },
                                            html: '<strong>This section is required if you want to do the following:</strong> <br /> &bull; Import Users from Active Directory,<br /> &bull; Link an Active Directory account to a CyberSchool account, or<br /> &bull; Synchronize data from LDAP into CyberSchool'
                                        },/*{
                                            fieldLabel: 'Admin DN',
                                            hidden: true,
                                            anchor: '0'
                                        },*/{
                                            fieldLabel: 'Admin User',
                                            name: 'ldap_admin_user',
                                            width: 150,
                                            value: 'Administrator'
                                        },{
                                            fieldLabel: 'Admin Pass',
                                           	inputType: 'password',
                                            name: 'ldap_admin_pass',
                                            width: 150,
                                            emptyText: 'Click to set password'
                                        }
                                      ]
                              }]
                    });
                    
        var general_Tab = new Ext.Panel({ 
                      title: 'General',
                      padding: 5,
                      items: [{
                                xtype:'fieldset',
                                title: 'Login Mode',
                                autoHeight:true,
                                defaultType: 'textfield',
                                defaults: {
                                  hideLabel: true
                                },
                                items :[
                                        {
                                            xtype: 'displayfield',
                                            style: {
                                              marginBottom: '10px'
                                            },
                                            html: 'Here you define how users are allowed to login to the CyberSchool platform.'
                                        },{
                                            xtype: 'radio',
                                            checked: true,
                                            boxLabel: 'Users will login with CyberSchool Credentials ONLY',
                                            name: 'login_mode',
                                            inputValue: 'cyberschool'
                                        },{
                                            xtype: 'radio',
                                            boxLabel: 'Users will login with LDAP Credentials ONLY',
                                            name: 'login_mode',
                                            inputValue: 'ldap'
                                        },{
                                            xtype: 'radio',
                                            boxLabel: 'Users may choose CyberSchool or LDAP Credentials (Hybrid)',
                                            name: 'login_mode',
                                            inputValue: 'hybrid'
                                        },{
                                            xtype: 'checkbox',
                                            boxLabel: 'Enable Google Login',
                                            name: 'login_google'
                                         },{
                                            xtype: 'displayfield',
                                            style: {
                                              marginTop: '10px'
                                            },
                                            html: '<strong>Notice:</strong> LDAP authentication will be performed on anyone who has a linked LDAP account regardless if they login with CyberSchool or Google Login.'
                                        }
                                      ]
                              }]
                    });

        var tabItems = [general_Tab,ldap_Tab];
        
        this.formPanel = new Ext.FormPanel({
                    waitMsgTarget: !Ext.isIE,
                    border: false,
                    reader : new Ext.data.XmlReader({
                          record : 'result',
                          success : '@success'
                      }, xmlCols),
                    autoScroll: true,
                    listeners: {
                      render: function(fp){
                        theTemplates.load();
                      }
                    },
                    cls: '',
                    baseCls: '',
                    layout: 'fit',
                    items: new Ext.TabPanel({
                      plain: true,
                      activeItem: 0,
                      deferredRender:false,
                      enableTabScroll:true,
                      defaults: {autoScroll:true},
                      items: tabItems
                    })
                  });
          
        this.win = new Ext.Window({
              width:550,
              height:500,
              resizable: false,
              title: 'System Login',
            	constrainHeader: true,
              layout:'fit',
              iconCls: 'cpi_ldapLogin',
              closeAction:'close',              
              modal:true,
              closable:true,
              border:true,
              padding: 5,
              items: this.formPanel,
              buttons: [{
                text: 'Save',
                handler: saveSchoolForm.createDelegate(_self, [], true)
              },{ text: 'Cancel', handler: function(){ _self.win.close(); } }],
              listeners: {
                afterRender: function(win){
                  _self.formPanel.getForm().load({url:'/ajax/siteconfig/login/getLoginConfig.cfm?s='+schoolID, waitMsg:'Loading Setting...'});
                }
              }
          });
        this.win.show(this);
      }
      
      
reportingIn('ldapTab');

