MDomItem.js 110 KB

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