﻿
__trGroup('CMS Form');Ext.namespace('NPSL','NPSL.Cms','NPSL.Cms.Form','Ext.ux');(function(){var Cms=NPSL.Cms,Form=Cms.Form,ColType=Cms.ColType,MimeTypes=Cms.MimeTypes;Form.CmsField=function(){};Form.CmsField.fromXML=function(n,ownerForm,ownerRecord){var tableName;var a=n.getAttribute("bind");if(!a){throw"cms-field node is missing the bind attribute";}
var tc=Cms.parseDotted(a);if(tc.length==1){for(var p=n.getParent();p;p=p.getParent()){if(p.getName()==="cms-record"){tableName=p.getAttribute("table");if(!tableName){throw"parent cms-record node of cms-field node has no table attribute";}}}
if(!tableName){throw"cannot find ancestor cms-record node for field bound to '"+a+"'. If there is no ancestor, ensure that the bound columm name includes a table name, i.e. TABLE.COLUMN, not just COLUMN";}
columnName=tc[0];}else if(tc.length==2){tableName=tc[0];columnName=tc[1];}else if(tc.length==3){tableName='"'+tc[0]+'"."'+tc[1]+'"';columnName=tc[2];}
var tab=g_schema.findTable(tableName);if(!tab){throw"cms-field node references the non-existent table \""+tableName+"\"";}
var col=tab.columnsByName[columnName];if(!col){throw"cms-field node references the non-existent column \""+tableName+"\".\""+columnName+"\"";}
if(!ownerRecord){ownerRecord=ownerForm.records[tab.qname()];if(!ownerRecord){throw"cms-field without an owning cms-record";}}
var config={fieldLabel:n.getAttribute("label"),ownerForm:ownerForm,ownerRecord:ownerRecord,helpTarget:n.getAttribute("help-target"),hideMandatory:n.getAttribute("hide-mandatory-icon")==='true',checkGetter:ownerRecord.getFieldValue.createDelegate(ownerRecord),regionOwner:n.getAttribute("region-owner")==="yes",valueTrigger:n.getChild("value-trigger"),type:n.getAttribute("type"),disabled:n.getAttribute("disabled")==="yes"?true:ownerForm.readOnly};if(n.getAttribute("light-html")){config.lightHtml=n.getAttribute("light-html")==='true';}
var val=n.getAttribute("force-value");if(val!==null){config.forceValue=val;}
Form.copyIntAttribute(config,n,"height");Form.copyIntAttribute(config,n,"width");Form.copyIntAttribute(config,n,"columns");Form.copyBoolAttribute(config,n,"vertical");Form.copyBoolAttribute(config,n,"autocomplete","autoComplete");Form.copyIntAttribute(config,n,"min-chars","minChars");Form.copyIntAttribute(config,n,"query-delay","queryDelay");var searchForm=n.selectSingleNode("search-form");if(searchForm){var scfg=config.searchFormConfig={};var searchFields=searchForm.getAttribute("fields");if(searchFields){scfg.fields=Form.parseQuotedList(searchFields);}
scfg.filterInline=searchForm.getAttribute("filter-inline")!=="no";scfg.inline=searchForm.getAttribute("inline")!=="no";}else{var scfg=config.searchFormConfig={};scfg.filterInline=false;scfg.inline=false;}
config.template=n.selectSingleNode("template");if(config.type==="value-combo"){var dataNodes=n.selectNodes("entries/entry");config.data=[];for(var i=0;i<dataNodes.length;++i){var dataNode=dataNodes[i];config.data.push([dataNode.getAttribute("label"),dataNode.getAttribute("value")]);}
Form.copyBoolAttribute(config,n,"allow-alpha","allowAlpha");Form.copyBoolAttribute(config,n,"allow-decimals","allowDecimals");Form.copyBoolAttribute(config,n,"is-percent","isPercent");config.otherText=n.getAttribute("other-text");config.otherLabel=n.getAttribute("other-label");Form.copyIntAttribute(config,n,"other-field-width","otherFieldWidth");}
var f=Form.createEditField(col,config);if(f==null){return null;}
ownerRecord.addField(f);if((col.help||(col.colType!=ColType.Boolean&&!col.nullable))&&!(f instanceof Ext.form.Hidden)){f._onRender=f.onRender;f.onRender=function(ct,pos){this._onRender(ct,pos);var el=Ext.getDom(this.wrap||this.el);var tab=document.createElement("table");tab.cellspacing=0;tab.cellpadding=0;el.parentNode.insertBefore(tab,el);el.parentNode.removeChild(el);var tr=tab.insertRow(-1);var td=tr.insertCell(-1);td.appendChild(el);function imageButton(url,tip){td=tr.insertCell(-1);td.vAlign="top";var img=document.createElement("img");img.style.verticalAlign="top";img.style.paddingLeft="4px";img.src=url;td.appendChild(img);Ext.QuickTips.register({target:img,text:tip,autoHide:true,showDelay:0,dismissDelay:0});}
if(col.help){var ht=Form.getInheritableAttribute(this,'helpTarget')||'icon';if(ht==='label'){Ext.DomHelper.append(this.formItem.select('label').elements[0],{tag:'span',cls:'label-info-text',html:col.help});}else if(ht==='field'){var hEl=Ext.DomHelper.insertAfter(this.el,{cls:'form-notes',html:col.help});this.ownerCt.on('afterlayout',function(hEl,el){Ext.fly(hEl).setWidth(el.getWidth());}.createDelegate(this,[hEl,this.el],false));}else{imageButton("/fp/shared/images/ic_info.gif",col.help);}}
if(col.colType!=ColType.Boolean&&!col.nullable){var hm=Form.getInheritableAttribute(this,'hideMandatory');if(!hm){imageButton("/fp/shared/images/mandatory.gif",__tr('This field is mandatory'));}}};}
if(!Form.LayoutMode){return f;}
function makeDraggable(o){o.afterRender=o.afterRender.createSequence(function(){Form.initDragZoneFE(this);});Ext.apply(o,{clone:function(){return makeDraggable(new this.constructor(this.initialConfig));},saveXml:function(p){var n=p.ownerDocument.createElement('textfield');p.appendChild(n);}});return o;}
return makeDraggable(f);};Form.reg(Form.CmsField,'cms-field');}());