MDomItem.js 109 KB

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