MDomItem.js 106 KB

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