// Copyright (c) 2008 Synology Inc. All rights reserved.
Ext.namespace("SYNOBLOG_UTILS");Ext.Ajax.on("requestcomplete",function(_1,_2,_3){if(SYNOBLOG_UTILS.checkServerError(_2)){_1.purgeListeners();}});SYNOBLOG_UTILS.SetTextMaxLen=function(_4,_5,_6){var _7=_4.findField(_5);if(_7){_7.getEl().dom.setAttribute("maxLength",_6);}};SYNOBLOG_UTILS.checkServerError=function(_8){if(_8&&_8.getResponseHeader){var _9=_8.getResponseHeader["x-request-error"];if(_9){_9=Ext.util.Format.trim(_9);var _a=blog_str_common_system_error;if(_9=="error_timeout"){_a=blog_str_common_session_timeout;}alert(_a);window.location="/blog/index.php";return true;}}return false;};SYNOBLOG_UTILS.arrayFindIndex=function(_b,_c){var i,_e=-1;for(i in _b){if(_b[i]==_c){_e=i;break;}}return _e;};Ext.form.SRadio=function(_f){if(_f.indent&&_f.indent>0){var _10=13*_f.indent;var _11=String.format("display: inline;width:{0}px;",_10);_f.labelStyle=_11;_f.labelSeparator="";}Ext.form.SRadio.superclass.constructor.apply(this,arguments);};Ext.extend(Ext.form.SRadio,Ext.form.Radio,{setValue:function(v){var _13=this.el.up("form").query("input[name="+this.el.dom.name+"]");if(typeof v=="string"){for(var j=0;j<_13.length;j++){var _15=Ext.getCmp(_13[j].id);if(_13[j].value==v){_13[j].checked=true;}else{_13[j].checked=false;}_15.checked=_13[j].checked;_15.fireEvent("check",_15,_15.checked);}}else{if(typeof v=="boolean"){if(v===true){this.setValue(this.el.dom.value);}}}},onClick:function(){if(this.el.dom.checked!=this.checked){this.setValue(this.el.dom.value);}}});Ext.namespace("SYNOBLOG_COLUMN_CENTRAL");SYNOBLOG_COLUMN_CENTRAL=function(){this.addEvents({article_update:true,comment_update:true,autosave_update:true});};Ext.extend(SYNOBLOG_COLUMN_CENTRAL,Ext.util.Observable);SYNOBLOG_COLUMN_CENTRAL.instance=function(){return SYNOBLOG_COLUMN_CENTRAL._inst;};SYNOBLOG_COLUMN_CENTRAL._inst=new SYNOBLOG_COLUMN_CENTRAL();SYNOBLOG_COLUMN_CENTRAL.deleteArticle=function(_1){Ext.MessageBox.confirm(blog_str_article_delete,blog_str_article_delete_info+" "+blog_str_article_delete_confirm,showResult);function showResult(_2){if(_2=="yes"){var _3={action:"delete_article",article_id:_1};Ext.Ajax.request({url:"include/article.php",params:_3,method:"POST",scope:this,success:function(_4,_5){if(_4.responseText!="0"){OnNavigate("page_1");}else{alert(blog_str_common_system_error);}var _6=SYNOBLOG_COLUMN_CENTRAL.instance();_6.fireEvent("article_update");}});}}};SYNOBLOG_COLUMN_CENTRAL.deleteComment=function(_7,_8){Ext.MessageBox.confirm(blog_str_comment_delete,blog_str_comment_delete_confirm,showResult);function showResult(_9){if(_9=="yes"){var _a={action:"delete_comment",comment_id:_7};Ext.Ajax.request({url:"include/comment.php",params:_a,method:"POST",scope:this,success:function(_b,_c){if(_b.responseText=="0"){alert(blog_str_common_system_error);}else{SYNOBLOG_COLUMN_CENTRAL.showWholeArticle(_8);}var _d=SYNOBLOG_COLUMN_CENTRAL.instance();_d.fireEvent("comment_update");}});}}};SYNOBLOG_COLUMN_CENTRAL.deleteAllAutosave=function(){Ext.MessageBox.confirm(blog_str_article_delete_all_autosave,blog_str_article_delete_all_autosave_confirm,showResult);function showResult(_e){if(_e=="yes"){var _f={action:"delete_allautosave"};Ext.Ajax.request({url:"include/article.php",params:_f,method:"POST",scope:this,success:function(res,_11){if(res.responseText!="0"){OnNavigate("page_1");}else{alert(blog_str_common_system_error);}var _12=SYNOBLOG_COLUMN_CENTRAL.instance();_12.fireEvent("autosave_update");}});}}};SYNOBLOG_COLUMN_CENTRAL.showWholeArticle=function(_13,_14){var el=Ext.get("column_central");var mgr=el.getUpdateManager();mgr.update("include/article.php",{id:_13,input_key:_14});window.scrollTo(0,0);};SYNOBLOG_COLUMN_CENTRAL.showAbstract=function(_17){var el=Ext.get("column_central");var mgr=el.getUpdateManager();mgr.update("include/article.php",{action:"show_abstract",page:_17});window.scrollTo(0,0);};SYNOBLOG_COLUMN_CENTRAL.showDraftList=function(){var el=Ext.get("column_central");var mgr=el.getUpdateManager();mgr.update("include/article.php",{list_type:"draft"});window.scrollTo(0,0);};SYNOBLOG_COLUMN_CENTRAL.showAutosaveList=function(){var el=Ext.get("column_central");var mgr=el.getUpdateManager();mgr.update("include/article.php",{list_type:"autosave"});window.scrollTo(0,0);};SYNOBLOG_COLUMN_CENTRAL.showDateList=function(_1e){var el=Ext.get("column_central");var mgr=el.getUpdateManager();mgr.update("include/article.php",{list_type:"date",value:_1e});window.scrollTo(0,0);};SYNOBLOG_COLUMN_CENTRAL.showLabelList=function(_21){var el=Ext.get("column_central");var mgr=el.getUpdateManager();mgr.update("include/article.php",{list_type:"label",value:_21});window.scrollTo(0,0);};SYNOBLOG_COLUMN_CENTRAL.showSearchResult=function(_24){if(_24==null||_24==""){return;}var el=Ext.get("column_central");var mgr=el.getUpdateManager();mgr.update("modules/search.php",{action:"search",key:_24});window.scrollTo(0,0);};SYNOBLOG_LOGINDIALOG=function(_1){config={modal:true,autoTabs:true,autoCreate:true,width:370,height:250,shadow:true,minWidth:370,minHeight:250,proxyDrag:true,closable:true,collapsible:false,center:{autoScroll:false,tabPosition:"top",closeOnTab:true,titlebar:false,alwaysShowTabs:true}};SYNOBLOG_LOGINDIALOG.superclass.constructor.call(this,_1,config);this.addButton(blog_str_common_submit,this.onClickSubmit,this);this.addButton(blog_str_common_close,this.hide,this);this.init();this.getLayout().getRegion("center").showPanel(0);this.addKeyListener(27,this.hide,this);this.addKeyListener([10,13],this.onClickSubmit,this);};Ext.extend(SYNOBLOG_LOGINDIALOG,Ext.LayoutDialog,{form:null,messageContainer:Ext.id(),text_field_username:null,photo_url:null,isRedirectToBlog:false,init:function(){var _2=Ext.id();var _3=String.format("<div style=\"margin:20px; font-size:12px;\" id=\"{0}\">{1}</div><div style=\"margin:20px;\" id=\"{2}\"></div>",this.messageContainer,blog_str_login_desc,_2);var _4=this.getLayout();_4.beginUpdate();var cp=_4.add("center",new Ext.ContentPanel(Ext.id(),{autoCreate:true,title:blog_str_home_login,background:true}));_4.endUpdate();cp.setContent(_3);this.form=new Ext.form.Form({labelWidth:100,labelAlign:"right",buttonAlign:"right",trackResetOnLoad:true});this.text_field_username=new Ext.form.TextField({fieldLabel:blog_str_login_account,name:"username",allowBlank:false,width:170,validateOnBlur:true,validationEvent:"blur"});this.form.column({width:300},this.text_field_username,new Ext.form.TextField({fieldLabel:blog_str_login_passwd,name:"passwd",inputType:"password",width:170,validateOnBlur:true,validationEvent:"blur"}));this.form.render(_2);SYNOBLOG_UTILS.SetTextMaxLen(this.form,"username",15);SYNOBLOG_UTILS.SetTextMaxLen(this.form,"passwd",128);this.on("show",function(_6){_6.text_field_username.focus();});this.on("hide",function(_7){if(!this.isRedirectToBlog){window.location="/photo/index.php";}});var el;this.form.on("actioncomplete",function(_9,_a){if(_a.result.success=="login_error"){el=Ext.get(this.messageContainer);el.dom.innerHTML="<font color='#FF0000'>"+blog_str_login_error+"</font><br>"+blog_str_login_desc;}else{if(_a.result.success=="disable_account"){el=Ext.get(this.messageContainer);el.dom.innerHTML="<font color='#FF0000'>"+blog_str_login_error_account_disable+"</font><br>"+blog_str_login_desc;}else{this.hide();var _b="/blog/index.php";if(_a.result.photo_url!=null){_b="/photo/index1.php?"+_a.result.photo_url;}else{if(!this.isRedirectToBlog){_b="/photo/index.php";}}window.location=_b;}}},this);},reset:function(){this.form.reset();var el=Ext.get(this.messageContainer);el.dom.innerHTML=blog_str_login_desc;},onClickSubmit:function(){if(this.form.isValid()){this.form.submit({url:"/blog/login.php",waitTitle:" ",waitMsg:blog_str_man_blog_header_pic_plz_wait,params:"action=login&"+this.photo_url});}},show_dialog:function(_d,_e){this.photo_url=_d;this.isRedirectToBlog=_e;this.show();}});SYNOBLOG_COMMENT_DIALOG=function(_1){config={modal:true,autoTabs:true,autoCreate:true,width:510,height:450,shadow:true,minWidth:510,minHeight:450,proxyDrag:true,closable:true,collapsible:false,center:{autoScroll:false,tabPosition:"top",closeOnTab:true,titlebar:false,alwaysShowTabs:true}};SYNOBLOG_COMMENT_DIALOG.superclass.constructor.call(this,_1,config);this.addButton(blog_str_common_submit,this.onClickSubmit,this);this.addButton(blog_str_common_close,this.hide,this);this.init();this.getLayout().getRegion("center").showPanel(0);this.addKeyListener(27,this.hide,this);this.addKeyListener([10,13],this.onClickSubmit,this);};Ext.extend(SYNOBLOG_COMMENT_DIALOG,Ext.LayoutDialog,{form:null,article_id:0,text_field_name:null,init:function(){var _2=Ext.id();var _3=String.format("<div style=\"margin:20px;\" id=\"{0}\"></div>",_2);var _4=this.getLayout();_4.beginUpdate();var cp=_4.add("center",new Ext.ContentPanel(Ext.id(),{autoCreate:true,title:blog_str_comment_give_comment,background:true}));_4.endUpdate();cp.setContent(_3);this.form=new Ext.form.Form({labelWidth:125,labelAlign:"left",buttonAlign:"right",trackResetOnLoad:true});this.text_field_name=new Ext.form.TextField({fieldLabel:blog_str_comment_name,name:"name",allowBlank:false,width:280,maxLength:16,validateOnBlur:true,validationEvent:"blur"});this.form.fieldset({legend:blog_str_comment,width:470});this.form.column({labelWidth:125,width:430},this.text_field_name,new Ext.form.TextField({fieldLabel:blog_str_comment_mail,name:"mail",width:280,maxLength:128,vtype:"email",validateOnBlur:true,validationEvent:"blur"}),new Ext.form.TextArea({fieldLabel:blog_str_comment,name:"comment",allowBlank:false,width:280,height:110,maxLength:512,validateOnBlur:true,validationEvent:"blur"}),new Ext.form.TextField({fieldLabel:blog_str_comment_magic_num,name:"magic_number",allowBlank:false,width:280,maxLength:64,validateOnBlur:true,validationEvent:"blur"}));var _6="<table><tr><td width='125'></td><td>";_6=_6+"<img id='pic_4' src='images/magic_num_0.gif' border='0'>";_6=_6+"<img id='pic_3' src='images/magic_num_0.gif' border='0'>";_6=_6+"<img id='pic_2' src='images/magic_num_0.gif' border='0'>";_6=_6+"<img id='pic_1' src='images/magic_num_0.gif' border='0'>";_6=_6+"</td></tr></table>";this.form.column({labelWidth:125,width:430,hideLabels:true},new Ext.form.MiscField({name:"magic_num_pic",id:"magic_num_pic",value:_6}));this.form.end();this.form.render(_2);SYNOBLOG_UTILS.SetTextMaxLen(this.form,"name",16);SYNOBLOG_UTILS.SetTextMaxLen(this.form,"mail",128);SYNOBLOG_UTILS.SetTextMaxLen(this.form,"comment",512);SYNOBLOG_UTILS.SetTextMaxLen(this.form,"magic_number",4);this.on("show",function(_7){_7.text_field_name.focus();_7.printMagicnumPics();});this.form.on("actioncomplete",function(_8,_9){if(_9.result.success=="wrong_key"){Ext.MessageBox.alert("",blog_str_comment_magic_num_failed);this.printMagicnumPics();this.form.findField("magic_number").setValue("");}else{this.hide();SYNOBLOG_COLUMN_CENTRAL.showWholeArticle(this.article_id);var _a=SYNOBLOG_COLUMN_CENTRAL.instance();_a.fireEvent("comment_update");}},this);},printMagicnumPics:function(){Ext.Ajax.request({url:"include/magic_number.php",params:"action=gen_rand",method:"POST",scope:this,success:function(_b,_c){var el=Ext.get("pic_4");el.dom.src="include/magic_number.php?n=4&r="+Math.random();el=Ext.get("pic_3");el.dom.src="include/magic_number.php?n=3&r="+Math.random();el=Ext.get("pic_2");el.dom.src="include/magic_number.php?n=2&r="+Math.random();el=Ext.get("pic_1");el.dom.src="include/magic_number.php?n=1&r="+Math.random();}});},reset:function(id){this.form.reset();this.article_id=id;},onClickSubmit:function(){var _f=1;if(!(this.form.isValid())){_f=0;}if(_f){var _10="action=add_comment&article_id="+this.article_id;this.form.submit({url:"include/comment.php",waitTitle:" ",waitMsg:blog_str_man_blog_header_pic_plz_wait,params:_10});}}});SYNOBLOG_MODULE=function(_1,_2){this.div_id=_1;this.hasConfigDialog=_2.hasConfigDialog;this.confDlg_width=_2.width;this.confDlg_height=_2.height;this.form=new Ext.form.Form({labelWidth:120,labelAlign:"left",buttonAlign:"right",trackResetOnLoad:true});this.form.on("actioncomplete",function(_3,_4){if(_4.result.success!=true){if(_4.result.msg!=null){Ext.MessageBox.alert("",_4.result.msg);}}this.getConfigDialogData(_4);},this);};SYNOBLOG_MODULE.prototype={div_id:"",hasConfigDialog:0,configDialog:null,form:null,init:function(){},showConfigDialog:function(){if(this.hasConfigDialog){if(this.configDialog==null){this.initConfigDialog();}this.configDialog.show();}else{Ext.MessageBox.alert("",blog_str_common_noconfig);}},initConfigDialog:function(){this.configDialog=new Ext.LayoutDialog(this.div_id+"_config_dlg",{modal:true,autoTabs:true,autoCreate:true,shadow:true,proxyDrag:true,closable:true,collapsible:false,width:this.confDlg_width,height:this.confDlg_height,minwidth:this.confDlg_width,minheight:this.confDlg_height,center:{autoScroll:true,tabPosition:"top",closeOnTab:true,titlebar:false,alwaysShowTabs:true}});this.configDialog.addKeyListener(27,this.configDialog.hide,this.configDialog);this.customizeConfigDialog();},customizeConfigDialog:function(){},hide:function(){if(this.configDialog){this.configDialog.hide();}},getConfigDialogData:function(_5){}};YAHOO.util.History.register("param",myModuleInitialState,myModuleStateChangeHandler);YAHOO.util.History.onLoadEvent.subscribe(function(){initHistoryManager();});function myModuleStateChangeHandler(_1){if(_1=="draft"){SYNOBLOG_COLUMN_CENTRAL.showDraftList();}else{if(_1=="autosave"){SYNOBLOG_COLUMN_CENTRAL.showAutosaveList();}else{if(_1.indexOf("page_")==0){SYNOBLOG_COLUMN_CENTRAL.showAbstract(_1.replace("page_",""),"");}else{if(_1.indexOf("id_")==0){SYNOBLOG_COLUMN_CENTRAL.showWholeArticle(_1.replace("id_",""),"");}else{if(_1.indexOf("label_")==0){SYNOBLOG_COLUMN_CENTRAL.showLabelList(_1.replace("label_",""));}else{if(_1.indexOf("date_")==0){SYNOBLOG_COLUMN_CENTRAL.showDateList(_1.replace("date_",""));}else{if(_1.indexOf("search_")==0){SYNOBLOG_COLUMN_CENTRAL.showSearchResult(_1.replace("search_",""));}}}}}}}}function initHistoryManager(){var _2=YAHOO.util.History.getQueryStringParameter("id");if(_2==null||_2==""){_2=YAHOO.util.History.getQueryStringParameter("list_type");}if(_2==null||_2==""){var _3=YAHOO.util.History.getCurrentState("param");if(_3!=null&&_3!=""&&_3!="page_1"){myModuleStateChangeHandler(YAHOO.util.History.getCurrentState("param"));}}}function OnNavigate(_4){YAHOO.util.History.navigate("param",_4);}function onShowCommentForm(id){var _6=SYNOBLOG.instance();_6.comment_dialog.reset(id);_6.comment_dialog.show();}function onShowArticleForm(id){var _8=SYNOBLOG.instance();if(_8.article_dialog!=null){_8.article_dialog.reset(id);_8.article_dialog.show();}}function OnLogin(){var _9=SYNOBLOG.instance();_9.login_dialog.reset();_9.login_dialog.show_dialog("",1);}function onShowModuleConfigDialog(_a){var _b=SYNOBLOG.instance();_b.modules[_a].showConfigDialog();}Ext.onReady(function(){if(g_is_synoblog_admin){tinyMCE_setFont();}YAHOO.util.History.afterInitialize();Ext.QuickTips.init();var _c=SYNOBLOG.instance();var x;var _e=_c.getAllModules();for(x in _e){_c.getModule(x).init();}_c.login_dialog=Ext.DialogManager.get("login-dlg");if(!_c.login_dialog){_c.login_dialog=new SYNOBLOG_LOGINDIALOG("login-dlg");}_c.comment_dialog=Ext.DialogManager.get("comment-dlg");if(!_c.comment_dialog){_c.comment_dialog=new SYNOBLOG_COMMENT_DIALOG("comment-dlg");}if(g_is_synoblog_admin){_c.article_dialog=Ext.DialogManager.get("article-dlg");if(!_c.article_dialog){_c.article_dialog=new SYNOBLOG_ARTICLE_DIALOG("article-dlg");}}});SYNOBLOG=function(){};SYNOBLOG.prototype={modules:{},login_dialog:null,comment_dialog:null,article_dialog:null,registerModule:function(_1,_2,_3){var _4=_3?(new _3(_1,_2)):null;if(_4){_4.manager=this;}this.modules[_1]=_4;},getModule:function(_5){if(this.modules[_5]){return this.modules[_5];}else{return null;}},getAllModules:function(){return this.modules;}};SYNOBLOG.instance=function(){return SYNOBLOG._inst;};SYNOBLOG._inst=new SYNOBLOG();