//SystemMsg
Ext.namespace('Das.SystemMsg');Das.SystemMsg.conn=new Ext.data.Connection;Das.SystemMsg.task={run:function(){if(Ext.get('system-msg').isVisible()){(function(){Ext.get('system-msg').slideOut('t',{remove:false,useDisplay:true,scope:Das.SystemMsg,callback:Das.SystemMsg.clear});}).defer(5000);}},interval:10000};Das.SystemMsg.prompt=function(msg){return Ext.Msg.show({title:msg.title,msg:msg.msg,icon:Ext.MessageBox.INFO,buttons:Ext.Msg.OK});};Das.SystemMsg.inline=function(msg){this.el.createChild({tag:'div',html:'<h2 style="width: 300px;">'+msg.title+'</h2><p>'+msg.msg+'</p>'});if(!this.el.isVisible()){this.el.slideIn('t');}};Das.SystemMsg.clear=function(){this.el.update('');};Das.SystemMsg.notify=function(msg){if(!Das.SystemMsg.windowGroup){Das.SystemMsg.windowGroup=Ext.ux.window.MessageWindowGroup({groupId:3,zseed:9000});}win=new Ext.ux.window.MessageWindow({id:'notify-win-'+msg.id,title:msg.title,autoDestroy:true,autoHide:false,bodyStyle:'text-align:left;padding:2px;overflow:auto;',help:false,plain:true,iconCls:'msg-window-notify',hideFx:{delay:5000,mode:'standard',useProxy:true},html:msg.msg,manager:Das.SystemMsg.windowGroup,tools:[{id:'close',handler:function(t,a,p){p.hide();}}],origin:{el:Ext.getDoc(),increment:true,pos:"br-br",offX:-30,offY:-5,spaY:5},showFx:{delay:0,duration:0.5,mode:'standard',useProxy:false},autoHeight:true,width:250}).show(Ext.getDoc());};Ext.EventManager.on(window,'load',function(){Ext.TaskMgr.start(Das.SystemMsg.task);Das.SystemMsg.el=Ext.get('system-msg');msg=Das.SystemMsg.conn.request({url:syspath+'func.system-msg.php',method:'POST',params:{p:page},scope:Das.SystemMsg,callback:function(options,success,response){var r=Ext.util.JSON.decode(response.responseText);if(typeof(r.results)=='object'){try{for(i=0;i<r.results.length;i++){if(r.results[i].type=='pop'){this.prompt(r.results[i]);}if(r.results[i].type=='inline'){this.el.createChild({tag:'div',html:'<h2 style="width: 300px;">'+r.results[i].title+'</h2><p>'+r.results[i].msg+'</p>'});this.el.show();}if(r.results[i].type=='notify'){this.notify(r.results[i]);}}}catch(e){}}else{return;}}});});
//CustomWindow
Das.OpenWindow=function(el,title,page,width,height,loadScripts,autoShow,closeAction){return new Das.CustomWindow(el,title,page,width,height,loadScripts,autoShow,closeAction);};Das.CustomWindow=function(el,title,page,width,height,loadScripts,autoShow,closeAction){this.title=title;if(page){this.page=page;}this.width=width;this.height=height;this.scripts=loadScripts;Das.CustomWindow.superclass.constructor.call(this,{layout:'fit',ctCls:'custom-window',closeAction:(!closeAction)?'close':closeAction,autoScroll:true,modal:true,bodyStyle:'background-color:#FFFFFF',renderTo:Ext.getBody()});if(this.page){this.load({url:this.page,scripts:loadScripts});}if(autoShow){this.show();}};Ext.extend(Das.CustomWindow,Ext.Window,{});
//LoginPanel
Ext.namespace("Das.LoginPanel");Das.LoginPanel=function(){el=Ext.get('login-panel');this.logins=0;this.popwindow=new Das.LoginPanel.Window();this.windowMgr=Ext.WindowMgr;Das.LoginPanel.superclass.constructor.call(this,{id:'login-panel-view',buttonAlign:'right',width:300,title:'Login to DAS',frame:true,renderTo:el,defaults:{width:150},defaultType:'textfield',hidden:true,floating:true,iconCls:'login-panel-icon',items:[{xtype:'box',autoEl:'div',id:'login-msg',width:'100%',style:'color: #FF0000;'},{xtype:'box',autoEl:'div',id:'capsOn-msg',width:'100%',style:'color: #FF0000;',html:"Your caps lock is on.",hidden:true},{fieldLabel:'Username',id:'user-field',autoCreate:{tag:"input",type:"text",size:"20",autocomplete:"on"},validateOnBlur:false,name:'user',allowBlank:false},{fieldLabel:'Password',name:'pass',validateOnBlur:false,inputType:'password',allowBlank:false},{xtype:'checkbox',boxLabel:'Remember Me',labelSeparator:'',align:'right',name:'remember-login'},{xtype:'box',autoEl:{tag:'div',style:'margin-top: 15px;height: 15px;text-align: left;',html:'<a title="Start keeping track of tree insects and diseases now by creating a new account." href="new-user" id="new-user">New User</a> | <a title="Forgot your password? Send your login information to your registered email" href="email-pass" id="email-pass">Email Password</a>'},id:'login-extras',width:'100%'}],keys:[{key:Ext.EventObject.ENTER,fn:function(key,e){if(this.getForm().isValid()){Ext.getCmp('login-btn').disable().setText('Logging In...');this.submitForm();}},scope:this}],listeners:{"show":{fn:function(panel){Ext.getCmp('user-field').focus();Ext.getCmp('login-btn').enable().setText('Login');var newuser=Ext.get('new-user');var emailpass=Ext.get('email-pass');newuser.on({"click":{fn:function(e,el){e.preventDefault();this.hide();this.popwindow.setTitle("IPM Decision Aid Registration");if(this.popwindow.items.get(0).isVisible()){this.popwindow.items.get(0).hide();}if(!this.popwindow.items.get(1).isVisible()){this.popwindow.items.get(1).show();}this.popwindow.setWidth(550);this.popwindow.center();this.popwindow.doLayout(true);this.popwindow.syncSize();this.windowMgr.bringToFront(this.popwindow);this.popwindow.show();},scope:this}});emailpass.on({"click":{fn:function(e,el){e.preventDefault();this.hide();this.popwindow.setTitle("Email Password");if(this.popwindow.items.get(1).isVisible()){this.popwindow.items.get(1).hide();}if(!this.popwindow.items.get(0).isVisible()){this.popwindow.items.get(0).show();}this.popwindow.setWidth(300);this.popwindow.center();this.popwindow.doLayout(true);this.popwindow.syncSize();this.windowMgr.bringToFront(this.popwindow);this.popwindow.show();},scope:this}});},scope:this},"hide":{fn:function(panel){panel.getForm().clearInvalid();panel.getForm().reset();},scope:this}},tools:[{id:'close',handler:function(event,toolEl,panel){panel.hide();}}],buttons:[{text:'Login',id:'login-btn',scope:this,handler:function(btn){btn.disable().setText('Logging In...');if(this.getForm().isValid()){this.submitForm();}else{btn.enable().setText('Login');}}}]});};Ext.extend(Das.LoginPanel,Ext.form.FormPanel,{submitForm:function(){this.getForm().submit({url:pathto+'func.login.php',method:'POST',scope:this,success:function(f,a){var user=Ext.util.JSON.decode(a.response.responseText);if(user.remember==true){var expire=365;}else{var expire=0;}Das.Cookie.set('WSUTFRECIPM',user.uid,expire,'',host,0);Das.Cookie.set('DASBETA',user.beta,expire,'',host,0);Das.Cookie.set('DASADMIN',user.admin,expire,'',host,0);if(Das.Cookie.get('WSUTFRECIPM')){window.location=user.landingPage;}else{alert('Can\'t login.\nThis website requires the use of cookies. Please enable your cookies.');}},failure:function(f,a){this.getForm().reset();Ext.getCmp('login-btn').enable().setText('Login');r=Ext.util.JSON.decode(a.response.responseText);Ext.get('login-msg').update(r.msg);if(this.logins==2){Ext.Msg.alert('Login Failure','3 attempted logins!');}else{this.logins=this.logins+1;}}});}});Das.LoginPanel.Window=function(config){Ext.apply(this,config);Das.LoginPanel.Window.superclass.constructor.call(this,{id:'login-extras-window',layout:'fit',width:300,autoHeight:true,plain:true,bodyBorder:false,modal:true,items:[new Das.LoginPanel.EmailPass(),new Das.LoginPanel.NewUser()],closeAction:'hide',renderTo:Ext.getBody()});};Ext.extend(Das.LoginPanel.Window,Ext.Window,{});Das.LoginPanel.EmailPass=function(){Das.LoginPanel.EmailPass.superclass.constructor.call(this,{id:'email-password',labelWidth:75,autoHeight:true,buttonAlign:'right',bodyBorder:false,frame:true,defaultType:'textfield',hidden:true,items:[{fieldLabel:'Your Email',id:'email',allowBlank:false}],listeners:{'beforeshow':{fn:function(){this.getForm().reset();this.getForm().clearInvalid();return true;},scope:this}},buttons:[{text:'Send',handler:function(btn){f=this.items.itemAt(0);if(f.isValid()){btn.disable();btn.setText("Sending...");v=f.getRawValue();Ext.Ajax.request({url:pathto+'func.login.php',method:'POST',params:{d:'emailpass,'+v},callback:function(action,success,response){r=Ext.util.JSON.decode(response.responseText);if(r.success==false){btn.setText("Send");btn.enable();Ext.Msg.alert("Email Password Error",r.msg);}else{this.ownerCt.hide();btn.setText("Send");btn.enable();Ext.Msg.alert("Email Sent!","<p>Please check email for your account information.</p> <br /><p><b>Note:</b> If you have <b>not</b> received an email from our system.</p><br /><p>If you never received an email, please contact us for further assistance.</p>");}},scope:this});}},scope:this}]});};Ext.extend(Das.LoginPanel.EmailPass,Ext.form.FormPanel,{});Das.LoginPanel.NewUser=function(){this.emailIsValid=false;this.usernameIsValid=false;this.formIsValid=false;this.disclaimerOpened=false;this.disclaimer=new Das.CustomWindow(this,'WSU-DAS Website Disclaimer','pages/website-disclaimer.html',750,550,false,false,'hide');Das.LoginPanel.NewUser.superclass.constructor.call(this,{id:'new-user-reg',labelWidth:125,labelAlign:'top',autoHeight:true,buttonAlign:'right',bodyBorder:false,bodyStyle:'padding:10px',hidden:true,items:[{xtype:'box',autoEl:{tag:'div',style:'font-weight: bold;padding: 0px 5px 5px 0px',html:'Please complete all information (business name is optional).'}},{layout:'column',border:false,items:[{columnWidth:.5,layout:'form',border:false,defaultType:'textfield',items:[{fieldLabel:"Your Name",id:'full-name',name:'name',allowBlank:false,validationEvent:false,anchor:'90%',tabIndex:1},{fieldLabel:"Email",id:'email-id',name:'email',allowBlank:false,anchor:'90%',vtype:'email',tabIndex:3,msgTarget:'qtip',validationEvent:false,listeners:{'blur':{fn:function(field){this.checkEmail(field);},scope:this}}}]},{columnWidth:.5,layout:'form',border:false,defaultType:'textfield',items:[{fieldLabel:"Business or Orchard Name",allowBlank:true,name:'bname',anchor:'90%',tabIndex:2},{xtype:'numberfield',fieldLabel:"Zipcode",name:'zipcode',validationEvent:false,allowBlank:false,anchor:'90%',tabIndex:4}]}]},{xtype:'box',autoEl:{tag:'div',style:'font-weight: bold;padding: 0px 5px 5px 0px',html:'Please create a user name and a password for logging into WSU-DAS.'}},{layout:'column',border:false,items:[{columnWidth:.5,layout:'form',border:false,defaultType:'textfield',items:[{fieldLabel:"Username",id:'username-id',name:'username',allowBlank:false,anchor:'90%',tabIndex:5,msgTarget:'qtip',validationEvent:false,listeners:{'blur':{fn:function(field){this.checkUser(field);},scope:this}}},{fieldLabel:"Re-enter Password",id:'password2-f',name:'password2',allowBlank:false,anchor:'90%',inputType:'password',tabIndex:7,validationEvent:false,enableKeyEvents:true,listeners:{'blur':{fn:function(field,e){var p1=Ext.getCmp('password-f');if(p1.getRawValue()!=field.getRawValue()){Ext.get('password-error').update("Passwords do not match. Please try again");}else{Ext.get('password-error').update("");}},scope:this}}}]},{columnWidth:.5,layout:'form',border:false,validateOnBlur:false,defaultType:'textfield',items:[{fieldLabel:"Password",id:'password-f',name:'password',inputType:'password',allowBlank:false,validationEvent:false,anchor:'90%',tabIndex:6},{xtype:'box',autoEl:{tag:'div',id:'password-error',style:'color: #FF0000;font-weight:bold;'}}]}]},{xtype:'box',autoEl:{tag:'div',html:'<a id="disclaimer-link" href="#" style="font-size:12px; font-weight: bold;">Read Disclaimer</a>'}},{xtype:'checkbox',name:'agree',checked:false,id:'agree-check',hideLabel:true,invalidText:'You must agree to our disclaimer to continue.',boxLabel:"I have read the above disclaimer and accept its terms."}],listeners:{'beforeshow':{fn:function(panel){this.getForm().reset();this.getForm().clearInvalid();if(this.disclaimerOpened=true){this.disclaimerOpened=false;Ext.getCmp('register-btn').disable();}Ext.fly('password-error').update('');var d=Ext.get("disclaimer-link");d.on("click",function(e,el){e.preventDefault();this.disclaimerOpened=true;this.disclaimer.show();Ext.getCmp('register-btn').enable();},this);},scope:this}},buttons:[{id:'register-btn',disabled:true,text:'Register',handler:function(btn){c=Ext.getCmp('agree-check');p1=Ext.getCmp('password-f');p2=Ext.getCmp('password2-f');if(p1.getRawValue()!=p2.getRawValue()){Ext.get('password-error').update("Passwords do not match. Please try again");}if(c.checked==false){Ext.Msg.alert("Disclaimer Agreement","You must check the agreement checkbox to continue.");}if(this.emailIsValid&&this.usernameIsValid){this.formIsValid=this.getForm().isValid();}if((this.formIsValid&&this.emailIsValid&&this.usernameIsValid)&&c.checked&&(p1.getRawValue()===p2.getRawValue())){Ext.Ajax.request({url:pathto+'func.login.php',method:'POST',params:{d:'newuser'},form:this.getForm().id,callback:function(actions,success,response){r=Ext.util.JSON.decode(response.responseText);if(r.success==false){Ext.Msg.alert("Server Error",r.msg);}else{this.ownerCt.hide();Ext.Msg.alert("Registration Confirm","<p>Please check your email for your registration confirmation. You will need to confirm your email before using the DAS system.</p> <br /><p><b>Note:</b> If you have <b>not</b> received an email from our system, please check your junk mailbox. If the email is in your junk mail, move the message to your inbox, then follow the instructions.</p><br /><p>If you never received an email, please contact us for further assistance.</p>");}},scope:this});}},scope:this},{text:'Cancel',handler:function(btn){this.ownerCt.hide();},scope:this}]});};Ext.extend(Das.LoginPanel.NewUser,Ext.form.FormPanel,{checkEmail:function(field){if(field.getRawValue()==""){this.emailIsValid=true;field.markInvalid("Your email is required to register a new account.");}else{Ext.Ajax.request({url:pathto+'func.login.php',method:'POST',params:{d:'checkemail,'+field.getRawValue()},callback:function(options,success,response){var r=Ext.util.JSON.decode(response.responseText);if(r.success==false){this.emailIsValid=false;field.markInvalid(r.msg);}else{this.emailIsValid=true;field.clearInvalid();}},scope:this});}},checkUser:function(field){Ext.Ajax.request({url:pathto+'func.login.php',method:'POST',params:{d:'checkusername,'+field.getRawValue()},callback:function(options,success,response){var r=Ext.util.JSON.decode(response.responseText);if(r.success==false){this.usernameIsValid=false;field.markInvalid(r.msg);}else{this.usernameIsValid=true;field.clearInvalid();}},scope:this});}});Ext.onReady(function(){panel=new Das.LoginPanel();ll=Ext.get("login-link");ll.on({'click':{fn:function(e,el){e.preventDefault();panel.getEl().alignTo(this.id,"tr-br");panel.show();},scope:ll}});});
//UserInvite
Ext.namespace("Das","Das.util");Das.util.Invite=function(){return{moveInvited:function(el,to,glue,offset,key){Ext.get("invite-body").update(to.getAttributeNS('das',"invite"));if(key==this.startAt){el.alignTo(to.id,this.glue,this.offset);}else{el.alignTo(to.id,glue,offset,{easing:'easeOut'});}},show:function(items,inviteEl,startAt,glue,offset){this.items=items;this.inviteEl=Ext.get(inviteEl);this.startAt=startAt;this.glue=glue;this.offset=offset;this.i=this.startAt;this.start();},start:function(){inviteTask={run:function(){if(this.i<this.items.getCount()){this.moveInvited(this.inviteEl,Ext.get(this.items.elements[this.i].id),this.glue,this.offset,this.i);this.i++;}else{moveIt.stop(inviteTask);this.inviteEl.fadeOut({useDisplay:true,remove:true});}},interval:7000,scope:this};var moveIt=new Ext.util.TaskRunner();moveIt.start(inviteTask);}};}();
//Simple Contact
Ext.namespace('Das.SimpleContactPanel');Das.SimpleContactPanel=function(config){Ext.apply(this,config);if(!this.msgtype||this.msgtype==""){this.msgtype='general';}if(!this.msgorigin||this.msgorigin==''){this.msgorigin='DAS Website';}if(this.isWin==true){this.header=false;}Das.SimpleContactPanel.superclass.constructor.call(this,{id:'contact-form-'+Ext.id(),labelWidth:70,buttonAlign:'right',bodyStyle:'padding:5px 5px 0',title:'<font class="translate">Submit Question</font>',defaults:{width:'90%'},defaultType:'textfield',url:pathto+'func.sendemail.php',collapsible:false,frame:true,items:[{fieldLabel:'<font class="translate">Name</font>',name:'name',allowBlank:false},{fieldLabel:'<font class="translate">Email</font>',name:'email',vtype:'email',allowBlank:false},{xtype:'textarea',fieldLabel:'<font class="translate">Message</font>',name:'message',allowBlank:false},{xtype:'hidden',name:'subject',value:this.subjectValue},{xtype:'hidden',name:'msgtype',value:this.msgtype},{xtype:'hidden',name:'msgorigin',value:this.msgorigin}],buttons:[{text:'<font class="translate">Send</font>',handler:this.submitPanel,scope:this},{text:'<font class="translate">Clear</font>',handler:function(){this.getForm().clearInvalid();this.getForm().reset();},scope:this}],renderTo:this.targetEl});};Ext.extend(Das.SimpleContactPanel,Ext.form.FormPanel,{submitPanel:function(){this.getForm().submit({method:'POST',success:function(f,a){if(this.isWin){this.ownerCt.hide();}Ext.Msg.alert("<font class='translate'>Email Sent!</font>","<font class='translate'>Thank you for taking the time to send us a message. We'll get back to you as soon as possible</font>",this.handleSuccess,this);},failure:function(f,a){},scope:this});},handleSuccess:function(btn){this.getForm().clearInvalid();this.getForm().reset();}});Ext.namespace('SimpleContactWindow');Das.SimpleContactWindow=function(config){config.isWin=true;this.cp=new Das.SimpleContactPanel(config);Das.SimpleContactWindow.superclass.constructor.call(this,{id:'contact-window',width:425,title:'Contact DAS',height:320,bodyBorder:false,layout:'fit',items:this.cp,resizable:false,draggable:false,autoDestroy:true,renderTo:Ext.getBody(),listeners:{'beforeshow':{fn:function(panel){if(Das.Translator.isTranslated()){Das.Translator.translatePage();}},scope:this}}});};Ext.extend(Das.SimpleContactWindow,Ext.Window,{});