
if(typeof pilifs=="undefined")var pilifs={};if(typeof pilifs.yui=="undefined")pilifs.yui={};pilifs.yui.BaseDialog=Base.extend({constructor:function(elementId,config){var dialog=null;this._Dom=YAHOO.util.Dom;this._dialog=null;this._visible=false;this._config={};this._elementId=elementId;this._element=this._Dom.get(this._elementId);this.extend({getId:function(id){return this._Dom.get(id);},setConfig:function(value){this._config=value;if(typeof this._config.visible=="undefined")this._config.visible=false;if(typeof this._config.fixedcenter=="undefined")this._config.fixedcenter=false;if(typeof this._config.constraintoviewport=="undefined")this._config.constraintoviewport=true;if(typeof this._config.width=="undefined"){if(this._element.getAttribute("yuiWidth")&&this._element.getAttribute("yuiWidth")!="")this._config.width=this._element.getAttribute("yuiWidth");else this._config.width="400px";}},handleSuccess:function(o){try{alert(o.responseText);this._dialog.hide();}catch(e){alert(e.message+"\n"+o.responseText);}},handleFailure:function(o){alert(elementId+" -> pilifs.yui.BaseDialog.handleFailure(o): Error in process of time the request!");},init:function(){this._dialog=null;if(typeof this._config.buttons=="undefined"){this._config.buttons=[{text:"OK",handler:function(){this.submit();},isDefault:true},{text:"Cancel",handler:function(){this.cancel();}}];}
this._config.hideaftersubmit=false;this._dialog=new YAHOO.widget.Dialog(elementId,this._config);this._dialog.hideEvent.subscribe(function(){this._visible=false;},this,true);this._dialog.showEvent.subscribe(function(){this._visible=true;},this,true);this._dialog.callback={success:this.handleSuccess,failure:this.handleFailure};this._dialog.render();this._element.style.display="block";dialog=this._dialog;this._dialog.ownerDlg=this;},setVisible:function(value){if(value==this._visible)return;if(value==true){this._dialog.show();}
else{this._dialog.hide();}},show:function(){this.setVisible(true);},hide:function(){this.setVisible(false);},getForm:function(){return this._dialog.form;}});if(typeof config=="undefined")this.setConfig({})
else this.setConfig(config);}});pilifs.yui.DialogError=pilifs.yui.BaseDialog.extend({constructor:function(){id="errorDialog";var config={};config.buttons=[{text:"OK",handler:function(){this.cancel();},isDefault:true}];config.fixedcenter=true;config.width="400px";this.base(id,config);this.getId(id).style.display='block';this.extend({show:function(msg){this.getId(id+'Msg').innerHTML=msg;this.base();document.getElementById(id+"_c").style.zIndex=document.getElementById(id+"_mask").style.zIndex+1;}});}});pilifs.yui.DialogInfo=pilifs.yui.BaseDialog.extend({constructor:function(){var id='infoDialog';var config={};config.buttons=[{text:"OK",handler:function(){this.cancel();},isDefault:true}];config.fixedcenter=true;config.width="400px";this.base(id,config);this.getId(id).style.display='block';this.extend({show:function(msg){this.getId(id+'Msg').innerHTML=msg;this.base();}});}});pilifs.yui.Dialog=pilifs.yui.BaseDialog.extend({btNew:null,btEdit:null,constructor:function(elementId,gridObj,config){this.base(elementId,config);var dialog=null;var submitText="Submit";var cancelText="Cancel";var grid;var isNew=false;var editors=new Array();this.extend({setIsNew:function(value){isNew=value==true;},dialogCancel:function(){this.cancel();},dialogSubmit:function(){var continue_ok=true;if(typeof grid.onBeforeSave!="undefined")continue_ok=grid.onBeforeSave(dialog);if(continue_ok)this.submit();},handleSuccess:function(o){try{var msg=YAHOO.lang.JSON.parse(o.responseText);if(typeof msg.Name!="undefined"&&msg.Name=="ResponseAjax"){if(msg.Error){throw msg.Message;}
var data=typeof msg.Data=="object"?msg.Data:YAHOO.lang.JSON.parse(msg.Data);if(isNew){grid.insertRow(data);}
else{grid.updateRow(data);}
if(msg.Message!='')window.infoDialog.show(msg.Message);}
else{if(isNew)grid.insertRow(msg);else grid.updateRow(msg);}
dialog.hide();}catch(err){if(typeof grid.onErrorSave!="undefined")grid.onErrorSave(err);else alert(err);}},handleFailure:function(o){alert(elementId+" -> pilifs.yui.Dialog.handleFailure(o): Error in process of time the request!");},editRecord:function(){if(!grid.isSelected()){alert("pilifs.yui.Grid.editRecord(): not selected row for edit!");return;}
isNew=false;var r=grid.getData();var f=dialog.form;for(var o in r){var el=dialog.form.elements[o];if(el&&el.getAttribute("autofill")!="false"){var v=eval("r."+o);switch(el.tagName.toLowerCase()){case'input':if(el.getAttribute("type")=="checkbox")el.checked=v=="1";else{var setting=el.getAttribute("setting");if(setting){setting=YAHOO.lang.JSON.parse("{"+setting+"}");if(setting.type=="date")v=pilifs.convert.dateIbToString(v);}
el.value=v;}
break;case'select':el.value=v;break;case'textarea':if(el.getAttribute("editor")=="true"){for(var i in editors){if(editors[i]._pilifName==el.name){editors[i].setEditorHTML(v);break;}}}
else{el.value=v;}
break;default:alert("pilif.yui.Dialog.eventDblClick ->"+el.tagName+": isn't supported element type!");break;}}}
if(typeof grid.onBeforeEdit!="undefined")grid.onBeforeEdit(r,dialog);dialog.show();},createRichEditors:function(){for(var i=0;i<this._dialog.form.elements.length;i++){var el=this._dialog.form.elements[i];if(el.tagName.toLowerCase()=="textarea"&&el.getAttribute("editor")=="true"){var edtConf={dompath:true,focusAtStart:true};var edt=new YAHOO.widget.SimpleEditor(el.id,edtConf);edt._pilifName=el.name;edt.render();editors.push(edt);}}},setDataGrid:function(value){grid=value;grid.setEventDblClick(this.editRecord);},init:function(){this._dialog=null;if(typeof this._config.buttons=="undefined"){if(document.getElementById("pnlEdit")){this.elPanel=document.getElementById("pnlEdit");if(this.elPanel.getAttribute("submitLabel")){submitText=this.elPanel.getAttribute("submitLabel");};if(this.elPanel.getAttribute("cancelLabel")){cancelText=this.elPanel.getAttribute("cancelLabel");};};this._config.buttons=[{text:submitText,handler:this.dialogSubmit,isDefault:true},{text:cancelText,handler:this.dialogCancel}];};this.base();dialog=this._dialog;this.createRichEditors();},setSubmitText:function(value){submitText=value;},setCancelText:function(value){cancelText=value;},setButtonNew:function(value){this.btNew=new YAHOO.widget.Button(value);YAHOO.util.Event.addListener(value,"click",function(){isNew=true;for(var i=0;i<this._dialog.form.elements.length;i++){var el=this._dialog.form.elements[i];if(el.getAttribute("autofill")!="false"){switch(el.tagName.toLowerCase()){case'input':if(el.getAttribute("type")=="checkbox")el.checked=false;else el.value="";break;case'select':el.value="";break;case'textarea':el.value="";break;default:break;}}}
if(typeof grid.onBeforeNew!="undefined")grid.onBeforeNew(this._dialog);this._dialog.show();},this,true);},setButtonEdit:function(value){this.btEdit=new YAHOO.widget.Button(value,{disabled:true});YAHOO.util.Event.addListener(value,"click",this.editRecord);}});if(typeof gridObj!="undefined")this.setDataGrid(gridObj);if(this._element.getAttribute("yuiButtonNew"))this.setButtonNew(this._element.getAttribute("yuiButtonNew"));if(this._element.getAttribute("yuiButtonEdit"))this.setButtonEdit(this._element.getAttribute("yuiButtonEdit"));}});pilifs.yui.DialogFiltr=pilifs.yui.BaseDialog.extend({constructor:function(dialogId,gridObj,config){var dialog=null;var grid=(typeof gridObj=="undefined")?null:gridObj;this.base(dialogId,config);var filtr=null;this.btFiltr=null;var buttons=[{text:"OK",handler:function(){this.hide();grid.loadByFiltr(filtr);},isDefault:true},{text:"Cancel",handler:function(){this.cancel();}}];this._config.buttons=buttons;this.extend({init:function(){this.base();dialog=this._dialog;filtr=dialog.form;},setConfig:function(value){if(typeof value.buttons=="undefined")value.buttons=buttons;this.base(value);},_findLoad:function(){grid.loadByFiltr(filtr);},setGrid:function(value){grid=value;},setButtonShow:function(value){this.btFiltr=new YAHOO.widget.Button(value);YAHOO.util.Event.addListener(value,"click",function(){this.show();},this,true);}});if(this._element.getAttribute("yuiButtonShow")){this.setButtonShow(this._element.getAttribute("yuiButtonShow"));}}});