MDomItem.js 110 KB

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