MDomItem.js 109 KB

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