MDomItem.js 112 KB

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