MDomItem.js 110 KB

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