MDomItem.js 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336
  1. /*
  2. DOMElement管理类
  3. var item = new MDomItem( containerNode, {
  4. name : "demo",
  5. type : "checkbox",
  6. selectValue: [opt1,opt2,opt3]
  7. selectText : function( callback , options ){ //异步方法的写法,需要一个callback,并且把该option值传给callback执行,这个function不能bind
  8. this.app.actions.XXX( id, function( json ){
  9. var optText = [];
  10. ....
  11. callback( optText )
  12. })
  13. },
  14. value : function(){ var val = .... ; return val; }
  15. } , null, app, css);
  16. item.load();
  17. 外部方法:
  18. get( textOrValue ) 参数"text"或"value" 获取文本或值
  19. getValue() 获取值
  20. getText() 获取文本
  21. getModifiedValue() 获取修改过的值,如果没有修改过返回null
  22. getModifiedText() 获取修改过的文本,如果没有修改过返回null
  23. setValue() 设置对象的值
  24. resetType( type ) 修改类型
  25. resetItemOptions( selectValue[, selectText ]) 修改可选项,selectValue可项值,selectText可选文本
  26. dispose() 清空对象
  27. verify( isShowWarning ) 参数isShowWarning,校验不通过的是否提示用户。根据isShowWarning参数和options的notEmpty、warningType、validRule属性校验对象,返回boolean
  28. */
  29. //MWF.xDesktop.requireApp("Template", "lp." + MWF.language, null, false);
  30. var MDomItem_ClassType = {
  31. "text" : "Text",
  32. "textarea" : "Textarea",
  33. "hidden" : "Hidden",
  34. "password" : "Password",
  35. "radio" : "Radio",
  36. "checkbox" : "Checkbox",
  37. "select" : "Select",
  38. "multiselect" : "Multiselect",
  39. "innertext" : "Innertext",
  40. "innerhtml" : "Innerhtml",
  41. "img" : "Img",
  42. "button" : "Button",
  43. "mselector" : "MSelector",
  44. "imageclipper" : "ImageClipper",
  45. "rtf" : "Rtf",
  46. "org" : "Org",
  47. "a" : "A"
  48. };
  49. var MDomItem = new Class({
  50. Implements: [Options, Events],
  51. options : {
  52. name : "", //生成的对象的name属性
  53. value : "", //对象的值
  54. text : "", //对应的中文名称
  55. type : "", //可以为 text,innertext, radio,checkbox,select,multiselect,img,button,hidden,rtf,imageClipper, org, mSelector
  56. isEdited : true,
  57. tType : "", //type 为text时候有效,可以为 number,date,time, datetime,person、unit、identity,如果是组织混合选择用数组,如["person"、"unit"、"identity"]
  58. orgType : "", //person、unit、identity, process, duty,如果是混合选择用数组,如["person"、"unit"、"identity"]
  59. unitType : "", //如果orgType包含unit,则可以指定组织类型
  60. count : 1, //如果是多选,多选的上限值,0表示无限制,默认为1,
  61. units : [], //orgType 为 identity、unit时的,部门选择范围
  62. groups : [], //orgType 为 person 时的选择访问
  63. exclude : [], //选择时的排除项目
  64. expandSubEnable : true, //orgType 为 identity、unit时是否展开下级选择范围
  65. orgStyle : "", //显示类型,比如default, xform 等
  66. unsetDefaultEvent : false, //tType 或 orgType 有值时,是否取消默认事件
  67. //可以传入json 如 : { change : function(){alert("change " + this.name );}, click : function(){alert("click " + this.name) } }
  68. //或 字符串 : "{ change : function(){alert('change ' + this.name );}, click : function(){alert('click ' + this.name) } }"
  69. //或字符串: "change^^function(){alert('change ' + this.name );##click^^function(obj){alert('click ' + this.name);}"
  70. event : null, //需要绑定的事件
  71. selectValue : "", //选择性控件的可选值
  72. selectText : "", //选择型控件的可选文本
  73. defaultValue : "", //默认值
  74. className : "", //类
  75. style : {}, //样式
  76. attr : {}, //其他参数, 比如 " {readonly : true, size : '20' }"
  77. notEmpty : false, //是否允许为空,默认允许
  78. defaultValueAsEmpty: false, //检查空值时,默认值是否为空,并且获取值得时候,如果是默认值,返回空值
  79. emptyTip : null, //为空时的提示,可以不设置
  80. disable : false, //为false,则load失效;
  81. //alert 或者 batch 或者 single,单个提醒或者批量提醒
  82. warningType : "batch",
  83. validImmediately : false,
  84. //可以传入校验类型或自定义方法,如
  85. //{email : true , url : true, date : true, dateISO : true, number : true, digits : true,
  86. // maxlength:5, minlength:10, rangelength:[5,10], max:5, min:10 ,range:[5,10], extension: ["xls","xlsx"],fun : function(){ return true }
  87. // }
  88. validRule : null,
  89. //validMessage和validRule对应,出错时提示的信息,如 {email : "请输入正确格式的电子邮件", fun : "请输入正确的密码"},如果不设置,默认如下:
  90. // { email: "请输入正确格式的电子邮件",
  91. // url: "请输入合法的网址",
  92. // date: "请输入合法的日期",
  93. // dateISO: "请输入合法的日期 (ISO).",
  94. // number: "请输入合法的数字",
  95. // digits: "只能输入整数",
  96. // maxlength: this.format("请输入一个 长度最多是 {0} 的字符串"),
  97. // minlength: this.format("请输入一个 长度最少是 {0} 的字符串"),
  98. // rangelength: this.format("请输入 一个长度介于 {0} 和 {1} 之间的字符串"),
  99. // range: this.format("请输入一个介于 {0} 和 {1} 之间的值"),
  100. // max: this.format("请输入一个最大为{0} 的值"),
  101. // min: this.format("请输入一个最小为{0} 的值"),
  102. // fun : "请输入正确的"+ this.options.text
  103. // }
  104. validMessage : null,
  105. RTFConfig : null, //CKEditor 的设置项
  106. mSelectorOptions : null, //自定义下拉组件设置项
  107. calendarOptions : null, //日期选择器的设置项
  108. orgWidgetOptions : null, //org组件的选项
  109. orgOptions: null
  110. },
  111. initialize: function (container, options , parent, app, css ) {
  112. this.form = parent;
  113. this.tr = parent;
  114. this.parent = parent;
  115. this.app = app;
  116. this.container = $(container);
  117. if( css )this.css = css;
  118. if( options.formStyle ){
  119. this.cssPath = "../x_component_Template/$MForm/"+options.formStyle+"/css.wcss";
  120. this._loadCss();
  121. }
  122. //for(var o in options ){ //允许使用 function 来计算设置, on开头的属性被留作 fireEvent
  123. // if( o != "validRule" && o!="validMessage" && o.substr(0,2)!="on" && typeOf( options[o] )== "function" ){
  124. // options[o] = options[o].call();
  125. // }
  126. //}
  127. //this.setOptions(options);
  128. this.valSeparator = /,|;|\^\^|\|/; //如果是多值对象,作为用户选择的多个值的分隔符
  129. this.mElement = this.container; //容器
  130. this.node = this.container;
  131. this.items = [];
  132. this.setOptionList( options );
  133. },
  134. setOptionList : function( options ){ //目的是使用options里的function异步方法通过 function(callback){ ...获取value; callback( value ); } 来回调设置option
  135. var callbackNameList = [];
  136. for(var o in options ){ //允许使用 function 来计算设置, on开头的属性被留作 fireEvent
  137. if( o != "validRule" && o!="validMessage" && o.substr(0,2)!="on" && typeOf( options[o] )== "function" ){
  138. var fun = options[o];
  139. if( fun.length && /\(\s*([\s\S]*?)\s*\)/.exec(fun)[1].split(/\s*,\s*/)[0] == "callback" ){ //如果有行参(fun.length!=0),并且第一形参是callback,注意,funciont不能bind(this),否则不能判断
  140. callbackNameList.push( o );
  141. }else{
  142. options[o] = fun( options, this ); //执行fun
  143. }
  144. }
  145. }
  146. this.setFunOption( options, callbackNameList, true ); //递归执行回调设置options
  147. },
  148. setFunOption : function( options, callbackNameList, isFirst ){
  149. this.optionsReady = false;
  150. if( callbackNameList.length == 0 ){
  151. this.setOptions( options );
  152. this.optionsReady = true;
  153. if( this.loadFunctionCalled ){ //如果外部程序已经执行过load,但是由于options没有设置完成而中断,需要再调用一下load
  154. this.load();
  155. }
  156. }else{
  157. if( isFirst )options = Object.merge( {}, options ); //避免外部程序对options的修改
  158. var name = callbackNameList.shift(); //返回第一个元素,然后在callbackNameList删除第一元素
  159. var fun = options[name]; //对应的参数,是一个function
  160. fun( function( val ){ //执行function
  161. options[name] = val; //在回调内部给option赋值
  162. this.setFunOption( options, callbackNameList, false ); //继续执行下一个回调
  163. }.bind(this), options );
  164. }
  165. },
  166. load: function () {
  167. if( !this.optionsReady ){ //如果options没有设置完成
  168. this.loadFunctionCalled = true;
  169. return;
  170. }
  171. if( this.options.disable )return;
  172. if( ! this.options.type ){
  173. this.options.type = this.options.orgType ? "org" : "text";
  174. }
  175. this.options.type = this.options.type.toLowerCase();
  176. this.fireEvent("queryLoad");
  177. this.createElement();
  178. this.fireEvent("postLoad", [this]);
  179. },
  180. _loadCss: function(reload){
  181. debugger;
  182. var key = encodeURIComponent(this.cssPath);
  183. if (!reload && o2.widget.css[key]){
  184. this.css = !this.css ? o2.widget.css[key] : Object.merge({}, o2.widget.css[key], this.css);
  185. }else{
  186. this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+o2.version.v : this.cssPath+"?v="+o2.version.v;
  187. var r = new Request.JSON({
  188. url: o2.filterUrl(this.cssPath),
  189. secure: false,
  190. async: false,
  191. method: "get",
  192. noCache: false,
  193. onSuccess: function(responseJSON, responseText){
  194. this.css = !this.css ? responseJSON : Object.merge({}, responseJSON, this.css);
  195. o2.widget.css[key] = responseJSON;
  196. }.bind(this),
  197. onError: function(text, error){
  198. alert(error + text);
  199. }
  200. });
  201. r.send();
  202. }
  203. },
  204. editMode : function( keep ){
  205. if(keep)this.save();
  206. this.options.isEdited = true;
  207. this.dispose();
  208. this.items = [];
  209. this.load();
  210. },
  211. save : function(){
  212. this.options.value = this.getValue();
  213. },
  214. readMode : function( keep ){
  215. if(keep)this.save();
  216. this.options.isEdited = false;
  217. this.dispose();
  218. this.items = [];
  219. this.load();
  220. },
  221. enable : function(){
  222. this.options.disable = false;
  223. this.dispose();
  224. this.load();
  225. },
  226. disable : function(){
  227. this.options.disable = true;
  228. this.dispose();
  229. },
  230. createElement:function(){
  231. if( this.options.disable )return;
  232. var clazzName = MDomItem_ClassType[ this.options.type ];
  233. if( clazzName ){
  234. this.dom = new MDomItem[ clazzName ]( this );
  235. this.dom.load();
  236. }
  237. return this.container;
  238. },
  239. get: function( vort ){ //value 和 text
  240. if( this.options.disable ){
  241. return {
  242. text : "",
  243. value : ""
  244. };
  245. }
  246. if( this.dom )return this.dom.get( vort );
  247. },
  248. getValue : function( separator, name ){
  249. var result = this.get( null , name ).value;
  250. if( separator && typeOf( result ) == "array" ){
  251. return result.join( separator );
  252. }else{
  253. return result;
  254. }
  255. },
  256. getText : function( separator, name ){
  257. var result = this.get( null , name ).text;
  258. if( separator && typeOf( result ) == "array" ){
  259. return result.join( separator );
  260. }else{
  261. return result;
  262. }
  263. },
  264. getModifiedValue : function( separator ){
  265. var value = this.getValue( separator );
  266. return value == this.options.value ? null : value ;
  267. },
  268. getModifiedText : function(){
  269. var value = this.getText();
  270. return text == this.options.text ? null : text ;
  271. },
  272. getVaildValue : function(verify, separator, isHiddenWarming, onlyModified ) {
  273. if ( !verify || this.verify(!isHiddenWarming)) {
  274. return onlyModified ? this.getModifiedValue( separator ) : this.getValue( separator );
  275. } else {
  276. return false;
  277. }
  278. },
  279. set : function( type, valueOrText ){
  280. this.setValue( valueOrText )
  281. },
  282. resetItemOptions : function( selectValue, selectText, isForce ){
  283. if( this.options.disable ){
  284. if( isForce ){
  285. this.options.disable = false;
  286. }else{
  287. return;
  288. }
  289. }
  290. var availTypes = "radio,checkbox,select,multiselect".split( "," );
  291. if( !availTypes.contains( this.options.type ) )return;
  292. this.dispose();
  293. this.options.selectValue = selectValue;
  294. this.options.selectText = selectText;
  295. this.createElement();
  296. },
  297. reset: function(){
  298. debugger;
  299. if( typeOf(this.dom.reset) === "function" ){
  300. this.dom.reset();
  301. }else{
  302. this.setValue( this.options.defaultValue || "" );
  303. }
  304. },
  305. setValue :function(value){
  306. if( this.dom )this.dom.setValue(value);
  307. },
  308. setStyles : function( styles ){
  309. if( this.options.disable )return;
  310. this.items.each( function( item ){
  311. item.setStyles( styles )
  312. })
  313. },
  314. getElements : function(){
  315. if( this.options.disable )return null;
  316. return this.mElement.getElements("[name='"+this.options.name+"']");
  317. },
  318. dispose : function(){
  319. this.container.empty();
  320. },
  321. verify : function( isShowWarning ){
  322. var flag = true;
  323. if( !this.options.isEdited )return flag;
  324. if( this.options.disable )return flag;
  325. if( this.options.warningType == "batch" ){
  326. if( !this.isNotEmpty(isShowWarning) ) flag = false;
  327. if( !this.checkValid(isShowWarning) ) flag = false;
  328. }else{
  329. if( !this.isNotEmpty(isShowWarning) || !this.checkValid(isShowWarning) ){
  330. return false;
  331. }
  332. }
  333. return flag;
  334. },
  335. isNotEmpty: function( isShowWarning ){
  336. if( !this.options.isEdited )return true;
  337. if( this.options.disable )return true;
  338. if( this.options.notEmpty == true || this.options.notEmpty == "yes" ){
  339. if( !this.checkNotEmpty( isShowWarning ) ){
  340. return false;
  341. }
  342. }
  343. return true;
  344. },
  345. checkNotEmpty:function( isShowWarning ){
  346. if( this.options.disable )return true;
  347. var value = this.getValue();
  348. var isEmpty = ( typeOf(value) === "array" ? ( value.length == 0 ) : ( value == "" || value == " ") );
  349. if( !isEmpty && this.options.defaultValueAsEmpty ){
  350. isEmpty = ( typeOf(value) === "array" ? ( value.length == 1 && value[0] == this.options.defaultValue ) : ( value == this.options.defaultValue ) );
  351. }
  352. if( !isEmpty ){
  353. this.clearWarning("empty");
  354. return true;
  355. }
  356. if( !isShowWarning )return false;
  357. var text = this.options.text;
  358. var items = this.mElement.getElements("[name='"+ this.options.name + "']");
  359. var warningText = "";
  360. var focus = false;
  361. try{
  362. warningText = this.options.emptyTip || (this.dom && this.dom.getErrorText()) || MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",text);
  363. if( this.options.warningType == "batch" ) {
  364. this.setWarning(warningText, "empty");
  365. }else if( this.options.warningType == "single" ){
  366. this.setWarning(warningText, "empty");
  367. }else{
  368. if( this.app && this.app.notice ){
  369. if (!this.container.isIntoView()){
  370. var pNode = this.container.getParent();
  371. while (pNode && ((pNode.getScrollSize().y-(pNode.getComputedSize().height+1)<=0) || pNode.getStyle("overflow")==="visible")) pNode = pNode.getParent();
  372. if (!pNode) pNode = document.body;
  373. pNode.scrollToNode(this.container, "bottom");
  374. }
  375. var y = this.container.getSize().y;
  376. this.app.notice(warningText,"error",this.container, {"x": "right", "y": "top"}, { x : 10, y : y });
  377. }
  378. if( !this.options.validImmediately ){
  379. if( ["text","password","textarea","select","multiselect"].contains( this.options.type ) ){
  380. items[0].focus();
  381. }
  382. }
  383. }
  384. this.fireEvent("empty", this);
  385. }catch( e ){
  386. }
  387. return false;
  388. },
  389. clearWarning : function( type ){
  390. if( this.tipNode && this.setedEmpty ){
  391. this.fireEvent("unempty", this);
  392. this.tipNode.empty();
  393. this.setedEmpty = false;
  394. }
  395. if( type == "empty" ){
  396. if( this.warningEmptyNode ){
  397. this.fireEvent("unempty", this);
  398. this.warningEmptyNode.destroy();
  399. this.warningEmptyNode = null;
  400. }
  401. }else{
  402. if( this.warningInvalidNode ){
  403. this.fireEvent("unempty", this);
  404. this.warningInvalidNode.destroy();
  405. this.warningInvalidNode = null;
  406. }
  407. }
  408. this.warningStatus = false;
  409. },
  410. setWarning : function( msg, type ){
  411. var div;
  412. if( type == "empty" ){
  413. if( this.tipNode ){
  414. this.setedEmpty = true;
  415. div = this.tipNode;
  416. div.set("html", "");
  417. }else if( this.warningEmptyNode ){
  418. div = this.warningEmptyNode;
  419. div.set("html", "");
  420. }else{
  421. div = this.warningEmptyNode = new Element("div");
  422. div.inject( this.container ) ;
  423. }
  424. }else{
  425. if( this.tipNode ){
  426. this.setedEmpty = true;
  427. div = this.tipNode;
  428. div.set("html", "");
  429. }else if( this.warningInvalidNode ){
  430. div = this.warningInvalidNode;
  431. div.set("html", "");
  432. }else{
  433. div = this.warningInvalidNode = new Element("div");
  434. div.inject( this.container ) ;
  435. }
  436. }
  437. this.warningStatus = true;
  438. if( typeOf(msg) != "array" ){
  439. msg = [msg];
  440. }
  441. msg.each( function(m){
  442. //var html = "<table style=\"margin-top:3px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
  443. //html += "<tr valign=\"middle\"><td><img src=\"./img/exclamation.png\" /></td>";
  444. //html += "<td style=\"width:3px;\"></td><td><div style=\"color:#FF0000; margin-top:2px;\">"+m+"</div></td></tr>";
  445. //html += "</table>";
  446. var node = new Element("div",{
  447. "text" : m,
  448. "styles" : this.css.warningMessageNode
  449. }).inject(div)
  450. }.bind(this))
  451. },
  452. checkValid : function( isShowWarning ){
  453. if( this.options.disable )return true;
  454. var value = this.getValue();
  455. var rules = this.options.validRule;
  456. if( !rules )return true;
  457. var msgs = [];
  458. var flag = true;
  459. //if( value && value != "" && value != " " ){
  460. var rule, msg, method, valid;
  461. if( typeOf( rules ) === "object" ){
  462. for(var r in rules ){
  463. valid = true;
  464. rule = rules[r];
  465. if( typeof rule == "function"){
  466. valid = rule.call( this, value, this );
  467. }else if( this.validMethod[r] ){
  468. method = this.validMethod[r];
  469. valid = method.call(this, value, rule, this );
  470. }
  471. if( !valid && isShowWarning ){
  472. msg = this.getValidMessage( r, rule );
  473. if( msg != "" )msgs.push( msg );
  474. }
  475. if( !valid )flag = false;
  476. }
  477. }else if( typeOf( rules ) === "array" ){
  478. for( var i = 0; i<rules.length; i++ ){
  479. if( typeof rules[i] == "function"){
  480. msg = rules[i].call( this, value, this );
  481. if( msg && typeof msg === "string" ){
  482. flag = false;
  483. if( isShowWarning )msgs.push( msg );
  484. }
  485. }
  486. }
  487. }else if( typeOf( rules ) === "function" ){
  488. msg = rules.call( this, value, this );
  489. if( msg && typeof msg === "string" ){
  490. flag = false;
  491. if( isShowWarning )msgs.push( msg );
  492. }
  493. }
  494. //}
  495. if( msgs.length > 0 ){
  496. if( this.options.warningType == "batch" ) {
  497. this.setWarning(msgs, "invaild");
  498. }else if( this.options.warningType == "single" ){
  499. this.setWarning(msgs, "invaild");
  500. }else{
  501. if( this.app && this.app.notice ) {
  502. if (!this.container.isIntoView()) {
  503. var pNode = this.container.getParent();
  504. while (pNode && ((pNode.getScrollSize().y - (pNode.getComputedSize().height + 1) <= 0) || pNode.getStyle("overflow") === "visible")) pNode = pNode.getParent();
  505. if (!pNode) pNode = document.body;
  506. pNode.scrollToNode(this.container, "bottom");
  507. }
  508. var y = this.container.getSize().y;
  509. this.app.notice(msgs.join("\n"), "error", this.container, {"x": "right", "y": "top"}, { x : 10, y : y });
  510. }
  511. }
  512. this.fireEvent("empty", this);
  513. }else{
  514. if( this.warningInvalidNode ){
  515. this.warningInvalidNode.destroy();
  516. this.warningInvalidNode = null;
  517. }
  518. this.fireEvent("unempty", this);
  519. }
  520. return flag;
  521. },
  522. validMethod : {
  523. email: function( value ) {
  524. return /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
  525. },
  526. url: function( value ) {
  527. return /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test( value );
  528. },
  529. phoneNumber: function( value ){
  530. return /^0?1[0-9]\d{9}$/.test( value );
  531. },
  532. date: function( value ) {
  533. return !/Invalid|NaN/.test( new Date( value ).toString() );
  534. },
  535. dateISO: function( value ) {
  536. return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value );
  537. },
  538. number: function( value ) {
  539. return /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
  540. },
  541. digits: function( value ) {
  542. return /^\d+$/.test( value );
  543. },
  544. minlength: function( value, param ) {
  545. return value.length >= param;
  546. },
  547. maxlength: function( value, param ) {
  548. return value.length <= param;
  549. },
  550. rangelength: function( value, param ) {
  551. return ( value.length >= param[ 0 ] && value.length <= param[ 1 ] );
  552. },
  553. min: function( value, param ) {
  554. return value >= param;
  555. },
  556. max: function( value, param ) {
  557. return value <= param;
  558. },
  559. range: function( value, param ) {
  560. return ( value >= param[ 0 ] && value <= param[ 1 ] );
  561. },
  562. extension: function( value, param ){
  563. param = typeOf( param ) == "array" ? param.join("|") : param.replace(/,/g, "|"); //"png|jpe?g|gif";
  564. return value.match(new RegExp(".(" + param + ")$", "i"));
  565. }
  566. },
  567. getValidMessage : function( type, param ){
  568. var msg = this.options.validMessage;
  569. if( msg && typeOf(msg) == "object" ){
  570. if( msg[type] ){
  571. if( typeof msg[type] == "function" ){
  572. return (msg[type]).call(this);
  573. }else{
  574. return msg[type];
  575. }
  576. }
  577. }
  578. var lp = MWF.xApplication.Template.LP.MDomItem;
  579. switch( type ){
  580. case "email":
  581. return lp.emailTip;
  582. case "url":
  583. return lp.urlTip;
  584. case "phoneNumber" :
  585. return lp.phoneNumberTip;
  586. case "date":
  587. return lp.dateTip;
  588. case "dateISO":
  589. return lp.dateISOTip;
  590. case "number":
  591. return lp.numberTip;
  592. case "digits":
  593. return lp.digitsTip;
  594. case "maxlength":
  595. return lp.maxlengthTip.replace("{n}",param );
  596. case "minlength":
  597. return lp.minlengthTip.replace("{n}",param );
  598. case "rangelength":
  599. return lp.rangelengthTip.replace("{n0}",param[0] ).replace("{n1}",param[1] ) ;
  600. case "range":
  601. return lp.rangeTip.replace("{n0}",param[0] ).replace("{n1}",param[1] ) ;
  602. case "min":
  603. return lp.minTip.replace("{n}",param );
  604. case "max":
  605. return lp.maxTip.replace("{n}",param );
  606. case "extension":
  607. return lp.extensionTip.replace("{text}",param );
  608. default :
  609. return lp.defaultTip.replace("{text}",this.options.text );
  610. }
  611. },
  612. destroy: function(){
  613. if( this.dom && this.dom.OrgWidgetList ){
  614. this.dom.OrgWidgetList.each( function( widget ){
  615. widget.destroy();
  616. })
  617. }
  618. if( this.mElement ){
  619. this.mElement.empty();
  620. }
  621. MWF.release( this );
  622. }
  623. });
  624. MDomItem.Util = {
  625. selectCalendar : function( target, container, options, callback ){
  626. var type = options.type;
  627. var calendarOptions = {
  628. "style" : "xform",
  629. "isTime": type == "time" || type.toLowerCase() == "datetime",
  630. "timeOnly": type == "time",
  631. "target": container,
  632. "onComplate" : function( dateString ,date ){
  633. if( callback )callback( dateString, date );
  634. }.bind(this),
  635. "onClear": function () {
  636. if( callback )callback( "", null );
  637. }
  638. };
  639. if( options.calendarOptions ){
  640. calendarOptions = Object.merge( calendarOptions, options.calendarOptions )
  641. }
  642. var calendar;
  643. MWF.require("MWF.widget.Calendar", function(){
  644. calendar = new MWF.widget.Calendar( target, calendarOptions);
  645. calendar.show();
  646. }.bind(this), false);
  647. return calendar;
  648. },
  649. selectPerson: function( container, options, callback ){
  650. if( options.type === "custom" ){
  651. this._selectCustom(container, options, callback);
  652. }else{
  653. this._selectPerson(container, options, callback);
  654. }
  655. },
  656. _selectCustom: function( container, options, callback ){
  657. MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false); //加载资源
  658. var opt = {
  659. "title": options.title,
  660. "count" : options.count,
  661. "values": options.selectedValues || [],
  662. "expand": typeOf( options.expand ) === "boolean" ? options.expand : true,
  663. "exclude" : options.exclude || [],
  664. "expandSubEnable" : typeOf( options.expandSubEnable ) === "boolean" ? options.expandSubEnable : true,
  665. "hasLetter" : false, //是否点击字母搜索
  666. "hasTop" : false, //可选、已选的标题
  667. // "level1Indent" : 0, //第一层的缩进
  668. // "indent" : 36, //第二层及以上的缩进
  669. "selectAllEnable" : true, //是否允许多选,如果分类可以被选中,blue_flat样式下失效
  670. "width" : "700px", //选中框宽度
  671. "height" :"550px", //选中框高度
  672. "category": true, //按分类选择
  673. "noSelectedContainer" : false, //是否隐藏右侧已选区域
  674. "categorySelectable" : false, //分类是否可以被选择,如果可以被选择那么执行的是item的事件
  675. "uniqueFlag" : "id", //项目匹配(是否选中)关键字
  676. "defaultExpandLevel" : 1, //默认展开项目,0表示折叠所有分类
  677. "onComplete": function( array ){
  678. if( callback )callback( array );
  679. }.bind(this)
  680. };
  681. if( options.orgOptions ){
  682. opt = Object.merge(opt, options.orgOptions);
  683. }
  684. var selector = new MWF.xApplication.Template.Selector.Custom(container, opt );
  685. selector.load();
  686. },
  687. _selectPerson: function( container, options, callback ){
  688. MWF.xDesktop.requireApp("Selector", "package", null, false);
  689. var selectType = "", selectTypeList = [];
  690. var type = options.type;
  691. if( typeOf( type ) == "array" ){
  692. if( type.length > 1 ){
  693. selectTypeList = type;
  694. }else if( type.length == 0 ) {
  695. selectType = "person";
  696. }else{
  697. selectType = type[0] || "person";
  698. }
  699. }else{
  700. selectType = type || "person";
  701. }
  702. var opt = {
  703. "type": selectType,
  704. "types" : selectTypeList,
  705. "title": options.title,
  706. "count" : options.count,
  707. "values": options.selectedValues || [],
  708. "units" : options.units,
  709. "unitType" : options.unitType,
  710. "groups" : options.groups,
  711. "expand": options.expand,
  712. "exclude" : options.exclude || [],
  713. "expandSubEnable" : options.expandSubEnable,
  714. "onComplete": function( array ){
  715. if( callback )callback( array );
  716. }.bind(this)
  717. };
  718. if( options.orgOptions ){
  719. opt = Object.merge(opt, options.orgOptions);
  720. }
  721. if( opt.types.length === 0 )opt.types = null;
  722. var selector = new MWF.O2Selector(container, opt );
  723. },
  724. replaceText : function( value, selectValue, selectText, separator ){
  725. if( typeOf( value ) == "number" )value = [ value ];
  726. if( typeOf( selectValue ) == "number" )selectValue = [ selectValue ];
  727. if( typeOf( selectText ) == "number" )selectText = [ selectText ];
  728. var vals = typeOf( value ) == "array" ? value : value.split( separator );
  729. var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( separator );
  730. var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split( separator );
  731. for( var i=0 ;i<vals.length; i++ ){
  732. for( var j= 0; j<selectValues.length; j++){
  733. if( vals[i] == selectValues[j] ){
  734. vals[i] = selectTexts[j]
  735. }
  736. }
  737. }
  738. return vals;
  739. },
  740. getEvents : function( events ){
  741. if( !events || events == "" || events == "$none" )return;
  742. if( typeof events == "string" ){
  743. if( events.indexOf("^^") > -1 ){
  744. var eventsArr = events.split("##");
  745. if( eventsArr[0].split("^^").length != 2 )return;
  746. events = {};
  747. for(var i=0;i<eventsArr.length;i++){
  748. var ename = eventsArr[i].split("^^")[0];
  749. var efunction = eventsArr[i].split("^^")[1];
  750. events[ ename ] = eval( "(function(){ return "+ efunction +" })()" ); //字符串变对象或function,方法1
  751. }
  752. }else{
  753. //字符串变对象或function,方法2
  754. eval( "var events = " + events );
  755. }
  756. }
  757. return events;
  758. },
  759. bindEvent: function( obj, item, events){
  760. events = MDomItem.Util.getEvents( events );
  761. if( typeOf(events) == "object" ){
  762. for( var e in events ){
  763. //jquery的写法
  764. //item.bind( e, { fun : events[e] }, function( event ){
  765. //this 是触发事件的对象,self是当前jDomItem对象
  766. //event.data.fun.call( this, _self );
  767. //})
  768. //方法固定,把参数作为this指正传给方法,需要在方法体里通过this获取参数
  769. //item.addEvent( e, events[e].bind({"item": item, "_self":_self}));
  770. //参数固定,把方法传入到function中,可以在回调方法中直接获取,和jquery的写法一样
  771. item.addEvent( e, function(ev){
  772. this.fun.call( ev ? ev.target : null, obj.module || obj, ev );
  773. }.bind({fun : events[e]}));
  774. //不一定行
  775. //item.addEvent( e, (function(){
  776. // return function(){
  777. // events[e].call(item,_self);
  778. // }
  779. //})(e));
  780. }
  781. // for( var e in events ){
  782. // if( type && (e=="dblclick" || e=="click") ){
  783. // if( jQuery.inArray( type , this.unsetClassType) == -1 ){
  784. // if( !item.attr("title") || item.attr("title") == "" ){
  785. // item.attr( "title", e=="dblclick" ? "双击选择"+this.options.text : "单击选择"+this.options.text );
  786. // }
  787. // item.removeClass("inputtext").addClass("inputclick");
  788. // break;
  789. // }
  790. // }
  791. // }
  792. }
  793. }
  794. };
  795. MDomItem.Text = new Class({
  796. initialize: function ( module ) {
  797. this.module = module;
  798. this.options = module.options;
  799. this.css = module.css;
  800. this.app = module.app;
  801. this.items = module.items;
  802. this.container = this.mElement = module.container;
  803. },
  804. load : function(){
  805. if( this.options.isEdited ){
  806. this.loadEdit()
  807. }else{
  808. this.loadRead();
  809. }
  810. },
  811. loadEdit : function(){
  812. var module = this.module;
  813. var options = this.options;
  814. var item;
  815. var value ;
  816. if( typeOf( options.value ) === "boolean" ){
  817. value = options.value.toString();
  818. }else{
  819. value = options.value || options.defaultValue
  820. }
  821. var parent = module.container ;
  822. var className = this.getClassName();
  823. item = new Element( "input", {
  824. "type" : "text",
  825. "name" : options.name,
  826. "value" : value
  827. });
  828. var tType = this.options.tType;
  829. if (tType == "time" || tType == "date" || tType.toLowerCase() == "datetime") {
  830. item.set("autocomplete", "off");
  831. }
  832. item.set( options.attr || {} );
  833. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  834. if( options.clazz )item.addClass( options.clazz );
  835. item.setStyles( options.style || {} );
  836. this.bindDefaultEvent( item );
  837. MDomItem.Util.bindEvent( this, item, options.event);
  838. if(parent)item.inject(parent);
  839. this.items.push( item );
  840. },
  841. loadRead : function(){
  842. var module = this.module;
  843. var options = this.options;
  844. var item;
  845. var value;
  846. var className = this.getClassName();
  847. var parent = module.container ;
  848. if( typeOf( options.value ) === "boolean" ){
  849. value = options.value.toString();
  850. }else{
  851. value = options.value || options.defaultValue
  852. }
  853. item = new Element( "span", {
  854. "name" : options.name,
  855. "text" : value
  856. });
  857. item.set( options.attr );
  858. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  859. if( options.clazz )item.addClass( options.clazz );
  860. item.setStyles( options.style || {} );
  861. if(parent)item.inject(parent);
  862. this.items.push( item );
  863. },
  864. get : function( vort ){ //value 和 text 或 空
  865. if( this.options.disable ){
  866. return ( vort == "value" || vort == "text" ) ? null : {
  867. value : null,
  868. text : null
  869. };
  870. }
  871. var value;
  872. var name = this.options.name;
  873. var item = this.mElement.getElement("[name='"+name+"']");
  874. if( this.options.isEdited ){
  875. value = item.get("value");
  876. }else{
  877. value = item.get("text");
  878. }
  879. if( vort == "value" )return value;
  880. if( vort == "text")return value;
  881. return {
  882. value : value,
  883. text : value
  884. };
  885. },
  886. setValue : function( value ){
  887. if( this.options.disable ){
  888. return;
  889. }
  890. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  891. if( this.options.isEdited ){
  892. item.set( "value", value );
  893. }else{
  894. item.set("text", value );
  895. }
  896. },
  897. getErrorText : function(){
  898. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  899. },
  900. getClassName : function(){
  901. var tType = this.options.tType;
  902. var className = null ;
  903. if( this.options.className == "none" ){
  904. }else if( this.options.className != "") {
  905. className = this.options.className
  906. }else if( !this.options.isEdited ){
  907. }else {
  908. if (typeOf(tType) == "array") {
  909. if (tType.contains("identity") || tType.contains("person") || tType.contains("unit")) {
  910. className = "inputPerson";
  911. } else {
  912. className = "inputText";
  913. }
  914. } else {
  915. if (!tType) {
  916. className = "inputText";
  917. } else if (tType == "number") {
  918. className = "inputText";
  919. } else if (tType == "time" || tType == "date" || tType.toLowerCase() == "datetime") {
  920. className = "inputTime";
  921. } else if (tType == "identity" || tType == "person" || tType.toLowerCase() == "unit") {
  922. className = "inputPerson";
  923. } else {
  924. className = "inputText";
  925. }
  926. }
  927. }
  928. return className;
  929. },
  930. bindDefaultEvent : function( item ){
  931. if( this.options.unsetDefaultEvent )return;
  932. var tType = this.options.tType;
  933. var type = "text";
  934. if( typeOf( tType ) == "array" || ( tType == "identity" || tType.toLowerCase() == "person" || tType == "unit" ) ){
  935. item.addEvent( "click" , function(ev){
  936. this.module.fireEvent("querySelect", this.module );
  937. var options = this.options;
  938. var opt = {
  939. type : tType,
  940. title : options.text,
  941. count : options.count,
  942. selectedValues : this.get("value").split(","),
  943. units : options.units,
  944. unitType : options.unitType,
  945. groups : options.groups,
  946. expand : options.expand
  947. };
  948. MDomItem.Util.selectPerson( this.app.content, opt, function( array ){
  949. item.empty();
  950. this.orgData = this.module.orgData = [];
  951. this.orgObject = this.module.orgObject = array;
  952. array.each(function( it ){
  953. this.orgData.push( it.data.distinguishedName || it.data.name );
  954. }.bind(this));
  955. item.set("value",this.orgData.join(","));
  956. this.items[0].fireEvent("change", [this.module, ev]);
  957. if( this.options.validImmediately )this.module.verify( true );
  958. }.bind(this))
  959. }.bind(this) );
  960. }else{
  961. if( tType == "number" ){
  962. item.addEvent( "keyup" , function(){
  963. this.value=this.value.replace(/[^\d.]/g,'');
  964. });
  965. if( this.options.validImmediately ){
  966. item.addEvent("blur", function(){ this.module.verify( true ); }.bind(this))
  967. }
  968. }else if( tType == "time" || tType.toLowerCase() == "datetime" || tType == "date" ){
  969. item.addEvent( "click" , function(ev){
  970. this.module.fireEvent("querySelect", this.module );
  971. if( this.calendarSelector ){
  972. this.calendarSelector.show();
  973. }else{
  974. this.calendarSelector = MDomItem.Util.selectCalendar( item, this.app.content, {
  975. calendarOptions : this.options.calendarOptions,
  976. type : tType
  977. }, function( dateString, date ){
  978. this.items[0].fireEvent("change", [this.module, ev]);
  979. if( this.options.validImmediately )this.module.verify( true );
  980. }.bind(this) )
  981. }
  982. }.bind(this) );
  983. }else{
  984. if( this.options.validImmediately ){
  985. item.addEvent("blur", function(){ this.module.verify( true ); }.bind(this))
  986. }
  987. }
  988. }
  989. }
  990. });
  991. MDomItem.Textarea = new Class({
  992. initialize: function ( module ) {
  993. this.module = module;
  994. this.options = module.options;
  995. this.css = module.css;
  996. this.app = module.app;
  997. this.items = module.items;
  998. this.container = this.mElement = module.container;
  999. },
  1000. load : function(){
  1001. if( this.options.isEdited ){
  1002. this.loadEdit()
  1003. }else{
  1004. this.loadRead();
  1005. }
  1006. },
  1007. loadEdit : function(){
  1008. var module = this.module;
  1009. var options = this.options;
  1010. var item;
  1011. var value ;
  1012. if( typeOf( options.value ) === "boolean" ){
  1013. value = options.value.toString();
  1014. }else{
  1015. value = options.value || options.defaultValue
  1016. }
  1017. var parent = module.container ;
  1018. var className = this.getClassName();
  1019. item = new Element( "textarea", {
  1020. "name" : options.name,
  1021. "value" : value
  1022. });
  1023. item.set( options.attr || {} );
  1024. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1025. if( options.clazz )item.addClass( options.clazz );
  1026. item.setStyles( options.style || {} );
  1027. this.bindDefaultEvent( item );
  1028. MDomItem.Util.bindEvent( this, item, options.event);
  1029. if(parent)item.inject(parent);
  1030. this.items.push( item );
  1031. },
  1032. loadRead : function(){
  1033. var module = this.module;
  1034. var options = this.options;
  1035. var item;
  1036. var value;
  1037. var className = this.getClassName();
  1038. var parent = module.container ;
  1039. if( typeOf( options.value ) === "boolean" ){
  1040. value = options.value.toString();
  1041. }else{
  1042. value = options.value || options.defaultValue
  1043. }
  1044. item = new Element( "span", {
  1045. "name" : options.name,
  1046. "text" : value
  1047. });
  1048. item.set( options.attr || {} );
  1049. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1050. if( options.clazz )item.addClass( options.clazz );
  1051. item.setStyles( options.style || {} );
  1052. if(parent)item.inject(parent);
  1053. this.items.push( item );
  1054. },
  1055. bindDefaultEvent : function( item ){
  1056. if( this.options.unsetDefaultEvent )return;
  1057. if( this.options.validImmediately ){
  1058. item.addEvent("blur", function(){ this.module.verify( true ); }.bind(this))
  1059. }
  1060. },
  1061. get : function( vort ){
  1062. if( this.options.disable ){
  1063. return ( vort == "value" || vort == "text" ) ? null : {
  1064. value : null,
  1065. text : null
  1066. };
  1067. }
  1068. var value;
  1069. var name = this.options.name;
  1070. var item = this.mElement.getElement("[name='"+name+"']");
  1071. if( this.options.isEdited ){
  1072. value = item.get("value");
  1073. }else{
  1074. value = item.get("text");
  1075. }
  1076. if( vort == "value" )return value;
  1077. if( vort == "text")return value;
  1078. return {
  1079. value : value,
  1080. text : value
  1081. };
  1082. },
  1083. setValue : function( value ){
  1084. if( this.options.disable ){
  1085. return;
  1086. }
  1087. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  1088. if( this.options.isEdited ){
  1089. item.set( "value", value );
  1090. }else{
  1091. item.set("text", value );
  1092. }
  1093. },
  1094. getErrorText : function(){
  1095. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  1096. },
  1097. getClassName : function(){
  1098. var tType = this.options.tType;
  1099. var className = null ;
  1100. if( this.options.className == "none" ){
  1101. }else if( this.options.className != "") {
  1102. className = this.options.className
  1103. }else if( !this.options.isEdited ){
  1104. }else {
  1105. className = "inputTextarea"
  1106. }
  1107. return className;
  1108. }
  1109. });
  1110. MDomItem.Hidden = new Class({
  1111. initialize: function ( module ) {
  1112. this.module = module;
  1113. this.options = module.options;
  1114. this.css = module.css;
  1115. this.app = module.app;
  1116. this.items = module.items;
  1117. this.container = this.mElement = module.container;
  1118. },
  1119. load : function(){
  1120. var parent = this.container;
  1121. var item = new Element( "input", {
  1122. "type" : "hidden",
  1123. "name" : this.options.name,
  1124. "value" : this.options.value
  1125. });
  1126. item.set( this.options.attr || {} );
  1127. //this.bindEvent(item,event,type);
  1128. if(parent)item.inject(parent);
  1129. this.items.push( item );
  1130. },
  1131. get : function( vort ){
  1132. if( this.options.disable ){
  1133. return ( vort == "value" || vort == "text" ) ? null : {
  1134. value : null,
  1135. text : null
  1136. };
  1137. }
  1138. var value;
  1139. var name = this.options.name;
  1140. var item = this.mElement.getElement("[name='"+name+"']");
  1141. if( this.options.isEdited ){
  1142. value = item.get("value");
  1143. }else{
  1144. value = item.get("text");
  1145. }
  1146. if( vort == "value" )return value;
  1147. if( vort == "text")return value;
  1148. return {
  1149. value : value,
  1150. text : value
  1151. };
  1152. },
  1153. setValue : function( value ){
  1154. if( this.options.disable ){
  1155. return;
  1156. }
  1157. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  1158. item.set( "value", value );
  1159. },
  1160. getErrorText : function(){
  1161. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  1162. }
  1163. });
  1164. MDomItem.Password = new Class({
  1165. initialize: function ( module ) {
  1166. this.module = module;
  1167. this.options = module.options;
  1168. this.css = module.css;
  1169. this.app = module.app;
  1170. this.items = module.items;
  1171. this.container = this.mElement = module.container;
  1172. },
  1173. load : function(){
  1174. if( this.options.isEdited ){
  1175. this.loadEdit()
  1176. }else{
  1177. }
  1178. },
  1179. loadEdit : function(){
  1180. var module = this.module;
  1181. var options = this.options;
  1182. var item;
  1183. var value ;
  1184. if( typeOf( options.value ) === "boolean" ){
  1185. value = options.value.toString();
  1186. }else{
  1187. value = options.value || options.defaultValue
  1188. }
  1189. var parent = module.container ;
  1190. var className = this.getClassName();
  1191. item = new Element( "input", {
  1192. "type" : "password",
  1193. "name" : options.name,
  1194. "value" : value
  1195. });
  1196. item.set( options.attr || {} );
  1197. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1198. if( options.clazz )item.addClass( options.clazz );
  1199. item.setStyles( options.style || {} );
  1200. this.bindDefaultEvent( item );
  1201. MDomItem.Util.bindEvent( this, item, options.event);
  1202. if(parent)item.inject(parent);
  1203. this.items.push( item );
  1204. },
  1205. loadRead : function(){
  1206. },
  1207. bindDefaultEvent : function( item ){
  1208. if( this.options.unsetDefaultEvent )return;
  1209. if( this.options.validImmediately ){
  1210. item.addEvent("blur", function(){ this.module.verify( true ); }.bind(this))
  1211. }
  1212. },
  1213. get : function( vort ){
  1214. if( this.options.disable ){
  1215. return ( vort == "value" || vort == "text" ) ? null : {
  1216. value : null,
  1217. text : null
  1218. };
  1219. }
  1220. var value;
  1221. var name = this.options.name;
  1222. var item = this.mElement.getElement("[name='"+name+"']");
  1223. if( this.options.isEdited ){
  1224. value = item.get("value");
  1225. }else{
  1226. value = this.options.value || this.options.defaultValue
  1227. }
  1228. if( vort == "value" )return value;
  1229. if( vort == "text")return value;
  1230. return {
  1231. value : value,
  1232. text : value
  1233. };
  1234. },
  1235. setValue : function( value ){
  1236. if( this.options.disable ){
  1237. return;
  1238. }
  1239. if( this.options.isEdited ){
  1240. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  1241. item.set( "value", value );
  1242. }else{
  1243. this.options.value = value;
  1244. }
  1245. },
  1246. getErrorText : function(){
  1247. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  1248. },
  1249. getClassName : function(){
  1250. var tType = this.options.tType;
  1251. var className = null ;
  1252. if( this.options.className == "none" ){
  1253. }else if( this.options.className != "") {
  1254. className = this.options.className
  1255. }else if( !this.options.isEdited ){
  1256. }else {
  1257. className = "inputPassword"
  1258. }
  1259. return className;
  1260. }
  1261. });
  1262. MDomItem.Radio = new Class({
  1263. initialize: function ( module ) {
  1264. this.module = module;
  1265. this.options = module.options;
  1266. this.css = module.css;
  1267. this.app = module.app;
  1268. this.items = module.items;
  1269. this.container = this.mElement = module.container;
  1270. this.valSeparator = module.valSeparator;
  1271. },
  1272. load : function(){
  1273. if( !this.options.selectValue && this.options.selectText )this.options.selectValue = this.options.selectText;
  1274. if( !this.options.selectText && this.options.selectValue )this.options.selectText = this.options.selectValue;
  1275. if( this.options.isEdited ){
  1276. this.loadEdit();
  1277. }else{
  1278. this.loadRead();
  1279. }
  1280. },
  1281. loadEdit : function(){
  1282. var _self = this;
  1283. var item;
  1284. var name = this.options.name;
  1285. var value ;
  1286. if( typeOf( this.options.value ) === "boolean" ){
  1287. value = this.options.value.toString();
  1288. }else{
  1289. value = this.options.value || this.options.defaultValue
  1290. }
  1291. var selectValue = this.options.selectValue || this.options.selectText;
  1292. var selectText = this.options.selectText || this.options.selectValue ;
  1293. var event = this.options.event;
  1294. var styles = this.options.style || {};
  1295. var attr = this.options.attr || {};
  1296. var parent = this.container ;
  1297. var className = this.getClassName() ;
  1298. var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( this.valSeparator );
  1299. var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split(this.valSeparator);
  1300. for( i=0;i<selectValues.length;i++){
  1301. item = new Element( "div");
  1302. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1303. if( this.options.clazz )item.addClass( this.options.clazz );
  1304. item.setStyles( styles );
  1305. var input = new Element( "input", {
  1306. "type" : "radio",
  1307. "name" : name,
  1308. "value" : selectValues[i],
  1309. "checked" : selectValues[i] == value
  1310. }).inject( item );
  1311. input.set( attr );
  1312. var textNode = new Element( "span", {
  1313. "text" : selectTexts[i]
  1314. }).inject(item);
  1315. textNode.addEvent("click", function (ev) {
  1316. if( _self.options.attr && _self.options.attr.disabled )return;
  1317. this.input.checked = !this.input.checked;
  1318. var envents = MDomItem.Util.getEvents(_self.options.event);
  1319. if (typeOf(envents) == "object") {
  1320. if (envents.change) {
  1321. envents.change.call(this.input, _self.module, ev);
  1322. }
  1323. if (envents.click) {
  1324. envents.click.call(this.input, _self.module, ev);
  1325. }
  1326. }
  1327. if (_self.options.validImmediately) {
  1328. _self.module.verify(true);
  1329. }
  1330. }.bind({input: input}));
  1331. if( this.options.validImmediately ){
  1332. input.addEvent( "click", function(){ this.module.verify( true )}.bind(this) );
  1333. }
  1334. MDomItem.Util.bindEvent( this, item, event ); //? input or item
  1335. if(parent)item.inject(parent);
  1336. this.items.push( item );
  1337. }
  1338. },
  1339. loadRead : function(){
  1340. var item;
  1341. var name = this.options.name;
  1342. var value ;
  1343. if( typeOf( this.options.value ) === "boolean" ){
  1344. value = this.options.value.toString();
  1345. }else{
  1346. value = this.options.value || this.options.defaultValue
  1347. }
  1348. var selectValue = this.options.selectValue || this.options.selectText;
  1349. var selectText = this.options.selectText || this.options.selectValue ;
  1350. var styles = this.options.style || {};
  1351. var attr = this.options.attr || {};
  1352. var parent = this.container ;
  1353. var className = this.getClassName() ;
  1354. if( selectValue && selectText ){
  1355. value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
  1356. value = value.join(",");
  1357. }
  1358. item = new Element( "span", {
  1359. "name" : name,
  1360. "text" : value
  1361. });
  1362. item.set( attr );
  1363. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1364. if( this.options.clazz )item.addClass( this.options.clazz );
  1365. item.setStyles( styles );
  1366. if(parent)item.inject(parent);
  1367. this.items.push( item );
  1368. },
  1369. get : function( vort ){
  1370. if( this.options.disable ){
  1371. return ( vort == "value" || vort == "text" ) ? null : {
  1372. value : null,
  1373. text : null
  1374. };
  1375. }
  1376. var value;
  1377. var text;
  1378. var items;
  1379. var name = this.options.name;
  1380. items = this.mElement.getElements("[name='"+name+"']");
  1381. if( this.options.isEdited ){
  1382. items.each(function( el ){
  1383. if( el.checked ){
  1384. value = el.get("value");
  1385. text = el.getParent().get("text").trim();
  1386. }
  1387. });
  1388. }else{
  1389. text = items[0].get("text");
  1390. if( this.options.selectValue && this.options.selectText ){
  1391. value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator).join();
  1392. }else{
  1393. value = text;
  1394. }
  1395. }
  1396. if( !value )value="";
  1397. if( !text )text = value;
  1398. if( vort == "value" )return value;
  1399. if( vort == "text")return text;
  1400. var result = {};
  1401. result.value = value;
  1402. result.text = text;
  1403. return result;
  1404. },
  1405. setValue : function( value ){
  1406. if( this.options.disable ){
  1407. return;
  1408. }
  1409. var items= this.mElement.getElements("[name='"+ this.options.name + "']");
  1410. if( this.options.isEdited ){
  1411. items.each(function( el ){
  1412. if( el.get("value") == value ) el.checked = true;
  1413. });
  1414. }else{
  1415. value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
  1416. value = value.join(",");
  1417. items[0].set("text", value );
  1418. }
  1419. },
  1420. getErrorText : function(){
  1421. return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
  1422. },
  1423. getClassName : function(){
  1424. var className = null ;
  1425. if( this.options.className == "none" ){
  1426. }else if( this.options.className != "") {
  1427. className = this.options.className
  1428. }else if( !this.options.isEdited ){
  1429. }else {
  1430. className = "inputRadio"
  1431. }
  1432. return className;
  1433. }
  1434. });
  1435. MDomItem.Checkbox = new Class({
  1436. initialize: function ( module ) {
  1437. this.module = module;
  1438. this.options = module.options;
  1439. this.css = module.css;
  1440. this.app = module.app;
  1441. this.items = module.items;
  1442. this.container = this.mElement = module.container;
  1443. this.valSeparator = module.valSeparator;
  1444. },
  1445. load : function(){
  1446. if( !this.options.selectValue && this.options.selectText )this.options.selectValue = this.options.selectText;
  1447. if( !this.options.selectText && this.options.selectValue )this.options.selectText = this.options.selectValue;
  1448. if( this.options.isEdited ){
  1449. this.loadEdit();
  1450. }else{
  1451. this.loadRead();
  1452. }
  1453. },
  1454. loadEdit : function(){
  1455. var _self = this;
  1456. var item;
  1457. var values;
  1458. var name = this.options.name;
  1459. var value ;
  1460. if( typeOf( this.options.value ) === "boolean" ){
  1461. value = this.options.value.toString();
  1462. }else{
  1463. value = this.options.value || this.options.defaultValue
  1464. }
  1465. var selectValue = this.options.selectValue || this.options.selectText;
  1466. var selectText = this.options.selectText || this.options.selectValue ;
  1467. var event = this.options.event;
  1468. var styles = this.options.style || {};
  1469. var attr = this.options.attr || {};
  1470. var isEdited = this.options.isEdited;
  1471. var parent = this.mElement = this.container ;
  1472. var className = this.getClassName();
  1473. values = typeOf( value ) == "string" ? value.split(this.valSeparator) : value ;
  1474. values = typeOf( value ) == "array" ? value : [value];
  1475. var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( this.valSeparator );
  1476. var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split(this.valSeparator);
  1477. for( var i=0;i<selectValues.length;i++){
  1478. item = new Element( "div");
  1479. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1480. if( this.options.clazz )item.addClass( this.options.clazz );
  1481. item.setStyles( styles );
  1482. var input = new Element( "input", {
  1483. "type" : "checkbox",
  1484. "name" : name,
  1485. "value" : selectValues[i],
  1486. "checked" : values.contains( selectValues[i] )
  1487. }).inject( item );
  1488. input.set( attr );
  1489. var textNode = new Element( "span", {
  1490. "text" : selectTexts[i]
  1491. }).inject(item);
  1492. textNode.addEvent("click", function( ev ){
  1493. if( _self.options.attr && _self.options.attr.disabled )return;
  1494. this.input.checked = ! this.input.checked;
  1495. var envents = MDomItem.Util.getEvents( _self.options.event );
  1496. if( typeOf( envents ) == "object" ){
  1497. if( envents.change ){
  1498. envents.change.call( this.input, _self.module, ev );
  1499. }
  1500. if( envents.click ){
  1501. envents.click.call( this.input, _self.module, ev );
  1502. }
  1503. }
  1504. if( _self.options.validImmediately ){
  1505. _self.module.verify( true );
  1506. }
  1507. }.bind( {input : input} ) );
  1508. if( this.options.validImmediately ){
  1509. item.addEvent("click", function(){ this.module.verify( true ); }.bind(this))
  1510. }
  1511. MDomItem.Util.bindEvent( this, item, event); // ? input or item
  1512. if(parent)item.inject(parent);
  1513. this.items.push( item );
  1514. }
  1515. },
  1516. loadRead : function(){
  1517. var item;
  1518. var name = this.options.name;
  1519. var value ;
  1520. if( typeOf( this.options.value ) === "boolean" ){
  1521. value = this.options.value.toString();
  1522. }else{
  1523. value = this.options.value || this.options.defaultValue
  1524. }
  1525. var selectValue = this.options.selectValue || this.options.selectText;
  1526. var selectText = this.options.selectText || this.options.selectValue ;
  1527. var styles = this.options.style || {};
  1528. var attr = this.options.attr || {};
  1529. var parent = this.mElement = this.container ;
  1530. var className = this.getClassName();
  1531. if( selectValue && selectText ){
  1532. value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
  1533. value = value.join(",");
  1534. }
  1535. item = new Element( "span", {
  1536. "name" : name,
  1537. "text" : value
  1538. });
  1539. item.set( attr );
  1540. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1541. if( this.options.clazz )item.addClass( this.options.clazz );
  1542. item.setStyles( styles );
  1543. if(parent)item.inject(parent);
  1544. this.items.push( item );
  1545. },
  1546. get : function( vort ){
  1547. if( this.options.disable ){
  1548. return ( vort == "value" || vort == "text" ) ? null : {
  1549. value : null,
  1550. text : null
  1551. };
  1552. }
  1553. var value;
  1554. var text;
  1555. var items;
  1556. var name = this.options.name;
  1557. items = this.mElement.getElements("[name='"+name+"']");
  1558. if( this.options.isEdited ){
  1559. value = [];
  1560. text = [];
  1561. items.each(function( el ){
  1562. if( el.checked ){
  1563. value.push(el.get("value"));
  1564. text.push( el.getParent().get("text").trim() )
  1565. }
  1566. });
  1567. }else{
  1568. text = items[0].get("text");
  1569. if( this.options.selectValue && this.options.selectText ){
  1570. value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue, this.valSeparator );
  1571. }else{
  1572. value = text;
  1573. }
  1574. }
  1575. if( !value )value="";
  1576. if( !text )text = value;
  1577. if( vort == "value" )return value;
  1578. if( vort == "text")return text;
  1579. var result = {};
  1580. result.value = value;
  1581. result.text = text;
  1582. return result;
  1583. },
  1584. setValue : function( value ){
  1585. if( this.options.disable ){
  1586. return;
  1587. }
  1588. var items= this.mElement.getElements("[name='"+ this.options.name + "']");
  1589. if( this.options.isEdited ){
  1590. var values = typeOf( value ) == "array" ? value : value.split("^^");
  1591. items.each(function( el ){
  1592. if( values.contains( el.get("value") ) ){
  1593. el.checked = true;
  1594. }else{
  1595. el.checked = false;
  1596. }
  1597. });
  1598. }else{
  1599. value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
  1600. value = value.join(",");
  1601. items[0].set("text", value );
  1602. }
  1603. },
  1604. getErrorText : function(){
  1605. return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
  1606. },
  1607. getClassName : function(){
  1608. var tType = this.options.tType;
  1609. var className = null ;
  1610. if( this.options.className == "none" ){
  1611. }else if( this.options.className != "") {
  1612. className = this.options.className
  1613. }else if( !this.options.isEdited ){
  1614. }else {
  1615. className = "inputCheckbox"
  1616. }
  1617. return className;
  1618. }
  1619. });
  1620. MDomItem.Select = new Class({
  1621. initialize: function ( module ) {
  1622. this.module = module;
  1623. this.options = module.options;
  1624. this.css = module.css;
  1625. this.app = module.app;
  1626. this.items = module.items;
  1627. this.container = this.mElement = module.container;
  1628. this.valSeparator = module.valSeparator;
  1629. },
  1630. load : function(){
  1631. if( !this.options.selectValue && this.options.selectText )this.options.selectValue = this.options.selectText;
  1632. if( !this.options.selectText && this.options.selectValue )this.options.selectText = this.options.selectValue;
  1633. if( this.options.disable )return;
  1634. if( this.options.isEdited ){
  1635. this.loadEdit();
  1636. }else{
  1637. this.loadRead();
  1638. }
  1639. },
  1640. loadEdit : function(){
  1641. var item;
  1642. var name = this.options.name;
  1643. var value ;
  1644. if( typeOf( this.options.value ) === "boolean" ){
  1645. value = this.options.value.toString();
  1646. }else{
  1647. value = this.options.value || this.options.defaultValue
  1648. }
  1649. var selectValue = this.options.selectValue || this.options.selectText;
  1650. var selectText = this.options.selectText || this.options.selectValue ;
  1651. var event = this.options.event;
  1652. var styles = this.options.style || {};
  1653. var attr = this.options.attr || {};
  1654. var parent = this.container ;
  1655. var className = this.getClassName() ;
  1656. item = new Element( "select" , {
  1657. "name" : name
  1658. });
  1659. item.set( attr );
  1660. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1661. item.setStyles( styles );
  1662. if( this.options.clazz )item.addClass( this.options.clazz );
  1663. var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( this.valSeparator );
  1664. var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split(this.valSeparator);
  1665. for( i=0;i<selectValues.length;i++){
  1666. new Element("option" , {
  1667. "value" : selectValues[i],
  1668. "selected" : selectValues[i] == value,
  1669. "text" : selectTexts[i]
  1670. }).inject(item)
  1671. }
  1672. if( this.options.validImmediately ){
  1673. item.addEvent("change", function(){ this.module.verify( true ); }.bind(this))
  1674. }
  1675. MDomItem.Util.bindEvent( this, item, event);
  1676. if(parent)item.inject(parent);
  1677. this.items.push( item );
  1678. },
  1679. loadRead : function(){
  1680. var item;
  1681. var name = this.options.name;
  1682. var value ;
  1683. if( typeOf( this.options.value ) === "boolean" ){
  1684. value = this.options.value.toString();
  1685. }else{
  1686. value = this.options.value || this.options.defaultValue
  1687. }
  1688. var selectValue = this.options.selectValue || this.options.selectText;
  1689. var selectText = this.options.selectText || this.options.selectValue ;
  1690. var styles = this.options.style || {};
  1691. var attr = this.options.attr || {};
  1692. var parent = this.mElement = this.container ;
  1693. var className = this.getClassName();
  1694. if( selectValue && selectText ){
  1695. value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
  1696. value = value.join(",");
  1697. }
  1698. item = new Element( "span", {
  1699. "name" : name,
  1700. "text" : value
  1701. });
  1702. item.set( attr );
  1703. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1704. if( this.options.clazz )item.addClass( this.options.clazz );
  1705. item.setStyles( styles );
  1706. if(parent)item.inject(parent);
  1707. this.items.push( item );
  1708. },
  1709. get : function( vort ){
  1710. if( this.options.disable ){
  1711. return ( vort == "value" || vort == "text" ) ? null : {
  1712. value : null,
  1713. text : null
  1714. };
  1715. }
  1716. var value;
  1717. var text;
  1718. var items;
  1719. var name = this.options.name;
  1720. items = this.mElement.getElements("[name='"+name+"']");
  1721. if( this.options.isEdited ){
  1722. items[0].getElements("option").each(function(el){
  1723. if( el.selected ){
  1724. value = el.get("value");
  1725. text = el.get("text").trim();
  1726. }
  1727. });
  1728. }else{
  1729. text = items[0].get("text");
  1730. if( this.options.selectValue && this.options.selectText ){
  1731. value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator).join();
  1732. }else{
  1733. value = text;
  1734. }
  1735. }
  1736. if( !value )value="";
  1737. if( !text )text = value;
  1738. if( vort == "value" )return value;
  1739. if( vort == "text")return text;
  1740. var result = {};
  1741. result.value = value;
  1742. result.text = text;
  1743. return result;
  1744. },
  1745. setValue : function( value ){
  1746. if( this.options.disable ){
  1747. return;
  1748. }
  1749. var items= this.mElement.getElements("[name='"+ this.options.name + "']");
  1750. if( this.options.isEdited ){
  1751. items[0].getElements("option").each(function( el ){
  1752. if( el.get("value") == value ) el.selected = true;
  1753. });
  1754. }else{
  1755. value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
  1756. value = value.join(",");
  1757. items[0].set("text", value );
  1758. }
  1759. },
  1760. getErrorText : function(){
  1761. return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
  1762. },
  1763. getClassName : function(){
  1764. var tType = this.options.tType;
  1765. var className = null ;
  1766. if( this.options.className == "none" ){
  1767. }else if( this.options.className != "") {
  1768. className = this.options.className
  1769. }else if( !this.options.isEdited ){
  1770. }else {
  1771. className = "inputSelect"
  1772. }
  1773. return className;
  1774. }
  1775. });
  1776. MDomItem.Multiselect = new Class({
  1777. initialize: function ( module ) {
  1778. this.module = module;
  1779. this.options = module.options;
  1780. this.css = module.css;
  1781. this.app = module.app;
  1782. this.items = module.items;
  1783. this.container = this.mElement = module.container;
  1784. this.valSeparator = module.valSeparator;
  1785. },
  1786. load : function(){
  1787. if( !this.options.selectValue && this.options.selectText )this.options.selectValue = this.options.selectText;
  1788. if( !this.options.selectText && this.options.selectValue )this.options.selectText = this.options.selectValue;
  1789. if( this.options.disable )return;
  1790. if( this.options.isEdited ){
  1791. this.loadEdit();
  1792. }else{
  1793. this.loadRead();
  1794. }
  1795. },
  1796. loadEdit : function(){
  1797. var item;
  1798. var values;
  1799. var name = this.options.name;
  1800. var value ;
  1801. if( typeOf( this.options.value ) === "boolean" ){
  1802. value = this.options.value.toString();
  1803. }else{
  1804. value = this.options.value || this.options.defaultValue
  1805. }
  1806. var selectValue = this.options.selectValue || this.options.selectText;
  1807. var selectText = this.options.selectText || this.options.selectValue ;
  1808. var event = this.options.event;
  1809. var styles = this.options.style || {};
  1810. var attr = this.options.attr || {};
  1811. var parent = this.container ;
  1812. var className = this.getClassName() ;
  1813. values = typeOf( value ) == "string" ? value.split(this.valSeparator) : value ;
  1814. values = typeOf( value ) == "array" ? value : [value];
  1815. item = new Element( "select" , {
  1816. "name" : name,
  1817. "multiple" : true
  1818. });
  1819. item.set( attr );
  1820. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1821. if( this.options.clazz )item.addClass( this.options.clazz );
  1822. item.setStyles( styles );
  1823. var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( this.valSeparator );
  1824. var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split(this.valSeparator);
  1825. for( i=0;i<selectValues.length;i++){
  1826. new Element("option" , {
  1827. "value" : selectValues[i],
  1828. "selected" : values.contains( selectValues[i] ),
  1829. "text" : selectTexts[i]
  1830. }).inject(item)
  1831. }
  1832. if( this.options.validImmediately ){
  1833. item.addEvent("change", function(){ this.module.verify( true ); }.bind(this))
  1834. }
  1835. MDomItem.Util.bindEvent( this, item, event);
  1836. if(parent)item.inject(parent);
  1837. this.items.push( item );
  1838. },
  1839. loadRead : function(){
  1840. var item;
  1841. var name = this.options.name;
  1842. var value ;
  1843. if( typeOf( this.options.value ) === "boolean" ){
  1844. value = this.options.value.toString();
  1845. }else{
  1846. value = this.options.value || this.options.defaultValue
  1847. }
  1848. var selectValue = this.options.selectValue || this.options.selectText;
  1849. var selectText = this.options.selectText || this.options.selectValue ;
  1850. var styles = this.options.style || {};
  1851. var attr = this.options.attr || {};
  1852. var parent = this.container ;
  1853. var className = this.getClassName();
  1854. if( selectValue && selectText ){
  1855. value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
  1856. value = value.join(",");
  1857. }
  1858. item = new Element( "span", {
  1859. "name" : name,
  1860. "text" : value
  1861. });
  1862. item.set( attr );
  1863. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1864. item.setStyles( styles );
  1865. if( this.options.clazz )item.addClass( this.options.clazz );
  1866. if(parent)item.inject(parent);
  1867. this.items.push( item );
  1868. },
  1869. get : function( vort ){
  1870. if( this.options.disable ){
  1871. return ( vort == "value" || vort == "text" ) ? null : {
  1872. value : null,
  1873. text : null
  1874. };
  1875. }
  1876. var value;
  1877. var text;
  1878. var items;
  1879. var name = this.options.name;
  1880. items = this.mElement.getElements("[name='"+name+"']");
  1881. if( this.options.isEdited ){
  1882. value = [];
  1883. text = [];
  1884. items[0].getElements("option").each(function(el){
  1885. if( el.selected ){
  1886. value.push( el.get("value") );
  1887. text.push( el.get("text").trim() );
  1888. }
  1889. });
  1890. }else{
  1891. text = items[0].get("text");
  1892. if( this.options.selectValue && this.options.selectText ){
  1893. value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator );
  1894. }else{
  1895. value = text;
  1896. }
  1897. }
  1898. if( !value )value="";
  1899. if( !text )text = value;
  1900. if( vort == "value" )return value;
  1901. if( vort == "text")return text;
  1902. var result = {};
  1903. result.value = value;
  1904. result.text = text;
  1905. return result;
  1906. },
  1907. setValue : function( value ){
  1908. if( this.options.disable ){
  1909. return;
  1910. }
  1911. var items= this.mElement.getElements("[name='"+ this.options.name + "']");
  1912. if( this.options.isEdited ){
  1913. var values = typeOf( value ) == "array" ? value : value.split("^^");
  1914. items[0].getElements("option").each(function( el ){
  1915. if( values.contains( el.get("value") ) ){
  1916. el.selected = true;
  1917. }else{
  1918. el.selected = false;
  1919. }
  1920. })
  1921. }else{
  1922. value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
  1923. value = value.join(",");
  1924. items[0].set("text", value );
  1925. }
  1926. },
  1927. getErrorText : function(){
  1928. return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
  1929. },
  1930. getClassName : function(){
  1931. var tType = this.options.tType;
  1932. var className = null ;
  1933. if( this.options.className == "none" ){
  1934. }else if( this.options.className != "") {
  1935. className = this.options.className
  1936. }else if( !this.options.isEdited ){
  1937. }else {
  1938. className = "inputMultiselect"
  1939. }
  1940. return className;
  1941. }
  1942. });
  1943. MDomItem.Innertext = new Class({
  1944. initialize: function ( module ) {
  1945. this.module = module;
  1946. this.options = module.options;
  1947. this.css = module.css;
  1948. this.app = module.app;
  1949. this.items = module.items;
  1950. this.container = this.mElement = module.container;
  1951. this.valSeparator = module.valSeparator;
  1952. },
  1953. load : function(){
  1954. if( this.options.disable )return;
  1955. var item;
  1956. var name = this.options.name;
  1957. var value ;
  1958. if( typeOf( this.options.value ) === "boolean" ){
  1959. value = this.options.value.toString();
  1960. }else{
  1961. value = this.options.value || this.options.defaultValue
  1962. }
  1963. var selectValue = this.options.selectValue || this.options.selectText;
  1964. var selectText = this.options.selectText || this.options.selectValue ;
  1965. var styles = this.options.style || {};
  1966. var attr = this.options.attr || {};
  1967. var parent = this.mElement = this.container ;
  1968. var className = this.getClassName();
  1969. if( selectValue && selectText ){
  1970. value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
  1971. value = value.join(",");
  1972. }
  1973. item = new Element( "span", {
  1974. "name" : name,
  1975. "text" : value
  1976. });
  1977. item.set( attr );
  1978. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  1979. if( this.options.clazz )item.addClass( this.options.clazz );
  1980. item.setStyles( styles );
  1981. if( this.options.isEdited ){
  1982. MDomItem.Util.bindEvent( this, item, this.options.event);
  1983. }
  1984. if(parent)item.inject(parent);
  1985. this.items.push( item );
  1986. },
  1987. get : function( vort ){
  1988. if( this.options.disable ){
  1989. return ( vort == "value" || vort == "text" ) ? null : {
  1990. value : null,
  1991. text : null
  1992. };
  1993. }
  1994. var value;
  1995. var text;
  1996. var name = this.options.name;
  1997. var item = this.mElement.getElement("[name='"+name+"']");
  1998. text = item.get("text");
  1999. if( this.options.selectValue && this.options.selectText ){
  2000. value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator);
  2001. }else{
  2002. value = text;
  2003. }
  2004. if( !value )value="";
  2005. if( !text )text = value;
  2006. if( vort == "value" )return value;
  2007. if( vort == "text")return text;
  2008. var result = {};
  2009. result.value = value;
  2010. result.text = text;
  2011. return result;
  2012. },
  2013. setValue : function( value ){
  2014. if( this.options.disable ){
  2015. return;
  2016. }
  2017. value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
  2018. value = value.join(",");
  2019. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  2020. item.set("text", value );
  2021. },
  2022. getErrorText : function(){
  2023. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  2024. },
  2025. getClassName : function(){
  2026. var tType = this.options.tType;
  2027. var className = null ;
  2028. if( this.options.className == "none" ){
  2029. }else if( this.options.className != "") {
  2030. className = this.options.className
  2031. }else if( !this.options.isEdited ){
  2032. }else {
  2033. }
  2034. return className;
  2035. }
  2036. });
  2037. MDomItem.Innerhtml = new Class({
  2038. initialize: function ( module ) {
  2039. this.module = module;
  2040. this.options = module.options;
  2041. this.css = module.css;
  2042. this.app = module.app;
  2043. this.items = module.items;
  2044. this.container = this.mElement = module.container;
  2045. this.valSeparator = module.valSeparator;
  2046. },
  2047. load : function(){
  2048. if( this.options.disable )return;
  2049. var item;
  2050. var name = this.options.name;
  2051. var value ;
  2052. if( typeOf( this.options.value ) === "boolean" ){
  2053. value = this.options.value.toString();
  2054. }else{
  2055. value = this.options.value || this.options.defaultValue
  2056. }
  2057. var selectValue = this.options.selectValue || this.options.selectText;
  2058. var selectText = this.options.selectText || this.options.selectValue ;
  2059. var styles = this.options.style || {};
  2060. var attr = this.options.attr || {};
  2061. var parent = this.mElement = this.container ;
  2062. var className = this.getClassName();
  2063. if( selectValue && selectText ){
  2064. value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
  2065. value = value.join(",");
  2066. }
  2067. item = new Element( "span", {
  2068. "name" : name,
  2069. "html" : value
  2070. });
  2071. item.set( attr );
  2072. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  2073. if( this.options.clazz )item.addClass( this.options.clazz );
  2074. item.setStyles( styles );
  2075. if( this.options.isEdited ){
  2076. MDomItem.Util.bindEvent( this, item, this.options.event);
  2077. }
  2078. if(parent)item.inject(parent);
  2079. this.items.push( item );
  2080. },
  2081. get : function( vort ){
  2082. if( this.options.disable ){
  2083. return ( vort == "value" || vort == "text" ) ? null : {
  2084. value : null,
  2085. text : null
  2086. };
  2087. }
  2088. var value;
  2089. var text;
  2090. var name = this.options.name;
  2091. var item = this.mElement.getElement("[name='"+name+"']");
  2092. text = item.get("html");
  2093. if( this.options.selectValue && this.options.selectText ){
  2094. value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator );
  2095. }else{
  2096. value = text;
  2097. }
  2098. if( !value )value="";
  2099. if( !text )text = value;
  2100. if( vort == "value" )return value;
  2101. if( vort == "text")return text;
  2102. var result = {};
  2103. result.value = value;
  2104. result.text = text;
  2105. return result;
  2106. },
  2107. setValue : function( value ){
  2108. if( this.options.disable ){
  2109. return;
  2110. }
  2111. value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
  2112. value = value.join(",");
  2113. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  2114. item.set("html", value );
  2115. },
  2116. getErrorText : function(){
  2117. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  2118. },
  2119. getClassName : function(){
  2120. var tType = this.options.tType;
  2121. var className = null ;
  2122. if( this.options.className == "none" ){
  2123. }else if( this.options.className != "") {
  2124. className = this.options.className
  2125. }else if( !this.options.isEdited ){
  2126. }else {
  2127. }
  2128. return className;
  2129. }
  2130. });
  2131. MDomItem.Img = new Class({
  2132. initialize: function ( module ) {
  2133. this.module = module;
  2134. this.options = module.options;
  2135. this.css = module.css;
  2136. this.items = module.items;
  2137. this.container = this.mElement = module.container;
  2138. },
  2139. load : function(){
  2140. if( this.options.disable )return;
  2141. var item;
  2142. var name = this.options.name;
  2143. var value = this.options.value || this.options.defaultValue ;
  2144. var event = this.options.event;
  2145. var styles = this.options.style || {};
  2146. var attr = this.options.attr || {};
  2147. var parent = this.container ;
  2148. var className = this.getClassName();
  2149. item = new Element( "img", {
  2150. "name" : name,
  2151. "src" : value
  2152. });
  2153. item.set( attr );
  2154. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  2155. item.setStyles( styles );
  2156. if( this.options.clazz )item.addClass( this.options.clazz );
  2157. MDomItem.Util.bindEvent( this, item, event);
  2158. if(parent)item.inject(parent);
  2159. this.items.push( item );
  2160. },
  2161. get : function( vort ){
  2162. if( this.options.disable ){
  2163. return ( vort == "value" || vort == "text" ) ? null : {
  2164. value : null,
  2165. text : null
  2166. };
  2167. }
  2168. var value;
  2169. var text;
  2170. var name = this.options.name;
  2171. var item = this.mElement.getElement("[name='"+name+"']");
  2172. value = item.get("src");
  2173. if( !value )value="";
  2174. if( !text )text = value;
  2175. if( vort == "value" )return value;
  2176. if( vort == "text")return text;
  2177. var result = {};
  2178. result.value = value;
  2179. result.text = text;
  2180. return result;
  2181. },
  2182. setValue : function( value ){
  2183. if( this.options.disable ){
  2184. return;
  2185. }
  2186. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  2187. item.set("src",value);
  2188. },
  2189. getErrorText : function(){
  2190. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  2191. },
  2192. getClassName : function(){
  2193. var tType = this.options.tType;
  2194. var className = null ;
  2195. if( this.options.className == "none" ){
  2196. }else if( this.options.className != "") {
  2197. className = this.options.className
  2198. }else if( !this.options.isEdited ){
  2199. }else {
  2200. }
  2201. return className;
  2202. }
  2203. });
  2204. MDomItem.Button = new Class({
  2205. initialize: function ( module ) {
  2206. this.module = module;
  2207. this.options = module.options;
  2208. this.css = module.css;
  2209. this.items = module.items;
  2210. this.container = this.mElement = module.container;
  2211. },
  2212. load : function(){
  2213. if( this.options.disable )return;
  2214. var item;
  2215. var name = this.options.name;
  2216. var value ;
  2217. if( typeOf( this.options.value ) === "boolean" ){
  2218. value = this.options.value.toString();
  2219. }else{
  2220. value = this.options.value || this.options.defaultValue
  2221. }
  2222. var event = this.options.event;
  2223. var styles = this.options.style || {};
  2224. var attr = this.options.attr || {};
  2225. var parent = this.container ;
  2226. var className = this.getClassName() ;
  2227. item = new Element( "button", {
  2228. "type" : "button",
  2229. "name" : name,
  2230. "value" : value,
  2231. "text" : value
  2232. });
  2233. item.set( attr );
  2234. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  2235. item.setStyles( styles );
  2236. if( this.options.clazz )item.addClass( this.options.clazz );
  2237. MDomItem.Util.bindEvent( this, item, event);
  2238. if(parent)item.inject(parent);
  2239. this.items.push( item );
  2240. },
  2241. get : function( vort ){
  2242. if( this.options.disable ){
  2243. return ( vort == "value" || vort == "text" ) ? null : {
  2244. value : null,
  2245. text : null
  2246. };
  2247. }
  2248. var value;
  2249. var text;
  2250. var name = this.options.name;
  2251. var item = this.mElement.getElement("[name='"+name+"']");
  2252. value = item.get("value");
  2253. if( !value )value="";
  2254. if( !text )text = value;
  2255. if( vort == "value" )return value;
  2256. if( vort == "text")return text;
  2257. var result = {};
  2258. result.value = value;
  2259. result.text = text;
  2260. return result;
  2261. },
  2262. setValue : function( value ){
  2263. if( this.options.disable ){
  2264. return;
  2265. }
  2266. var item= this.mElement.getElement("[name='"+ this.options.name + "']");
  2267. item.set( "value", value );
  2268. },
  2269. getErrorText : function(){
  2270. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  2271. },
  2272. getClassName : function(){
  2273. var className = null ;
  2274. if( this.options.className == "none" ){
  2275. }else if( this.options.className != "") {
  2276. className = this.options.className
  2277. }else if( !this.options.isEdited ){
  2278. }else {
  2279. className = "inputButton"
  2280. }
  2281. return className;
  2282. }
  2283. });
  2284. MDomItem.A = new Class({
  2285. initialize: function ( module ) {
  2286. this.module = module;
  2287. this.options = module.options;
  2288. this.css = module.css;
  2289. this.items = module.items;
  2290. this.container = this.mElement = module.container;
  2291. },
  2292. load : function(){
  2293. if( this.options.disable )return;
  2294. var item;
  2295. var name = this.options.name;
  2296. var value ;
  2297. if( typeOf( this.options.value ) === "boolean" ){
  2298. value = this.options.value.toString();
  2299. }else{
  2300. value = this.options.value || this.options.defaultValue
  2301. }
  2302. var event = this.options.event;
  2303. var styles = this.options.style || {};
  2304. var attr = this.options.attr || {};
  2305. var parent = this.container ;
  2306. var className = this.getClassName() ;
  2307. item = new Element( "a", {
  2308. "name" : name,
  2309. "value" : value,
  2310. "text" : value
  2311. });
  2312. item.set( attr );
  2313. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  2314. item.setStyles( styles );
  2315. if( this.options.clazz )item.addClass( this.options.clazz );
  2316. MDomItem.Util.bindEvent( this, item, event);
  2317. if(parent)item.inject(parent);
  2318. this.items.push( item );
  2319. },
  2320. get : function( vort ){
  2321. if( this.options.disable ){
  2322. return ( vort == "value" || vort == "text" ) ? null : {
  2323. value : null,
  2324. text : null
  2325. };
  2326. }
  2327. var value;
  2328. var text;
  2329. var name = this.options.name;
  2330. var item = this.mElement.getElement("[name='"+name+"']");
  2331. value = item.get("value");
  2332. if( !value )value="";
  2333. if( !text )text = value;
  2334. if( vort == "value" )return value;
  2335. if( vort == "text")return text;
  2336. var result = {};
  2337. result.value = value;
  2338. result.text = text;
  2339. return result;
  2340. },
  2341. setValue : function( value ){
  2342. if( this.options.disable ){
  2343. return;
  2344. }
  2345. var item= this.mElement.getElement("[name='"+ this.options.name + "']");
  2346. item.set( "value", value );
  2347. },
  2348. getErrorText : function(){
  2349. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  2350. },
  2351. getClassName : function(){
  2352. var className = null ;
  2353. if( this.options.className == "none" ){
  2354. }else if( this.options.className != "") {
  2355. className = this.options.className
  2356. }else if( !this.options.isEdited ){
  2357. }else {
  2358. className = "inputA"
  2359. }
  2360. return className;
  2361. }
  2362. });
  2363. MDomItem.MSelector = new Class({
  2364. initialize: function ( module ) {
  2365. this.module = module;
  2366. this.options = module.options;
  2367. this.css = module.css;
  2368. this.app = module.app;
  2369. this.items = module.items;
  2370. this.container = this.mElement = module.container;
  2371. this.valSeparator = module.valSeparator;
  2372. },
  2373. load : function(){
  2374. if( this.options.disable )return;
  2375. MWF.xDesktop.requireApp("Template", "MSelector",null,false);
  2376. var value ;
  2377. if( typeOf( this.options.value ) === "boolean" ){
  2378. value = this.options.value.toString();
  2379. }else{
  2380. value = this.options.value || this.options.defaultValue
  2381. }
  2382. var selectValue = this.options.selectValue || this.options.selectText;
  2383. var selectText = this.options.selectText || this.options.selectValue ;
  2384. this.mSelectorOptions = {
  2385. "style": "default",
  2386. "width": "230px",
  2387. "height": "30px",
  2388. "defaultOptionLp" : MWF.xApplication.Template.LP.MDomItem.defaultOption,
  2389. "trigger" : "delay", //immediately
  2390. "isSetSelectedValue" : true,
  2391. "inputEnable" : false,
  2392. "isCreateReadNode" : false, //适应给MDomItem的做法
  2393. "textField" : "",
  2394. "valueField" : "",
  2395. "value" : value,
  2396. "text" : "",
  2397. "defaultVaue" : this.options.defaultValue,
  2398. "selectValue" : selectValue,
  2399. "selectText" : selectText,
  2400. "isEdited" : this.options.isEdited
  2401. //"onSelectItem" : function( itemNode, itemData ){}.bind(this)
  2402. //"onLoadData" :function( callback ){}.bind(this)
  2403. };
  2404. if( this.options.mSelectorOptions ){
  2405. this.mSelectorOptions = Object.merge( this.mSelectorOptions, this.options.mSelectorOptions );
  2406. }
  2407. this.mSelectorOptions.value = value;
  2408. if( !this.options.isEdited ){
  2409. var name = this.options.name;
  2410. var item;
  2411. var attr = this.options.attr || {};
  2412. var className = this.getClassName();
  2413. var styles = this.options.style || {};
  2414. var parent = this.container;
  2415. this.mSelectorOptions.onLoadReadNode = function( text ){
  2416. if( this.items.length > 0 ){
  2417. parent.empty();
  2418. }
  2419. item = new Element( "span", {
  2420. "name" : name,
  2421. "text" : text
  2422. });
  2423. item.set( attr );
  2424. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  2425. item.setStyles( styles );
  2426. if( this.options.clazz )item.addClass( this.options.clazz );
  2427. if(parent)item.inject(parent);
  2428. this.items.push( item );
  2429. }.bind(this);
  2430. }
  2431. this.mSelector = new MSelector(this.container, this.mSelectorOptions , this.app , this.css);
  2432. this.mSelector.load();
  2433. },
  2434. get : function( vort ){
  2435. if( this.options.disable ){
  2436. return ( vort == "value" || vort == "text" ) ? null : {
  2437. value : null,
  2438. text : null
  2439. };
  2440. }
  2441. if( vort == "value" )return this.mSelector.getValue();
  2442. if( vort == "text")return this.mSelector.getText();
  2443. return this.mSelector.get();
  2444. },
  2445. setValue : function( value ){
  2446. this.mSelector.setValue( value );
  2447. },
  2448. getErrorText : function(){
  2449. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  2450. },
  2451. getClassName : function(){
  2452. var className = null ;
  2453. if( this.options.className == "none" ){
  2454. }else if( this.options.className != "") {
  2455. className = this.options.className
  2456. }else if( !this.options.isEdited ){
  2457. }else {
  2458. }
  2459. return className;
  2460. }
  2461. });
  2462. MDomItem.ImageClipper = new Class({
  2463. initialize: function ( module ) {
  2464. this.module = module;
  2465. this.options = module.options;
  2466. this.css = module.css;
  2467. this.app = module.app;
  2468. this.items = module.items;
  2469. this.container = this.mElement = module.container;
  2470. this.valSeparator = module.valSeparator;
  2471. },
  2472. load : function(){
  2473. if( this.options.disable )return;
  2474. if( this.options.isEdited ){
  2475. this.loadEdit();
  2476. }else{
  2477. this.loadRead();
  2478. }
  2479. },
  2480. loadEdit : function(){
  2481. var item;
  2482. var values;
  2483. var name = this.options.name;
  2484. var value ;
  2485. if( typeOf( this.options.value ) === "boolean" ){
  2486. value = this.options.value.toString();
  2487. }else{
  2488. value = this.options.value || this.options.defaultValue
  2489. }
  2490. var styles = this.options.style || {};
  2491. var parent = this.container ;
  2492. this.imageId = this.module.imageId = value;
  2493. if( value && parent ){
  2494. if( styles.imageWrapStyle ){
  2495. this.imageWrap = new Element("div", { styles : styles.imageWrapStyle}).inject( parent )
  2496. }
  2497. this.image = new Element("img", {
  2498. "src" : MWF.xDesktop.getImageSrc( value )
  2499. }).inject( this.imageWrap || parent );
  2500. this.image.addEvent("click",function(){
  2501. window.open( o2.filterUrl(MWF.xDesktop.getImageSrc( this.imageId )), "_blank" );
  2502. }.bind(this));
  2503. if( styles.imageStyle )this.image.setStyles( styles.imageStyle );
  2504. }
  2505. var action = new Element("button",{
  2506. "text" : MWF.xApplication.Template.LP.MDomItem.setPicture
  2507. }).inject( parent );
  2508. //if( this.css && this.css["inputButton"] )action.setStyles( this.css["inputButton"] );
  2509. if( styles.actionStyle )action.setStyles( styles.actionStyle );
  2510. action.addEvents({
  2511. "click": function(){
  2512. MWF.xDesktop.requireApp("Template", "widget.ImageClipper",null,false);
  2513. this.clipper = new MWF.xApplication.Template.widget.ImageClipper(this.app, {
  2514. "imageUrl": value ? MWF.xDesktop.getImageSrc( value ) : "",
  2515. "aspectRatio": this.options.aspectRatio || 0,
  2516. "ratioAdjustedEnable" : this.options.ratioAdjustedEnable || false,
  2517. "reference": this.options.reference,
  2518. "referenceType": this.options.referenceType,
  2519. "onChange": function () {
  2520. if( this.image )this.image.destroy();
  2521. if(this.imageWrap)this.imageWrap.destroy();
  2522. if( styles.imageWrapStyle ){
  2523. this.imageWrap = new Element("div", { styles : styles.imageWrapStyle}).inject( parent, "top" )
  2524. }
  2525. this.image = new Element("img", {
  2526. "src" : this.clipper.imageSrc
  2527. }).inject( this.imageWrap || parent, "top" );
  2528. if( styles.imageStyle )this.image.setStyles( styles.imageStyle );
  2529. this.image.addEvent("click",function(){
  2530. window.open( o2.filterUrl(MWF.xDesktop.getImageSrc( this.imageId )), "_blank" );
  2531. }.bind(this));
  2532. this.imageId = this.module.imageId = this.clipper.imageId;
  2533. if( this.options.validImmediately ){
  2534. this.module.verify( true )
  2535. }
  2536. }.bind(this)
  2537. });
  2538. this.clipper.load();
  2539. }.bind(this)
  2540. });
  2541. },
  2542. loadRead : function(){
  2543. var value = this.options.value || this.options.defaultValue ;
  2544. var parent = this.container ;
  2545. this.imageId = this.module.imageId = value;
  2546. if( value && parent ){
  2547. this.image = new Element("img", {
  2548. "src" : MWF.xDesktop.getImageSrc( value )
  2549. }).inject( parent );
  2550. var styles = this.options.style || {};
  2551. if( styles.imageStyle )this.image.setStyles( styles.imageStyle );
  2552. }
  2553. },
  2554. get : function( vort ){
  2555. if( this.options.disable ){
  2556. return ( vort == "value" || vort == "text" ) ? null : {
  2557. value : null,
  2558. text : null
  2559. };
  2560. }
  2561. var items;
  2562. var value = this.imageId;
  2563. if( vort == "value" )return value;
  2564. if( vort == "text")return value;
  2565. var result = {};
  2566. result.value = value;
  2567. result.text = value;
  2568. return result;
  2569. },
  2570. setValue : function( value ){
  2571. if( this.options.disable ){
  2572. return;
  2573. }
  2574. var styles = this.options.style || {};
  2575. this.imageId = this.module.imageId = value;
  2576. if( value ){
  2577. if( this.image ){
  2578. this.image.set("src", MWF.xDesktop.getImageSrc( value ))
  2579. }else{
  2580. if( styles.imageWrapStyle ){
  2581. this.imageWrap = new Element("div", { styles : styles.imageWrapStyle}).inject( this.container )
  2582. }
  2583. this.image = new Element("img", {
  2584. "src" : MWF.xDesktop.getImageSrc( value )
  2585. }).inject( this.imageWrap || this.container );
  2586. if( styles.imageStyle )this.image.setStyles( styles.imageStyle );
  2587. }
  2588. }
  2589. },
  2590. getErrorText : function(){
  2591. return MWF.xApplication.Template.LP.MDomItem.uploadPictureNotice+":"+this.options.text ;
  2592. }
  2593. });
  2594. MDomItem.Rtf = new Class({
  2595. initialize: function ( module ) {
  2596. this.module = module;
  2597. this.options = module.options;
  2598. this.css = module.css;
  2599. this.app = module.app;
  2600. this.items = module.items;
  2601. this.container = this.mElement = module.container;
  2602. this.valSeparator = module.valSeparator;
  2603. },
  2604. load : function(){
  2605. if( this.options.disable )return;
  2606. if( this.options.isEdited ){
  2607. this.loadEdit();
  2608. }else{
  2609. this.loadRead();
  2610. }
  2611. },
  2612. loadEdit : function(){
  2613. var _self = this;
  2614. var item;
  2615. var name = this.options.name;
  2616. var value = this.options.value || this.options.defaultValue ;
  2617. var attr = this.options.attr || {};
  2618. var parent = this.container ;
  2619. window.COMMON.AjaxModule.load("ckeditor", function(){
  2620. CKEDITOR.disableAutoInline = true;
  2621. var item = new Element("div",{
  2622. "name" : name,
  2623. "id" : name
  2624. });
  2625. item.set( attr );
  2626. if(parent)item.inject(parent);
  2627. if( value )item.set("html", value);
  2628. var editorConfig = {
  2629. //"autoGrow_maxHeight": 400,
  2630. //"autoGrow_minHeight": 300,
  2631. "resize_enabled": true,
  2632. //"resize_maxHeight": "3000",
  2633. //"resize_minHeight": "200",
  2634. "autoParagraph": true,
  2635. "autoUpdateElement": true,
  2636. "enterMode": 1,
  2637. //"height": "200",
  2638. //"width": "",
  2639. "readOnly": false,
  2640. "language": MWF.language || "zh-cn",
  2641. "enablePreview": true,
  2642. "removePlugins": ['image','easyimage','exportpdf','cloudservices'],
  2643. "extraPlugins": [ 'lineheight','o2image','o2uploadimage','o2uploadremoteimage']
  2644. // "extraAllowedContent " : "img[onerror,data-id]"
  2645. };
  2646. if( this.options.RTFConfig ){
  2647. editorConfig = Object.merge( editorConfig, this.options.RTFConfig )
  2648. }
  2649. if( editorConfig.skin )editorConfig.skin = "moono-lisa";
  2650. if( !editorConfig.filebrowserFilesImage && !editorConfig.cloudFileDisable ){
  2651. editorConfig.filebrowserFilesImage = function( e, callback ){
  2652. MWF.xDesktop.requireApp("File", "FileSelector", function(){
  2653. _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  2654. "style" : "default",
  2655. "title": MWF.xApplication.Template.LP.MDomItem.selectCoundPicture,
  2656. "toBase64" : true,
  2657. "listStyle": "preview",
  2658. "selectType" : "images",
  2659. "onPostSelectAttachment" : function(url, base64File){
  2660. if(callback)callback(url, base64File);
  2661. }
  2662. });
  2663. _self.selector_cloud.load();
  2664. }, true);
  2665. }
  2666. }
  2667. this.editor = this.module.editor = CKEDITOR.replace(item, editorConfig);
  2668. var imgSrc = MWF.xDesktop.getImageSrc();
  2669. var imgHost = imgSrc.split("/x_file_assemble_control/")[0];
  2670. debugger;
  2671. this.editor.on("instanceReady", function(e){
  2672. debugger;
  2673. var editable = e.editor.editable && e.editor.editable();
  2674. if(!editable)return;
  2675. var imgs = editable.find("img");
  2676. for( var i=0; i<imgs.count(); i++ ){
  2677. var img = imgs.getItem(i);
  2678. var src = img.getAttribute("src");
  2679. if( src && src.indexOf("/x_file_assemble_control/") > -1 ){
  2680. if( imgHost !== src.split("/x_file_assemble_control/")[0] ){
  2681. var id = img.getAttribute("data-id");
  2682. if( id ){
  2683. var newSrc = MWF.xDesktop.getImageSrc(id);
  2684. if(newSrc){
  2685. img.setAttribute("src" , newSrc );
  2686. img.setAttribute("data-cke-saved-src" , newSrc );
  2687. }
  2688. }
  2689. }
  2690. }
  2691. }
  2692. });
  2693. this.items.push( this.editor );
  2694. }.bind(this));
  2695. },
  2696. loadRead : function(){
  2697. var _self = this;
  2698. var item;
  2699. var name = this.options.name;
  2700. var value = this.options.value || this.options.defaultValue ;
  2701. var styles = this.options.style || {};
  2702. var attr = this.options.attr || {};
  2703. var parent = this.container ;
  2704. var className = null ;
  2705. item = new Element( "span", {
  2706. "name" : name
  2707. // "html" : value
  2708. });
  2709. item.set( attr );
  2710. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  2711. item.setStyles( styles );
  2712. if( this.options.clazz )item.addClass( this.options.clazz );
  2713. if(parent)item.inject(parent);
  2714. this.loadLazyImage(item, value, function(){
  2715. if( window.layout && layout.mobile ){
  2716. }else if( this.options.enablePreview ) {
  2717. this.loadImageViewer(item);
  2718. }else if( this.options.RTFConfig && this.options.RTFConfig.enablePreview === false) {
  2719. }else{
  2720. this.loadImageViewer(item);
  2721. }
  2722. }.bind(this));
  2723. this.items.push( item );
  2724. },
  2725. getAttrRegExp: function( attr ){
  2726. return "\\s+" + attr + "\\s*=\\s*[\"|\'](.*?)[\"|\']";
  2727. },
  2728. getAttributeValue: function(str, attribute){
  2729. var regexp = new RegExp( this.getAttrRegExp(attribute) , "i");
  2730. var array = str.match( regexp );
  2731. return (o2.typeOf(array) === "array" && array.length === 2) ? array[1] : "";
  2732. },
  2733. addAttribute: function(str, attribute, value){
  2734. var regexp = new RegExp( "\\/*\\s*>" , "i");
  2735. return str.replace( regexp, ' ' + attribute + '="' + value + '"' + " />");
  2736. },
  2737. removeAttribute: function(str, attribute){
  2738. var regexp = new RegExp( this.getAttrRegExp(attribute) , "ig");
  2739. return str.replace( regexp, "" );
  2740. },
  2741. parseHtml: function(html){
  2742. html = this.replaceHrefJavascriptStr(html);
  2743. html = this.replaceOnAttribute(html);
  2744. html = this.parseOnerror(html);
  2745. return html;
  2746. },
  2747. parseOnerror: function(html){
  2748. var regexp_all = /(i?)(<img)([^>]+>)/gmi;
  2749. var images = html.match(regexp_all);
  2750. if(images){
  2751. if (images.length){
  2752. for (var i=0; i<images.length; i++){
  2753. var image = images[i];
  2754. var image1 = this.removeAttribute(image, "onerror");
  2755. image1 = this.addAttribute(image1, "onerror", "MWF.xDesktop.setImageSrc()");
  2756. html = html.replace(image, image1);
  2757. }
  2758. }
  2759. }
  2760. return html;
  2761. },
  2762. replaceHrefJavascriptStr: function( html ){
  2763. var regexp_a_all = /(i?)(<a)([^>]+>)/gmi;
  2764. var as = html.match(regexp_a_all);
  2765. if(as){
  2766. if (as.length){
  2767. for (var i=0; i<as.length; i++){
  2768. var a = as[i];
  2769. var href = this.getAttributeValue(a, "href");
  2770. if( href.indexOf('javascript:') > -1 ){
  2771. var a1 = this.removeAttribute(a, "href");
  2772. html = html.replace(a, a1);
  2773. }
  2774. }
  2775. }
  2776. }
  2777. return html;
  2778. },
  2779. replaceOnAttribute: function (htmlString){
  2780. var tempDiv = document.createElement('div');
  2781. tempDiv.innerHTML = htmlString;
  2782. var elements = tempDiv.getElementsByTagName('*');
  2783. for (var i = 0; i < elements.length; i++) {
  2784. var element = elements[i];
  2785. var attributeNames = element.getAttributeNames();
  2786. for (var j = 0; j < attributeNames.length; j++) {
  2787. var attributeName = attributeNames[j];
  2788. if (attributeName.substr(0,2).toLowerCase() === 'on') {
  2789. element.removeAttribute(attributeName);
  2790. }
  2791. }
  2792. }
  2793. return tempDiv.innerHTML;
  2794. },
  2795. loadLazyImage: function(node, html, callback){
  2796. if( this.options && this.options.imageLazyLoading) {
  2797. o2.require("o2.widget.ImageLazyLoader", null, false);
  2798. var loadder = new o2.widget.ImageLazyLoader(node, html);
  2799. loadder.load(function () {
  2800. if (callback) callback();
  2801. }.bind(this));
  2802. }else{
  2803. node.set("html", this.parseHtml(html));
  2804. if (callback) callback();
  2805. }
  2806. },
  2807. loadImageViewer: function(node){
  2808. o2.require("o2.widget.ImageViewer", null, false);
  2809. var imageViewer = new o2.widget.ImageViewer(node);
  2810. imageViewer.load();
  2811. },
  2812. get : function( vort ){
  2813. if( this.options.disable ){
  2814. return ( vort == "value" || vort == "text" ) ? null : {
  2815. value : null,
  2816. text : null
  2817. };
  2818. }
  2819. var value;
  2820. var text;
  2821. if( this.options.isEdited ){
  2822. if( this.options.RTFConfig && this.options.RTFConfig.isSetImageMaxWidth ){
  2823. var div = new Element( "div" , {
  2824. "styles" : { "display" : "none" },
  2825. "html" : this.editor.getData()
  2826. } ).inject( this.container );
  2827. div.getElements( "img").each( function( el ){
  2828. el.setStyle( "max-width" , "100%" );
  2829. });
  2830. value = div.get("html");
  2831. div.destroy();
  2832. }else{
  2833. value = this.editor.getData();
  2834. }
  2835. }else{
  2836. var item = this.mElement.getElement("[name='"+name+"']");
  2837. value = item.get("html");
  2838. }
  2839. if( !value )value="";
  2840. if( !text )text = value;
  2841. if( vort == "value" )return value;
  2842. if( vort == "text")return text;
  2843. var result = {};
  2844. result.value = value;
  2845. result.text = text;
  2846. return result;
  2847. },
  2848. setValue : function( value ){
  2849. if( this.options.disable ){
  2850. return;
  2851. }
  2852. if( this.options.isEdited ){
  2853. this.editor.setData(value);
  2854. }else{
  2855. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  2856. item.set("html", value );
  2857. }
  2858. },
  2859. getErrorText : function(){
  2860. return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
  2861. },
  2862. getClassName : function(){
  2863. var className = null ;
  2864. if( this.options.className == "none" ){
  2865. }else if( this.options.className != "") {
  2866. className = this.options.className
  2867. }else if( !this.options.isEdited ){
  2868. }else {
  2869. }
  2870. return className;
  2871. }
  2872. });
  2873. MDomItem.Org = new Class({
  2874. initialize: function ( module ) {
  2875. this.module = module;
  2876. this.options = module.options;
  2877. this.css = module.css;
  2878. this.app = module.app;
  2879. this.items = module.items;
  2880. this.container = this.mElement = module.container;
  2881. this.valSeparator = module.valSeparator;
  2882. },
  2883. load : function(){
  2884. if( this.options.disable )return;
  2885. if( this.options.isEdited ){
  2886. this.loadEdit();
  2887. }else{
  2888. this.loadRead();
  2889. }
  2890. },
  2891. loadEdit : function(){
  2892. var item;
  2893. var name = this.options.name;
  2894. var value = this.options.value || this.options.defaultValue ;
  2895. var styles = this.options.style || {};
  2896. var attr = this.options.attr || {};
  2897. var parent = this.container ;
  2898. var className = this.getClassName() ;
  2899. if( !value ){
  2900. this.orgData = [];
  2901. }else if( typeOf( value ) == "array" ){
  2902. this.orgData = value;
  2903. }else if( typeOf( value ) == "string" ){
  2904. this.orgData = value.split( this.valSeparator )
  2905. }else if( typeOf( value ) == "object" ){
  2906. this.orgData = [value]
  2907. }else{
  2908. this.orgData = [];
  2909. }
  2910. item = new Element( "div", {
  2911. "name" : name
  2912. });
  2913. item.set( attr );
  2914. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  2915. item.setStyles( styles );
  2916. if( this.options.clazz )item.addClass( this.options.clazz );
  2917. this.loadOrgWidget( this.orgData, item, true );
  2918. this.bindDefaultEvent( item );
  2919. MDomItem.Util.bindEvent( this, item, this.options.event );
  2920. if(parent)item.inject(parent);
  2921. this.items.push( item );
  2922. },
  2923. loadRead : function(){
  2924. var item;
  2925. var name = this.options.name;
  2926. var value = this.options.value || this.options.defaultValue;
  2927. var styles = this.options.style || {};
  2928. var attr = this.options.attr || {};
  2929. var parent = this.container ;
  2930. var className = this.getClassName();
  2931. if( !value ){
  2932. this.orgData = [];
  2933. }else if( typeOf( value ) == "array" ){
  2934. this.orgData = value;
  2935. }else if( typeOf( value ) == "string" ){
  2936. this.orgData = value.split( this.valSeparator )
  2937. }else{
  2938. this.orgData = [];
  2939. }
  2940. this.module.orgData = this.orgData;
  2941. item = new Element( "div", {
  2942. "name" : name
  2943. });
  2944. item.set( attr );
  2945. if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
  2946. item.setStyles( styles );
  2947. if( this.options.clazz )item.addClass( this.options.clazz );
  2948. this.loadOrgWidget( this.orgData, item , false);
  2949. if(parent)item.inject(parent);
  2950. this.items.push( item );
  2951. },
  2952. reset: function(){
  2953. this.setValue( this.options.defaultValue || [] );
  2954. },
  2955. getData : function( parse ){
  2956. var data = [];
  2957. this.OrgWidgetList.each( function( widget ){
  2958. data.push( parse ? MWF.org.parseOrgData(widget.data, true) : widget.data );
  2959. }.bind(this));
  2960. return data;
  2961. },
  2962. get : function( vort ){
  2963. if( this.options.disable ){
  2964. return ( vort == "value" || vort == "text" ) ? null : {
  2965. value : null,
  2966. text : null
  2967. };
  2968. }
  2969. var value = this.orgData;
  2970. if( vort == "value" )return value;
  2971. if( vort == "text")return value;
  2972. var result = {};
  2973. result.value = value;
  2974. result.text = value;
  2975. return result;
  2976. },
  2977. setValue : function( value ){
  2978. if( this.options.disable ){
  2979. return;
  2980. }
  2981. var item = this.mElement.getElement("[name='"+ this.options.name + "']");
  2982. if( !value ){
  2983. this.orgData = [];
  2984. }else if( typeOf( value ) == "array" ){
  2985. this.orgData = value;
  2986. }else if( typeOf( value ) == "string" ){
  2987. this.orgData = value.split( this.valSeparator );
  2988. }else{
  2989. this.orgData = [];
  2990. }
  2991. this.orgObjData = null;
  2992. item.empty();
  2993. this.loadOrgWidget( this.orgData, item, this.options.isEdited );
  2994. this.module.orgData = this.orgData
  2995. },
  2996. getErrorText : function(){
  2997. return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
  2998. },
  2999. bindDefaultEvent : function( item ){
  3000. if( this.options.unsetDefaultEvent )return;
  3001. item.addEvent( "click" , function( ev ){
  3002. debugger;
  3003. this.module.fireEvent("querySelect", this.module );
  3004. var options = this.options;
  3005. var opt = {
  3006. type : options.orgType,
  3007. title : options.text,
  3008. count : options.count,
  3009. selectedValues : this.orgObjData || this.orgData,
  3010. units : options.units,
  3011. unitType : options.unitType,
  3012. groups : options.groups,
  3013. expand : options.expand,
  3014. exclude : options.exclude,
  3015. expandSubEnable : options.expandSubEnable
  3016. };
  3017. if( this.options.orgOptions ){
  3018. opt.orgOptions = this.options.orgOptions;
  3019. }
  3020. MDomItem.Util.selectPerson( this.app.content, opt, function( array ){
  3021. item.empty();
  3022. this.orgData = this.module.orgData = [];
  3023. this.orgObjData = [];
  3024. this.orgObject = this.module.orgObject = array;
  3025. array.each(function( it ){
  3026. this.orgData.push( it.data.distinguishedName || it.data.name );
  3027. this.orgObjData.push( it.data );
  3028. }.bind(this));
  3029. this.OrgWidgetList = [];
  3030. this.loadOrgWidget( this.orgObjData, item, true );
  3031. this.modified = true;
  3032. this.items[0].fireEvent("change", [this.module, ev]);
  3033. if( this.options.validImmediately )this.module.verify( true );
  3034. }.bind(this))
  3035. }.bind(this) );
  3036. },
  3037. getValueByType : function( type ){
  3038. var types = typeOf( type ) == "string" ? type.split(",") : type;
  3039. types = types.map( function( item, index ){
  3040. switch (item.toLowerCase()) {
  3041. case "person": return "p";
  3042. case "identity": return "i";
  3043. case "unit": return "u";
  3044. case "group": return "g";
  3045. case "role": return "r";
  3046. default: return item.toLowerCase();
  3047. }
  3048. });
  3049. var value = [];
  3050. this.get("value").each( function( v ){
  3051. var flag = v.substr(v.length-1, 1);
  3052. if( types.contains( flag.toLowerCase() ) )value.push( v );
  3053. });
  3054. return value;
  3055. },
  3056. loadOrgWidget: function(value, node, canRemove){
  3057. this.OrgWidgetList = this.OrgWidgetList || [];
  3058. MWF.require("MWF.widget.O2Identity", null, false);
  3059. var options = { "style": this.options.orgStyle || "xform", "canRemove": canRemove , "onRemove" : this.removeOrgItem, "lazy": true };
  3060. if( this.options.orgWidgetOptions ){
  3061. options = Object.merge( options, this.options.orgWidgetOptions );
  3062. }
  3063. value.each(function( v ){
  3064. var data;
  3065. var distinguishedName;
  3066. if( typeOf(v) === "string" ){
  3067. distinguishedName = v;
  3068. if( distinguishedName.indexOf("@") > 0 ){
  3069. data = {
  3070. "distinguishedName" : distinguishedName,
  3071. "name": distinguishedName.split("@")[0]
  3072. }
  3073. }else{
  3074. data = {
  3075. "id" : distinguishedName,
  3076. "name": distinguishedName.split("@")[0]
  3077. }
  3078. }
  3079. }else{
  3080. distinguishedName = v.distinguishedName || v.name || "";
  3081. if( !v.name )v.name = distinguishedName.split("@")[0];
  3082. data = v;
  3083. }
  3084. var flag = distinguishedName.substr(distinguishedName.length-1, 1);
  3085. switch (flag.toLowerCase()){
  3086. case "i":
  3087. var widget = new MWF.widget.O2Identity( data, node, options );
  3088. break;
  3089. case "p":
  3090. var widget = new MWF.widget.O2Person(data, node, options);
  3091. break;
  3092. case "u":
  3093. var widget = new MWF.widget.O2Unit(data, node, options);
  3094. break;
  3095. case "g":
  3096. var widget = new MWF.widget.O2Group(data, node, options);
  3097. break;
  3098. //case "d":
  3099. // var widget = new MWF.widget.O2Duty(data, node, options);
  3100. // break;
  3101. default:
  3102. var orgType = this.options.orgType;
  3103. var t = ( typeOf( orgType ) == "array" && orgType.length == 1 ) ? orgType[0] : orgType;
  3104. t = typeOf( t ) == "string" ? t.toLowerCase() : "";
  3105. if( t == "identity" ){
  3106. var widget = new MWF.widget.O2Identity( data, node, options );
  3107. }else if( t == "person" ){
  3108. var widget = new MWF.widget.O2Person(data, node, options);
  3109. }else if( t == "unit" ){
  3110. var widget = new MWF.widget.O2Unit(data, node, options);
  3111. }else if( t == "group" ){
  3112. var widget = new MWF.widget.O2Group(data, node, options);
  3113. }else if( t == "process" ){
  3114. // var d = { id : distinguishedName };
  3115. if( data.id === data.name )delete data.name;
  3116. var widget = new MWF.widget.O2Process(data, node, options);
  3117. //}else if( t == "duty" ){
  3118. // var widget = new MWF.widget.O2Duty(data, node, options);
  3119. }else if( t == "CMSView" ){
  3120. // var d = { id : distinguishedName };
  3121. var widget = new MWF.widget.O2CMSView(data, node, options);
  3122. //}else if( t == "duty" ){
  3123. // var widget = new MWF.widget.O2Duty(data, node, options);
  3124. }else{
  3125. var widget = new MWF.widget.O2Other( data, node, options);
  3126. }
  3127. }
  3128. widget.field = this;
  3129. this.OrgWidgetList.push( widget );
  3130. }.bind(this));
  3131. },
  3132. removeOrgItem : function( widget, ev ){
  3133. //this 是 MWF.widget.O2Identity 之类的对象
  3134. var _self = this.field; //这个才是MDomItem 对象
  3135. var dn = widget.data.distinguishedName || widget.data.name;
  3136. var data = [];
  3137. var index;
  3138. _self.orgData.each( function ( d , i){
  3139. if( d != dn )data.push( d )
  3140. });
  3141. _self.orgData = data;
  3142. if( _self.orgObject ){
  3143. data = [];
  3144. _self.orgObject.each( function( d ){
  3145. if( d.data ){
  3146. if( d.data.distinguishedName ){
  3147. if( d.data.distinguishedName != dn )data.push( d );
  3148. }else{
  3149. if( d.data.name != dn )data.push( d );
  3150. }
  3151. }
  3152. });
  3153. _self.orgObject = data;
  3154. }
  3155. if( _self.orgObjData ){
  3156. data = [];
  3157. _self.orgObjData.each( function( d ){
  3158. if( d.distinguishedName ){
  3159. if( d.distinguishedName != dn )data.push( d );
  3160. }else{
  3161. if( d.name != dn )data.push( d );
  3162. }
  3163. });
  3164. _self.orgObjData = data;
  3165. }
  3166. this.node.destroy();
  3167. _self.items[0].fireEvent("change");
  3168. ev.stopPropagation();
  3169. },
  3170. getClassName : function(){
  3171. var className = null ;
  3172. if( this.options.className == "none" ){
  3173. }else if( this.options.className != "") {
  3174. className = this.options.className
  3175. }else if( !this.options.isEdited ){
  3176. }else {
  3177. className = "inputPerson"
  3178. }
  3179. return className;
  3180. }
  3181. });
  3182. MDomItem.File = new Class({
  3183. initialize: function ( module ) {
  3184. this.module = module;
  3185. this.options = module.options;
  3186. this.css = module.css;
  3187. this.app = module.app;
  3188. this.items = module.items;
  3189. this.container = this.mElement = module.container;
  3190. this.valSeparator = module.valSeparator;
  3191. },
  3192. load : function(){
  3193. if( this.options.disable )return;
  3194. if( this.options.isEdited ){
  3195. this.loadEdit();
  3196. }else{
  3197. this.loadRead();
  3198. }
  3199. },
  3200. loadEdit : function(){
  3201. },
  3202. loadRead : function(){
  3203. },
  3204. get : function( vort ){
  3205. },
  3206. setValue : function( value ){
  3207. },
  3208. getErrorText : function(){
  3209. }
  3210. });