MDomItem.js 106 KB

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