123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336 |
- /*
- DOMElement管理类
- var item = new MDomItem( containerNode, {
- name : "demo",
- type : "checkbox",
- selectValue: [opt1,opt2,opt3]
- selectText : function( callback , options ){ //异步方法的写法,需要一个callback,并且把该option值传给callback执行,这个function不能bind
- this.app.actions.XXX( id, function( json ){
- var optText = [];
- ....
- callback( optText )
- })
- },
- value : function(){ var val = .... ; return val; }
- } , null, app, css);
- item.load();
- 外部方法:
- get( textOrValue ) 参数"text"或"value" 获取文本或值
- getValue() 获取值
- getText() 获取文本
- getModifiedValue() 获取修改过的值,如果没有修改过返回null
- getModifiedText() 获取修改过的文本,如果没有修改过返回null
- setValue() 设置对象的值
- resetType( type ) 修改类型
- resetItemOptions( selectValue[, selectText ]) 修改可选项,selectValue可项值,selectText可选文本
- dispose() 清空对象
- verify( isShowWarning ) 参数isShowWarning,校验不通过的是否提示用户。根据isShowWarning参数和options的notEmpty、warningType、validRule属性校验对象,返回boolean
- */
- //MWF.xDesktop.requireApp("Template", "lp." + MWF.language, null, false);
- var MDomItem_ClassType = {
- "text" : "Text",
- "textarea" : "Textarea",
- "hidden" : "Hidden",
- "password" : "Password",
- "radio" : "Radio",
- "checkbox" : "Checkbox",
- "select" : "Select",
- "multiselect" : "Multiselect",
- "innertext" : "Innertext",
- "innerhtml" : "Innerhtml",
- "img" : "Img",
- "button" : "Button",
- "mselector" : "MSelector",
- "imageclipper" : "ImageClipper",
- "rtf" : "Rtf",
- "org" : "Org",
- "a" : "A"
- };
- var MDomItem = new Class({
- Implements: [Options, Events],
- options : {
- name : "", //生成的对象的name属性
- value : "", //对象的值
- text : "", //对应的中文名称
- type : "", //可以为 text,innertext, radio,checkbox,select,multiselect,img,button,hidden,rtf,imageClipper, org, mSelector
- isEdited : true,
- tType : "", //type 为text时候有效,可以为 number,date,time, datetime,person、unit、identity,如果是组织混合选择用数组,如["person"、"unit"、"identity"]
- orgType : "", //person、unit、identity, process, duty,如果是混合选择用数组,如["person"、"unit"、"identity"]
- unitType : "", //如果orgType包含unit,则可以指定组织类型
- count : 1, //如果是多选,多选的上限值,0表示无限制,默认为1,
- units : [], //orgType 为 identity、unit时的,部门选择范围
- groups : [], //orgType 为 person 时的选择访问
- exclude : [], //选择时的排除项目
- expandSubEnable : true, //orgType 为 identity、unit时是否展开下级选择范围
- orgStyle : "", //显示类型,比如default, xform 等
- unsetDefaultEvent : false, //tType 或 orgType 有值时,是否取消默认事件
- //可以传入json 如 : { change : function(){alert("change " + this.name );}, click : function(){alert("click " + this.name) } }
- //或 字符串 : "{ change : function(){alert('change ' + this.name );}, click : function(){alert('click ' + this.name) } }"
- //或字符串: "change^^function(){alert('change ' + this.name );##click^^function(obj){alert('click ' + this.name);}"
- event : null, //需要绑定的事件
- selectValue : "", //选择性控件的可选值
- selectText : "", //选择型控件的可选文本
- defaultValue : "", //默认值
- className : "", //类
- style : {}, //样式
- attr : {}, //其他参数, 比如 " {readonly : true, size : '20' }"
- notEmpty : false, //是否允许为空,默认允许
- defaultValueAsEmpty: false, //检查空值时,默认值是否为空,并且获取值得时候,如果是默认值,返回空值
- emptyTip : null, //为空时的提示,可以不设置
- disable : false, //为false,则load失效;
- //alert 或者 batch 或者 single,单个提醒或者批量提醒
- warningType : "batch",
- validImmediately : false,
- //可以传入校验类型或自定义方法,如
- //{email : true , url : true, date : true, dateISO : true, number : true, digits : true,
- // maxlength:5, minlength:10, rangelength:[5,10], max:5, min:10 ,range:[5,10], extension: ["xls","xlsx"],fun : function(){ return true }
- // }
- validRule : null,
- //validMessage和validRule对应,出错时提示的信息,如 {email : "请输入正确格式的电子邮件", fun : "请输入正确的密码"},如果不设置,默认如下:
- // { email: "请输入正确格式的电子邮件",
- // url: "请输入合法的网址",
- // date: "请输入合法的日期",
- // dateISO: "请输入合法的日期 (ISO).",
- // number: "请输入合法的数字",
- // digits: "只能输入整数",
- // maxlength: this.format("请输入一个 长度最多是 {0} 的字符串"),
- // minlength: this.format("请输入一个 长度最少是 {0} 的字符串"),
- // rangelength: this.format("请输入 一个长度介于 {0} 和 {1} 之间的字符串"),
- // range: this.format("请输入一个介于 {0} 和 {1} 之间的值"),
- // max: this.format("请输入一个最大为{0} 的值"),
- // min: this.format("请输入一个最小为{0} 的值"),
- // fun : "请输入正确的"+ this.options.text
- // }
- validMessage : null,
- RTFConfig : null, //CKEditor 的设置项
- mSelectorOptions : null, //自定义下拉组件设置项
- calendarOptions : null, //日期选择器的设置项
- orgWidgetOptions : null, //org组件的选项
- orgOptions: null
- },
- initialize: function (container, options , parent, app, css ) {
- this.form = parent;
- this.tr = parent;
- this.parent = parent;
- this.app = app;
- this.container = $(container);
- if( css )this.css = css;
- if( options.formStyle ){
- this.cssPath = "../x_component_Template/$MForm/"+options.formStyle+"/css.wcss";
- this._loadCss();
- }
- //for(var o in options ){ //允许使用 function 来计算设置, on开头的属性被留作 fireEvent
- // if( o != "validRule" && o!="validMessage" && o.substr(0,2)!="on" && typeOf( options[o] )== "function" ){
- // options[o] = options[o].call();
- // }
- //}
- //this.setOptions(options);
- this.valSeparator = /,|;|\^\^|\|/; //如果是多值对象,作为用户选择的多个值的分隔符
- this.mElement = this.container; //容器
- this.node = this.container;
- this.items = [];
- this.setOptionList( options );
- },
- setOptionList : function( options ){ //目的是使用options里的function异步方法通过 function(callback){ ...获取value; callback( value ); } 来回调设置option
- var callbackNameList = [];
- for(var o in options ){ //允许使用 function 来计算设置, on开头的属性被留作 fireEvent
- if( o != "validRule" && o!="validMessage" && o.substr(0,2)!="on" && typeOf( options[o] )== "function" ){
- var fun = options[o];
- if( fun.length && /\(\s*([\s\S]*?)\s*\)/.exec(fun)[1].split(/\s*,\s*/)[0] == "callback" ){ //如果有行参(fun.length!=0),并且第一形参是callback,注意,funciont不能bind(this),否则不能判断
- callbackNameList.push( o );
- }else{
- options[o] = fun( options, this ); //执行fun
- }
- }
- }
- this.setFunOption( options, callbackNameList, true ); //递归执行回调设置options
- },
- setFunOption : function( options, callbackNameList, isFirst ){
- this.optionsReady = false;
- if( callbackNameList.length == 0 ){
- this.setOptions( options );
- this.optionsReady = true;
- if( this.loadFunctionCalled ){ //如果外部程序已经执行过load,但是由于options没有设置完成而中断,需要再调用一下load
- this.load();
- }
- }else{
- if( isFirst )options = Object.merge( {}, options ); //避免外部程序对options的修改
- var name = callbackNameList.shift(); //返回第一个元素,然后在callbackNameList删除第一元素
- var fun = options[name]; //对应的参数,是一个function
- fun( function( val ){ //执行function
- options[name] = val; //在回调内部给option赋值
- this.setFunOption( options, callbackNameList, false ); //继续执行下一个回调
- }.bind(this), options );
- }
- },
- load: function () {
- if( !this.optionsReady ){ //如果options没有设置完成
- this.loadFunctionCalled = true;
- return;
- }
- if( this.options.disable )return;
- if( ! this.options.type ){
- this.options.type = this.options.orgType ? "org" : "text";
- }
- this.options.type = this.options.type.toLowerCase();
- this.fireEvent("queryLoad");
- this.createElement();
- this.fireEvent("postLoad", [this]);
- },
- _loadCss: function(reload){
- debugger;
- var key = encodeURIComponent(this.cssPath);
- if (!reload && o2.widget.css[key]){
- this.css = !this.css ? o2.widget.css[key] : Object.merge({}, o2.widget.css[key], this.css);
- }else{
- this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+o2.version.v : this.cssPath+"?v="+o2.version.v;
- var r = new Request.JSON({
- url: o2.filterUrl(this.cssPath),
- secure: false,
- async: false,
- method: "get",
- noCache: false,
- onSuccess: function(responseJSON, responseText){
- this.css = !this.css ? responseJSON : Object.merge({}, responseJSON, this.css);
- o2.widget.css[key] = responseJSON;
- }.bind(this),
- onError: function(text, error){
- alert(error + text);
- }
- });
- r.send();
- }
- },
- editMode : function( keep ){
- if(keep)this.save();
- this.options.isEdited = true;
- this.dispose();
- this.items = [];
- this.load();
- },
- save : function(){
- this.options.value = this.getValue();
- },
- readMode : function( keep ){
- if(keep)this.save();
- this.options.isEdited = false;
- this.dispose();
- this.items = [];
- this.load();
- },
- enable : function(){
- this.options.disable = false;
- this.dispose();
- this.load();
- },
- disable : function(){
- this.options.disable = true;
- this.dispose();
- },
- createElement:function(){
- if( this.options.disable )return;
- var clazzName = MDomItem_ClassType[ this.options.type ];
- if( clazzName ){
- this.dom = new MDomItem[ clazzName ]( this );
- this.dom.load();
- }
- return this.container;
- },
- get: function( vort ){ //value 和 text
- if( this.options.disable ){
- return {
- text : "",
- value : ""
- };
- }
- if( this.dom )return this.dom.get( vort );
- },
- getValue : function( separator, name ){
- var result = this.get( null , name ).value;
- if( separator && typeOf( result ) == "array" ){
- return result.join( separator );
- }else{
- return result;
- }
- },
- getText : function( separator, name ){
- var result = this.get( null , name ).text;
- if( separator && typeOf( result ) == "array" ){
- return result.join( separator );
- }else{
- return result;
- }
- },
- getModifiedValue : function( separator ){
- var value = this.getValue( separator );
- return value == this.options.value ? null : value ;
- },
- getModifiedText : function(){
- var value = this.getText();
- return text == this.options.text ? null : text ;
- },
- getVaildValue : function(verify, separator, isHiddenWarming, onlyModified ) {
- if ( !verify || this.verify(!isHiddenWarming)) {
- return onlyModified ? this.getModifiedValue( separator ) : this.getValue( separator );
- } else {
- return false;
- }
- },
- set : function( type, valueOrText ){
- this.setValue( valueOrText )
- },
- resetItemOptions : function( selectValue, selectText, isForce ){
- if( this.options.disable ){
- if( isForce ){
- this.options.disable = false;
- }else{
- return;
- }
- }
- var availTypes = "radio,checkbox,select,multiselect".split( "," );
- if( !availTypes.contains( this.options.type ) )return;
- this.dispose();
- this.options.selectValue = selectValue;
- this.options.selectText = selectText;
- this.createElement();
- },
- reset: function(){
- debugger;
- if( typeOf(this.dom.reset) === "function" ){
- this.dom.reset();
- }else{
- this.setValue( this.options.defaultValue || "" );
- }
- },
- setValue :function(value){
- if( this.dom )this.dom.setValue(value);
- },
- setStyles : function( styles ){
- if( this.options.disable )return;
- this.items.each( function( item ){
- item.setStyles( styles )
- })
- },
- getElements : function(){
- if( this.options.disable )return null;
- return this.mElement.getElements("[name='"+this.options.name+"']");
- },
- dispose : function(){
- this.container.empty();
- },
- verify : function( isShowWarning ){
- var flag = true;
- if( !this.options.isEdited )return flag;
- if( this.options.disable )return flag;
- if( this.options.warningType == "batch" ){
- if( !this.isNotEmpty(isShowWarning) ) flag = false;
- if( !this.checkValid(isShowWarning) ) flag = false;
- }else{
- if( !this.isNotEmpty(isShowWarning) || !this.checkValid(isShowWarning) ){
- return false;
- }
- }
- return flag;
- },
- isNotEmpty: function( isShowWarning ){
- if( !this.options.isEdited )return true;
- if( this.options.disable )return true;
- if( this.options.notEmpty == true || this.options.notEmpty == "yes" ){
- if( !this.checkNotEmpty( isShowWarning ) ){
- return false;
- }
- }
- return true;
- },
- checkNotEmpty:function( isShowWarning ){
- if( this.options.disable )return true;
- var value = this.getValue();
- var isEmpty = ( typeOf(value) === "array" ? ( value.length == 0 ) : ( value == "" || value == " ") );
- if( !isEmpty && this.options.defaultValueAsEmpty ){
- isEmpty = ( typeOf(value) === "array" ? ( value.length == 1 && value[0] == this.options.defaultValue ) : ( value == this.options.defaultValue ) );
- }
- if( !isEmpty ){
- this.clearWarning("empty");
- return true;
- }
- if( !isShowWarning )return false;
- var text = this.options.text;
- var items = this.mElement.getElements("[name='"+ this.options.name + "']");
- var warningText = "";
- var focus = false;
- try{
- warningText = this.options.emptyTip || (this.dom && this.dom.getErrorText()) || MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",text);
- if( this.options.warningType == "batch" ) {
- this.setWarning(warningText, "empty");
- }else if( this.options.warningType == "single" ){
- this.setWarning(warningText, "empty");
- }else{
- if( this.app && this.app.notice ){
- if (!this.container.isIntoView()){
- var pNode = this.container.getParent();
- while (pNode && ((pNode.getScrollSize().y-(pNode.getComputedSize().height+1)<=0) || pNode.getStyle("overflow")==="visible")) pNode = pNode.getParent();
- if (!pNode) pNode = document.body;
- pNode.scrollToNode(this.container, "bottom");
- }
- var y = this.container.getSize().y;
- this.app.notice(warningText,"error",this.container, {"x": "right", "y": "top"}, { x : 10, y : y });
- }
- if( !this.options.validImmediately ){
- if( ["text","password","textarea","select","multiselect"].contains( this.options.type ) ){
- items[0].focus();
- }
- }
- }
- this.fireEvent("empty", this);
- }catch( e ){
- }
- return false;
- },
- clearWarning : function( type ){
- if( this.tipNode && this.setedEmpty ){
- this.fireEvent("unempty", this);
- this.tipNode.empty();
- this.setedEmpty = false;
- }
- if( type == "empty" ){
- if( this.warningEmptyNode ){
- this.fireEvent("unempty", this);
- this.warningEmptyNode.destroy();
- this.warningEmptyNode = null;
- }
- }else{
- if( this.warningInvalidNode ){
- this.fireEvent("unempty", this);
- this.warningInvalidNode.destroy();
- this.warningInvalidNode = null;
- }
- }
- this.warningStatus = false;
- },
- setWarning : function( msg, type ){
- var div;
- if( type == "empty" ){
- if( this.tipNode ){
- this.setedEmpty = true;
- div = this.tipNode;
- div.set("html", "");
- }else if( this.warningEmptyNode ){
- div = this.warningEmptyNode;
- div.set("html", "");
- }else{
- div = this.warningEmptyNode = new Element("div");
- div.inject( this.container ) ;
- }
- }else{
- if( this.tipNode ){
- this.setedEmpty = true;
- div = this.tipNode;
- div.set("html", "");
- }else if( this.warningInvalidNode ){
- div = this.warningInvalidNode;
- div.set("html", "");
- }else{
- div = this.warningInvalidNode = new Element("div");
- div.inject( this.container ) ;
- }
- }
- this.warningStatus = true;
- if( typeOf(msg) != "array" ){
- msg = [msg];
- }
- msg.each( function(m){
- //var html = "<table style=\"margin-top:3px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
- //html += "<tr valign=\"middle\"><td><img src=\"./img/exclamation.png\" /></td>";
- //html += "<td style=\"width:3px;\"></td><td><div style=\"color:#FF0000; margin-top:2px;\">"+m+"</div></td></tr>";
- //html += "</table>";
- var node = new Element("div",{
- "text" : m,
- "styles" : this.css.warningMessageNode
- }).inject(div)
- }.bind(this))
- },
- checkValid : function( isShowWarning ){
- if( this.options.disable )return true;
- var value = this.getValue();
- var rules = this.options.validRule;
- if( !rules )return true;
- var msgs = [];
- var flag = true;
- //if( value && value != "" && value != " " ){
- var rule, msg, method, valid;
- if( typeOf( rules ) === "object" ){
- for(var r in rules ){
- valid = true;
- rule = rules[r];
- if( typeof rule == "function"){
- valid = rule.call( this, value, this );
- }else if( this.validMethod[r] ){
- method = this.validMethod[r];
- valid = method.call(this, value, rule, this );
- }
- if( !valid && isShowWarning ){
- msg = this.getValidMessage( r, rule );
- if( msg != "" )msgs.push( msg );
- }
- if( !valid )flag = false;
- }
- }else if( typeOf( rules ) === "array" ){
- for( var i = 0; i<rules.length; i++ ){
- if( typeof rules[i] == "function"){
- msg = rules[i].call( this, value, this );
- if( msg && typeof msg === "string" ){
- flag = false;
- if( isShowWarning )msgs.push( msg );
- }
- }
- }
- }else if( typeOf( rules ) === "function" ){
- msg = rules.call( this, value, this );
- if( msg && typeof msg === "string" ){
- flag = false;
- if( isShowWarning )msgs.push( msg );
- }
- }
- //}
- if( msgs.length > 0 ){
- if( this.options.warningType == "batch" ) {
- this.setWarning(msgs, "invaild");
- }else if( this.options.warningType == "single" ){
- this.setWarning(msgs, "invaild");
- }else{
- if( this.app && this.app.notice ) {
- if (!this.container.isIntoView()) {
- var pNode = this.container.getParent();
- while (pNode && ((pNode.getScrollSize().y - (pNode.getComputedSize().height + 1) <= 0) || pNode.getStyle("overflow") === "visible")) pNode = pNode.getParent();
- if (!pNode) pNode = document.body;
- pNode.scrollToNode(this.container, "bottom");
- }
- var y = this.container.getSize().y;
- this.app.notice(msgs.join("\n"), "error", this.container, {"x": "right", "y": "top"}, { x : 10, y : y });
- }
- }
- this.fireEvent("empty", this);
- }else{
- if( this.warningInvalidNode ){
- this.warningInvalidNode.destroy();
- this.warningInvalidNode = null;
- }
- this.fireEvent("unempty", this);
- }
- return flag;
- },
- validMethod : {
- email: function( value ) {
- 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 );
- },
- url: function( value ) {
- 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 );
- },
- phoneNumber: function( value ){
- return /^0?1[0-9]\d{9}$/.test( value );
- },
- date: function( value ) {
- return !/Invalid|NaN/.test( new Date( value ).toString() );
- },
- dateISO: function( value ) {
- return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value );
- },
- number: function( value ) {
- return /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
- },
- digits: function( value ) {
- return /^\d+$/.test( value );
- },
- minlength: function( value, param ) {
- return value.length >= param;
- },
- maxlength: function( value, param ) {
- return value.length <= param;
- },
- rangelength: function( value, param ) {
- return ( value.length >= param[ 0 ] && value.length <= param[ 1 ] );
- },
- min: function( value, param ) {
- return value >= param;
- },
- max: function( value, param ) {
- return value <= param;
- },
- range: function( value, param ) {
- return ( value >= param[ 0 ] && value <= param[ 1 ] );
- },
- extension: function( value, param ){
- param = typeOf( param ) == "array" ? param.join("|") : param.replace(/,/g, "|"); //"png|jpe?g|gif";
- return value.match(new RegExp(".(" + param + ")$", "i"));
- }
- },
- getValidMessage : function( type, param ){
- var msg = this.options.validMessage;
- if( msg && typeOf(msg) == "object" ){
- if( msg[type] ){
- if( typeof msg[type] == "function" ){
- return (msg[type]).call(this);
- }else{
- return msg[type];
- }
- }
- }
- var lp = MWF.xApplication.Template.LP.MDomItem;
- switch( type ){
- case "email":
- return lp.emailTip;
- case "url":
- return lp.urlTip;
- case "phoneNumber" :
- return lp.phoneNumberTip;
- case "date":
- return lp.dateTip;
- case "dateISO":
- return lp.dateISOTip;
- case "number":
- return lp.numberTip;
- case "digits":
- return lp.digitsTip;
- case "maxlength":
- return lp.maxlengthTip.replace("{n}",param );
- case "minlength":
- return lp.minlengthTip.replace("{n}",param );
- case "rangelength":
- return lp.rangelengthTip.replace("{n0}",param[0] ).replace("{n1}",param[1] ) ;
- case "range":
- return lp.rangeTip.replace("{n0}",param[0] ).replace("{n1}",param[1] ) ;
- case "min":
- return lp.minTip.replace("{n}",param );
- case "max":
- return lp.maxTip.replace("{n}",param );
- case "extension":
- return lp.extensionTip.replace("{text}",param );
- default :
- return lp.defaultTip.replace("{text}",this.options.text );
- }
- },
- destroy: function(){
- if( this.dom && this.dom.OrgWidgetList ){
- this.dom.OrgWidgetList.each( function( widget ){
- widget.destroy();
- })
- }
- if( this.mElement ){
- this.mElement.empty();
- }
- MWF.release( this );
- }
- });
- MDomItem.Util = {
- selectCalendar : function( target, container, options, callback ){
- var type = options.type;
- var calendarOptions = {
- "style" : "xform",
- "isTime": type == "time" || type.toLowerCase() == "datetime",
- "timeOnly": type == "time",
- "target": container,
- "onComplate" : function( dateString ,date ){
- if( callback )callback( dateString, date );
- }.bind(this),
- "onClear": function () {
- if( callback )callback( "", null );
- }
- };
- if( options.calendarOptions ){
- calendarOptions = Object.merge( calendarOptions, options.calendarOptions )
- }
- var calendar;
- MWF.require("MWF.widget.Calendar", function(){
- calendar = new MWF.widget.Calendar( target, calendarOptions);
- calendar.show();
- }.bind(this), false);
- return calendar;
- },
- selectPerson: function( container, options, callback ){
- if( options.type === "custom" ){
- this._selectCustom(container, options, callback);
- }else{
- this._selectPerson(container, options, callback);
- }
- },
- _selectCustom: function( container, options, callback ){
- MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false); //加载资源
- var opt = {
- "title": options.title,
- "count" : options.count,
- "values": options.selectedValues || [],
- "expand": typeOf( options.expand ) === "boolean" ? options.expand : true,
- "exclude" : options.exclude || [],
- "expandSubEnable" : typeOf( options.expandSubEnable ) === "boolean" ? options.expandSubEnable : true,
- "hasLetter" : false, //是否点击字母搜索
- "hasTop" : false, //可选、已选的标题
- // "level1Indent" : 0, //第一层的缩进
- // "indent" : 36, //第二层及以上的缩进
- "selectAllEnable" : true, //是否允许多选,如果分类可以被选中,blue_flat样式下失效
- "width" : "700px", //选中框宽度
- "height" :"550px", //选中框高度
- "category": true, //按分类选择
- "noSelectedContainer" : false, //是否隐藏右侧已选区域
- "categorySelectable" : false, //分类是否可以被选择,如果可以被选择那么执行的是item的事件
- "uniqueFlag" : "id", //项目匹配(是否选中)关键字
- "defaultExpandLevel" : 1, //默认展开项目,0表示折叠所有分类
- "onComplete": function( array ){
- if( callback )callback( array );
- }.bind(this)
- };
- if( options.orgOptions ){
- opt = Object.merge(opt, options.orgOptions);
- }
- var selector = new MWF.xApplication.Template.Selector.Custom(container, opt );
- selector.load();
- },
- _selectPerson: function( container, options, callback ){
- MWF.xDesktop.requireApp("Selector", "package", null, false);
- var selectType = "", selectTypeList = [];
- var type = options.type;
- if( typeOf( type ) == "array" ){
- if( type.length > 1 ){
- selectTypeList = type;
- }else if( type.length == 0 ) {
- selectType = "person";
- }else{
- selectType = type[0] || "person";
- }
- }else{
- selectType = type || "person";
- }
- var opt = {
- "type": selectType,
- "types" : selectTypeList,
- "title": options.title,
- "count" : options.count,
- "values": options.selectedValues || [],
- "units" : options.units,
- "unitType" : options.unitType,
- "groups" : options.groups,
- "expand": options.expand,
- "exclude" : options.exclude || [],
- "expandSubEnable" : options.expandSubEnable,
- "onComplete": function( array ){
- if( callback )callback( array );
- }.bind(this)
- };
- if( options.orgOptions ){
- opt = Object.merge(opt, options.orgOptions);
- }
- if( opt.types.length === 0 )opt.types = null;
- var selector = new MWF.O2Selector(container, opt );
- },
- replaceText : function( value, selectValue, selectText, separator ){
- if( typeOf( value ) == "number" )value = [ value ];
- if( typeOf( selectValue ) == "number" )selectValue = [ selectValue ];
- if( typeOf( selectText ) == "number" )selectText = [ selectText ];
- var vals = typeOf( value ) == "array" ? value : value.split( separator );
- var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( separator );
- var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split( separator );
- for( var i=0 ;i<vals.length; i++ ){
- for( var j= 0; j<selectValues.length; j++){
- if( vals[i] == selectValues[j] ){
- vals[i] = selectTexts[j]
- }
- }
- }
- return vals;
- },
- getEvents : function( events ){
- if( !events || events == "" || events == "$none" )return;
- if( typeof events == "string" ){
- if( events.indexOf("^^") > -1 ){
- var eventsArr = events.split("##");
- if( eventsArr[0].split("^^").length != 2 )return;
- events = {};
- for(var i=0;i<eventsArr.length;i++){
- var ename = eventsArr[i].split("^^")[0];
- var efunction = eventsArr[i].split("^^")[1];
- events[ ename ] = eval( "(function(){ return "+ efunction +" })()" ); //字符串变对象或function,方法1
- }
- }else{
- //字符串变对象或function,方法2
- eval( "var events = " + events );
- }
- }
- return events;
- },
- bindEvent: function( obj, item, events){
- events = MDomItem.Util.getEvents( events );
- if( typeOf(events) == "object" ){
- for( var e in events ){
- //jquery的写法
- //item.bind( e, { fun : events[e] }, function( event ){
- //this 是触发事件的对象,self是当前jDomItem对象
- //event.data.fun.call( this, _self );
- //})
- //方法固定,把参数作为this指正传给方法,需要在方法体里通过this获取参数
- //item.addEvent( e, events[e].bind({"item": item, "_self":_self}));
- //参数固定,把方法传入到function中,可以在回调方法中直接获取,和jquery的写法一样
- item.addEvent( e, function(ev){
- this.fun.call( ev ? ev.target : null, obj.module || obj, ev );
- }.bind({fun : events[e]}));
- //不一定行
- //item.addEvent( e, (function(){
- // return function(){
- // events[e].call(item,_self);
- // }
- //})(e));
- }
- // for( var e in events ){
- // if( type && (e=="dblclick" || e=="click") ){
- // if( jQuery.inArray( type , this.unsetClassType) == -1 ){
- // if( !item.attr("title") || item.attr("title") == "" ){
- // item.attr( "title", e=="dblclick" ? "双击选择"+this.options.text : "单击选择"+this.options.text );
- // }
- // item.removeClass("inputtext").addClass("inputclick");
- // break;
- // }
- // }
- // }
- }
- }
- };
- MDomItem.Text = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- },
- load : function(){
- if( this.options.isEdited ){
- this.loadEdit()
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var module = this.module;
- var options = this.options;
- var item;
- var value ;
- if( typeOf( options.value ) === "boolean" ){
- value = options.value.toString();
- }else{
- value = options.value || options.defaultValue
- }
- var parent = module.container ;
- var className = this.getClassName();
- item = new Element( "input", {
- "type" : "text",
- "name" : options.name,
- "value" : value
- });
- var tType = this.options.tType;
- if (tType == "time" || tType == "date" || tType.toLowerCase() == "datetime") {
- item.set("autocomplete", "off");
- }
- item.set( options.attr || {} );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( options.clazz )item.addClass( options.clazz );
- item.setStyles( options.style || {} );
- this.bindDefaultEvent( item );
- MDomItem.Util.bindEvent( this, item, options.event);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- loadRead : function(){
- var module = this.module;
- var options = this.options;
- var item;
- var value;
- var className = this.getClassName();
- var parent = module.container ;
- if( typeOf( options.value ) === "boolean" ){
- value = options.value.toString();
- }else{
- value = options.value || options.defaultValue
- }
- item = new Element( "span", {
- "name" : options.name,
- "text" : value
- });
- item.set( options.attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( options.clazz )item.addClass( options.clazz );
- item.setStyles( options.style || {} );
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){ //value 和 text 或 空
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- if( this.options.isEdited ){
- value = item.get("value");
- }else{
- value = item.get("text");
- }
- if( vort == "value" )return value;
- if( vort == "text")return value;
- return {
- value : value,
- text : value
- };
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- if( this.options.isEdited ){
- item.set( "value", value );
- }else{
- item.set("text", value );
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- if (typeOf(tType) == "array") {
- if (tType.contains("identity") || tType.contains("person") || tType.contains("unit")) {
- className = "inputPerson";
- } else {
- className = "inputText";
- }
- } else {
- if (!tType) {
- className = "inputText";
- } else if (tType == "number") {
- className = "inputText";
- } else if (tType == "time" || tType == "date" || tType.toLowerCase() == "datetime") {
- className = "inputTime";
- } else if (tType == "identity" || tType == "person" || tType.toLowerCase() == "unit") {
- className = "inputPerson";
- } else {
- className = "inputText";
- }
- }
- }
- return className;
- },
- bindDefaultEvent : function( item ){
- if( this.options.unsetDefaultEvent )return;
- var tType = this.options.tType;
- var type = "text";
- if( typeOf( tType ) == "array" || ( tType == "identity" || tType.toLowerCase() == "person" || tType == "unit" ) ){
- item.addEvent( "click" , function(ev){
- this.module.fireEvent("querySelect", this.module );
- var options = this.options;
- var opt = {
- type : tType,
- title : options.text,
- count : options.count,
- selectedValues : this.get("value").split(","),
- units : options.units,
- unitType : options.unitType,
- groups : options.groups,
- expand : options.expand
- };
- MDomItem.Util.selectPerson( this.app.content, opt, function( array ){
- item.empty();
- this.orgData = this.module.orgData = [];
- this.orgObject = this.module.orgObject = array;
- array.each(function( it ){
- this.orgData.push( it.data.distinguishedName || it.data.name );
- }.bind(this));
- item.set("value",this.orgData.join(","));
- this.items[0].fireEvent("change", [this.module, ev]);
- if( this.options.validImmediately )this.module.verify( true );
- }.bind(this))
- }.bind(this) );
- }else{
- if( tType == "number" ){
- item.addEvent( "keyup" , function(){
- this.value=this.value.replace(/[^\d.]/g,'');
- });
- if( this.options.validImmediately ){
- item.addEvent("blur", function(){ this.module.verify( true ); }.bind(this))
- }
- }else if( tType == "time" || tType.toLowerCase() == "datetime" || tType == "date" ){
- item.addEvent( "click" , function(ev){
- this.module.fireEvent("querySelect", this.module );
- if( this.calendarSelector ){
- this.calendarSelector.show();
- }else{
- this.calendarSelector = MDomItem.Util.selectCalendar( item, this.app.content, {
- calendarOptions : this.options.calendarOptions,
- type : tType
- }, function( dateString, date ){
- this.items[0].fireEvent("change", [this.module, ev]);
- if( this.options.validImmediately )this.module.verify( true );
- }.bind(this) )
- }
- }.bind(this) );
- }else{
- if( this.options.validImmediately ){
- item.addEvent("blur", function(){ this.module.verify( true ); }.bind(this))
- }
- }
- }
- }
- });
- MDomItem.Textarea = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- },
- load : function(){
- if( this.options.isEdited ){
- this.loadEdit()
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var module = this.module;
- var options = this.options;
- var item;
- var value ;
- if( typeOf( options.value ) === "boolean" ){
- value = options.value.toString();
- }else{
- value = options.value || options.defaultValue
- }
- var parent = module.container ;
- var className = this.getClassName();
- item = new Element( "textarea", {
- "name" : options.name,
- "value" : value
- });
- item.set( options.attr || {} );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( options.clazz )item.addClass( options.clazz );
- item.setStyles( options.style || {} );
- this.bindDefaultEvent( item );
- MDomItem.Util.bindEvent( this, item, options.event);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- loadRead : function(){
- var module = this.module;
- var options = this.options;
- var item;
- var value;
- var className = this.getClassName();
- var parent = module.container ;
- if( typeOf( options.value ) === "boolean" ){
- value = options.value.toString();
- }else{
- value = options.value || options.defaultValue
- }
- item = new Element( "span", {
- "name" : options.name,
- "text" : value
- });
- item.set( options.attr || {} );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( options.clazz )item.addClass( options.clazz );
- item.setStyles( options.style || {} );
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- bindDefaultEvent : function( item ){
- if( this.options.unsetDefaultEvent )return;
- if( this.options.validImmediately ){
- item.addEvent("blur", function(){ this.module.verify( true ); }.bind(this))
- }
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- if( this.options.isEdited ){
- value = item.get("value");
- }else{
- value = item.get("text");
- }
- if( vort == "value" )return value;
- if( vort == "text")return value;
- return {
- value : value,
- text : value
- };
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- if( this.options.isEdited ){
- item.set( "value", value );
- }else{
- item.set("text", value );
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputTextarea"
- }
- return className;
- }
- });
- MDomItem.Hidden = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- },
- load : function(){
- var parent = this.container;
- var item = new Element( "input", {
- "type" : "hidden",
- "name" : this.options.name,
- "value" : this.options.value
- });
- item.set( this.options.attr || {} );
- //this.bindEvent(item,event,type);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- if( this.options.isEdited ){
- value = item.get("value");
- }else{
- value = item.get("text");
- }
- if( vort == "value" )return value;
- if( vort == "text")return value;
- return {
- value : value,
- text : value
- };
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- item.set( "value", value );
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- }
- });
- MDomItem.Password = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- },
- load : function(){
- if( this.options.isEdited ){
- this.loadEdit()
- }else{
- }
- },
- loadEdit : function(){
- var module = this.module;
- var options = this.options;
- var item;
- var value ;
- if( typeOf( options.value ) === "boolean" ){
- value = options.value.toString();
- }else{
- value = options.value || options.defaultValue
- }
- var parent = module.container ;
- var className = this.getClassName();
- item = new Element( "input", {
- "type" : "password",
- "name" : options.name,
- "value" : value
- });
- item.set( options.attr || {} );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( options.clazz )item.addClass( options.clazz );
- item.setStyles( options.style || {} );
- this.bindDefaultEvent( item );
- MDomItem.Util.bindEvent( this, item, options.event);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- loadRead : function(){
- },
- bindDefaultEvent : function( item ){
- if( this.options.unsetDefaultEvent )return;
- if( this.options.validImmediately ){
- item.addEvent("blur", function(){ this.module.verify( true ); }.bind(this))
- }
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- if( this.options.isEdited ){
- value = item.get("value");
- }else{
- value = this.options.value || this.options.defaultValue
- }
- if( vort == "value" )return value;
- if( vort == "text")return value;
- return {
- value : value,
- text : value
- };
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- if( this.options.isEdited ){
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- item.set( "value", value );
- }else{
- this.options.value = value;
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputPassword"
- }
- return className;
- }
- });
- MDomItem.Radio = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( !this.options.selectValue && this.options.selectText )this.options.selectValue = this.options.selectText;
- if( !this.options.selectText && this.options.selectValue )this.options.selectText = this.options.selectValue;
- if( this.options.isEdited ){
- this.loadEdit();
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var _self = this;
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var event = this.options.event;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName() ;
- var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( this.valSeparator );
- var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split(this.valSeparator);
- for( i=0;i<selectValues.length;i++){
- item = new Element( "div");
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( this.options.clazz )item.addClass( this.options.clazz );
- item.setStyles( styles );
- var input = new Element( "input", {
- "type" : "radio",
- "name" : name,
- "value" : selectValues[i],
- "checked" : selectValues[i] == value
- }).inject( item );
- input.set( attr );
- var textNode = new Element( "span", {
- "text" : selectTexts[i]
- }).inject(item);
- textNode.addEvent("click", function (ev) {
- if( _self.options.attr && _self.options.attr.disabled )return;
- this.input.checked = !this.input.checked;
- var envents = MDomItem.Util.getEvents(_self.options.event);
- if (typeOf(envents) == "object") {
- if (envents.change) {
- envents.change.call(this.input, _self.module, ev);
- }
- if (envents.click) {
- envents.click.call(this.input, _self.module, ev);
- }
- }
- if (_self.options.validImmediately) {
- _self.module.verify(true);
- }
- }.bind({input: input}));
- if( this.options.validImmediately ){
- input.addEvent( "click", function(){ this.module.verify( true )}.bind(this) );
- }
- MDomItem.Util.bindEvent( this, item, event ); //? input or item
- if(parent)item.inject(parent);
- this.items.push( item );
- }
- },
- loadRead : function(){
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName() ;
- if( selectValue && selectText ){
- value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
- value = value.join(",");
- }
- item = new Element( "span", {
- "name" : name,
- "text" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( this.options.clazz )item.addClass( this.options.clazz );
- item.setStyles( styles );
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var items;
- var name = this.options.name;
- items = this.mElement.getElements("[name='"+name+"']");
- if( this.options.isEdited ){
- items.each(function( el ){
- if( el.checked ){
- value = el.get("value");
- text = el.getParent().get("text").trim();
- }
- });
- }else{
- text = items[0].get("text");
- if( this.options.selectValue && this.options.selectText ){
- value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator).join();
- }else{
- value = text;
- }
- }
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var items= this.mElement.getElements("[name='"+ this.options.name + "']");
- if( this.options.isEdited ){
- items.each(function( el ){
- if( el.get("value") == value ) el.checked = true;
- });
- }else{
- value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
- value = value.join(",");
- items[0].set("text", value );
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputRadio"
- }
- return className;
- }
- });
- MDomItem.Checkbox = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( !this.options.selectValue && this.options.selectText )this.options.selectValue = this.options.selectText;
- if( !this.options.selectText && this.options.selectValue )this.options.selectText = this.options.selectValue;
- if( this.options.isEdited ){
- this.loadEdit();
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var _self = this;
- var item;
- var values;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var event = this.options.event;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var isEdited = this.options.isEdited;
- var parent = this.mElement = this.container ;
- var className = this.getClassName();
- values = typeOf( value ) == "string" ? value.split(this.valSeparator) : value ;
- values = typeOf( value ) == "array" ? value : [value];
- var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( this.valSeparator );
- var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split(this.valSeparator);
- for( var i=0;i<selectValues.length;i++){
- item = new Element( "div");
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( this.options.clazz )item.addClass( this.options.clazz );
- item.setStyles( styles );
- var input = new Element( "input", {
- "type" : "checkbox",
- "name" : name,
- "value" : selectValues[i],
- "checked" : values.contains( selectValues[i] )
- }).inject( item );
- input.set( attr );
- var textNode = new Element( "span", {
- "text" : selectTexts[i]
- }).inject(item);
- textNode.addEvent("click", function( ev ){
- if( _self.options.attr && _self.options.attr.disabled )return;
- this.input.checked = ! this.input.checked;
- var envents = MDomItem.Util.getEvents( _self.options.event );
- if( typeOf( envents ) == "object" ){
- if( envents.change ){
- envents.change.call( this.input, _self.module, ev );
- }
- if( envents.click ){
- envents.click.call( this.input, _self.module, ev );
- }
- }
- if( _self.options.validImmediately ){
- _self.module.verify( true );
- }
- }.bind( {input : input} ) );
- if( this.options.validImmediately ){
- item.addEvent("click", function(){ this.module.verify( true ); }.bind(this))
- }
- MDomItem.Util.bindEvent( this, item, event); // ? input or item
- if(parent)item.inject(parent);
- this.items.push( item );
- }
- },
- loadRead : function(){
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.mElement = this.container ;
- var className = this.getClassName();
- if( selectValue && selectText ){
- value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
- value = value.join(",");
- }
- item = new Element( "span", {
- "name" : name,
- "text" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( this.options.clazz )item.addClass( this.options.clazz );
- item.setStyles( styles );
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var items;
- var name = this.options.name;
- items = this.mElement.getElements("[name='"+name+"']");
- if( this.options.isEdited ){
- value = [];
- text = [];
- items.each(function( el ){
- if( el.checked ){
- value.push(el.get("value"));
- text.push( el.getParent().get("text").trim() )
- }
- });
- }else{
- text = items[0].get("text");
- if( this.options.selectValue && this.options.selectText ){
- value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue, this.valSeparator );
- }else{
- value = text;
- }
- }
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var items= this.mElement.getElements("[name='"+ this.options.name + "']");
- if( this.options.isEdited ){
- var values = typeOf( value ) == "array" ? value : value.split("^^");
- items.each(function( el ){
- if( values.contains( el.get("value") ) ){
- el.checked = true;
- }else{
- el.checked = false;
- }
- });
- }else{
- value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
- value = value.join(",");
- items[0].set("text", value );
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputCheckbox"
- }
- return className;
- }
- });
- MDomItem.Select = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( !this.options.selectValue && this.options.selectText )this.options.selectValue = this.options.selectText;
- if( !this.options.selectText && this.options.selectValue )this.options.selectText = this.options.selectValue;
- if( this.options.disable )return;
- if( this.options.isEdited ){
- this.loadEdit();
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var event = this.options.event;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName() ;
- item = new Element( "select" , {
- "name" : name
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( this.valSeparator );
- var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split(this.valSeparator);
- for( i=0;i<selectValues.length;i++){
- new Element("option" , {
- "value" : selectValues[i],
- "selected" : selectValues[i] == value,
- "text" : selectTexts[i]
- }).inject(item)
- }
- if( this.options.validImmediately ){
- item.addEvent("change", function(){ this.module.verify( true ); }.bind(this))
- }
- MDomItem.Util.bindEvent( this, item, event);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- loadRead : function(){
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.mElement = this.container ;
- var className = this.getClassName();
- if( selectValue && selectText ){
- value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
- value = value.join(",");
- }
- item = new Element( "span", {
- "name" : name,
- "text" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( this.options.clazz )item.addClass( this.options.clazz );
- item.setStyles( styles );
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var items;
- var name = this.options.name;
- items = this.mElement.getElements("[name='"+name+"']");
- if( this.options.isEdited ){
- items[0].getElements("option").each(function(el){
- if( el.selected ){
- value = el.get("value");
- text = el.get("text").trim();
- }
- });
- }else{
- text = items[0].get("text");
- if( this.options.selectValue && this.options.selectText ){
- value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator).join();
- }else{
- value = text;
- }
- }
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var items= this.mElement.getElements("[name='"+ this.options.name + "']");
- if( this.options.isEdited ){
- items[0].getElements("option").each(function( el ){
- if( el.get("value") == value ) el.selected = true;
- });
- }else{
- value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
- value = value.join(",");
- items[0].set("text", value );
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputSelect"
- }
- return className;
- }
- });
- MDomItem.Multiselect = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( !this.options.selectValue && this.options.selectText )this.options.selectValue = this.options.selectText;
- if( !this.options.selectText && this.options.selectValue )this.options.selectText = this.options.selectValue;
- if( this.options.disable )return;
- if( this.options.isEdited ){
- this.loadEdit();
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var item;
- var values;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var event = this.options.event;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName() ;
- values = typeOf( value ) == "string" ? value.split(this.valSeparator) : value ;
- values = typeOf( value ) == "array" ? value : [value];
- item = new Element( "select" , {
- "name" : name,
- "multiple" : true
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( this.options.clazz )item.addClass( this.options.clazz );
- item.setStyles( styles );
- var selectValues = typeOf( selectValue ) == "array" ? selectValue : selectValue.split( this.valSeparator );
- var selectTexts = typeOf( selectText ) == "array" ? selectText : selectText.split(this.valSeparator);
- for( i=0;i<selectValues.length;i++){
- new Element("option" , {
- "value" : selectValues[i],
- "selected" : values.contains( selectValues[i] ),
- "text" : selectTexts[i]
- }).inject(item)
- }
- if( this.options.validImmediately ){
- item.addEvent("change", function(){ this.module.verify( true ); }.bind(this))
- }
- MDomItem.Util.bindEvent( this, item, event);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- loadRead : function(){
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName();
- if( selectValue && selectText ){
- value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
- value = value.join(",");
- }
- item = new Element( "span", {
- "name" : name,
- "text" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var items;
- var name = this.options.name;
- items = this.mElement.getElements("[name='"+name+"']");
- if( this.options.isEdited ){
- value = [];
- text = [];
- items[0].getElements("option").each(function(el){
- if( el.selected ){
- value.push( el.get("value") );
- text.push( el.get("text").trim() );
- }
- });
- }else{
- text = items[0].get("text");
- if( this.options.selectValue && this.options.selectText ){
- value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator );
- }else{
- value = text;
- }
- }
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var items= this.mElement.getElements("[name='"+ this.options.name + "']");
- if( this.options.isEdited ){
- var values = typeOf( value ) == "array" ? value : value.split("^^");
- items[0].getElements("option").each(function( el ){
- if( values.contains( el.get("value") ) ){
- el.selected = true;
- }else{
- el.selected = false;
- }
- })
- }else{
- value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
- value = value.join(",");
- items[0].set("text", value );
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputMultiselect"
- }
- return className;
- }
- });
- MDomItem.Innertext = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( this.options.disable )return;
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.mElement = this.container ;
- var className = this.getClassName();
- if( selectValue && selectText ){
- value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
- value = value.join(",");
- }
- item = new Element( "span", {
- "name" : name,
- "text" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( this.options.clazz )item.addClass( this.options.clazz );
- item.setStyles( styles );
- if( this.options.isEdited ){
- MDomItem.Util.bindEvent( this, item, this.options.event);
- }
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- text = item.get("text");
- if( this.options.selectValue && this.options.selectText ){
- value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator);
- }else{
- value = text;
- }
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
- value = value.join(",");
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- item.set("text", value );
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- }
- return className;
- }
- });
- MDomItem.Innerhtml = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( this.options.disable )return;
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.mElement = this.container ;
- var className = this.getClassName();
- if( selectValue && selectText ){
- value = MDomItem.Util.replaceText( value, selectValue , selectText, this.valSeparator );
- value = value.join(",");
- }
- item = new Element( "span", {
- "name" : name,
- "html" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- if( this.options.clazz )item.addClass( this.options.clazz );
- item.setStyles( styles );
- if( this.options.isEdited ){
- MDomItem.Util.bindEvent( this, item, this.options.event);
- }
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- text = item.get("html");
- if( this.options.selectValue && this.options.selectText ){
- value = MDomItem.Util.replaceText( text, this.options.selectText , this.options.selectValue , this.valSeparator );
- }else{
- value = text;
- }
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- value = MDomItem.Util.replaceText( value, this.options.selectValue , this.options.selectText, this.valSeparator );
- value = value.join(",");
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- item.set("html", value );
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- }
- return className;
- }
- });
- MDomItem.Img = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.items = module.items;
- this.container = this.mElement = module.container;
- },
- load : function(){
- if( this.options.disable )return;
- var item;
- var name = this.options.name;
- var value = this.options.value || this.options.defaultValue ;
- var event = this.options.event;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName();
- item = new Element( "img", {
- "name" : name,
- "src" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- MDomItem.Util.bindEvent( this, item, event);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- value = item.get("src");
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- item.set("src",value);
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var tType = this.options.tType;
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- }
- return className;
- }
- });
- MDomItem.Button = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.items = module.items;
- this.container = this.mElement = module.container;
- },
- load : function(){
- if( this.options.disable )return;
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var event = this.options.event;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName() ;
- item = new Element( "button", {
- "type" : "button",
- "name" : name,
- "value" : value,
- "text" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- MDomItem.Util.bindEvent( this, item, event);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- value = item.get("value");
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var item= this.mElement.getElement("[name='"+ this.options.name + "']");
- item.set( "value", value );
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputButton"
- }
- return className;
- }
- });
- MDomItem.A = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.items = module.items;
- this.container = this.mElement = module.container;
- },
- load : function(){
- if( this.options.disable )return;
- var item;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var event = this.options.event;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName() ;
- item = new Element( "a", {
- "name" : name,
- "value" : value,
- "text" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- MDomItem.Util.bindEvent( this, item, event);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- var name = this.options.name;
- var item = this.mElement.getElement("[name='"+name+"']");
- value = item.get("value");
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var item= this.mElement.getElement("[name='"+ this.options.name + "']");
- item.set( "value", value );
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputA"
- }
- return className;
- }
- });
- MDomItem.MSelector = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( this.options.disable )return;
- MWF.xDesktop.requireApp("Template", "MSelector",null,false);
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var selectValue = this.options.selectValue || this.options.selectText;
- var selectText = this.options.selectText || this.options.selectValue ;
- this.mSelectorOptions = {
- "style": "default",
- "width": "230px",
- "height": "30px",
- "defaultOptionLp" : MWF.xApplication.Template.LP.MDomItem.defaultOption,
- "trigger" : "delay", //immediately
- "isSetSelectedValue" : true,
- "inputEnable" : false,
- "isCreateReadNode" : false, //适应给MDomItem的做法
- "textField" : "",
- "valueField" : "",
- "value" : value,
- "text" : "",
- "defaultVaue" : this.options.defaultValue,
- "selectValue" : selectValue,
- "selectText" : selectText,
- "isEdited" : this.options.isEdited
- //"onSelectItem" : function( itemNode, itemData ){}.bind(this)
- //"onLoadData" :function( callback ){}.bind(this)
- };
- if( this.options.mSelectorOptions ){
- this.mSelectorOptions = Object.merge( this.mSelectorOptions, this.options.mSelectorOptions );
- }
- this.mSelectorOptions.value = value;
- if( !this.options.isEdited ){
- var name = this.options.name;
- var item;
- var attr = this.options.attr || {};
- var className = this.getClassName();
- var styles = this.options.style || {};
- var parent = this.container;
- this.mSelectorOptions.onLoadReadNode = function( text ){
- if( this.items.length > 0 ){
- parent.empty();
- }
- item = new Element( "span", {
- "name" : name,
- "text" : text
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- if(parent)item.inject(parent);
- this.items.push( item );
- }.bind(this);
- }
- this.mSelector = new MSelector(this.container, this.mSelectorOptions , this.app , this.css);
- this.mSelector.load();
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- if( vort == "value" )return this.mSelector.getValue();
- if( vort == "text")return this.mSelector.getText();
- return this.mSelector.get();
- },
- setValue : function( value ){
- this.mSelector.setValue( value );
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- }
- return className;
- }
- });
- MDomItem.ImageClipper = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( this.options.disable )return;
- if( this.options.isEdited ){
- this.loadEdit();
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var item;
- var values;
- var name = this.options.name;
- var value ;
- if( typeOf( this.options.value ) === "boolean" ){
- value = this.options.value.toString();
- }else{
- value = this.options.value || this.options.defaultValue
- }
- var styles = this.options.style || {};
- var parent = this.container ;
- this.imageId = this.module.imageId = value;
- if( value && parent ){
- if( styles.imageWrapStyle ){
- this.imageWrap = new Element("div", { styles : styles.imageWrapStyle}).inject( parent )
- }
- this.image = new Element("img", {
- "src" : MWF.xDesktop.getImageSrc( value )
- }).inject( this.imageWrap || parent );
- this.image.addEvent("click",function(){
- window.open( o2.filterUrl(MWF.xDesktop.getImageSrc( this.imageId )), "_blank" );
- }.bind(this));
- if( styles.imageStyle )this.image.setStyles( styles.imageStyle );
- }
- var action = new Element("button",{
- "text" : MWF.xApplication.Template.LP.MDomItem.setPicture
- }).inject( parent );
- //if( this.css && this.css["inputButton"] )action.setStyles( this.css["inputButton"] );
- if( styles.actionStyle )action.setStyles( styles.actionStyle );
- action.addEvents({
- "click": function(){
- MWF.xDesktop.requireApp("Template", "widget.ImageClipper",null,false);
- this.clipper = new MWF.xApplication.Template.widget.ImageClipper(this.app, {
- "imageUrl": value ? MWF.xDesktop.getImageSrc( value ) : "",
- "aspectRatio": this.options.aspectRatio || 0,
- "ratioAdjustedEnable" : this.options.ratioAdjustedEnable || false,
- "reference": this.options.reference,
- "referenceType": this.options.referenceType,
- "onChange": function () {
- if( this.image )this.image.destroy();
- if(this.imageWrap)this.imageWrap.destroy();
- if( styles.imageWrapStyle ){
- this.imageWrap = new Element("div", { styles : styles.imageWrapStyle}).inject( parent, "top" )
- }
- this.image = new Element("img", {
- "src" : this.clipper.imageSrc
- }).inject( this.imageWrap || parent, "top" );
- if( styles.imageStyle )this.image.setStyles( styles.imageStyle );
- this.image.addEvent("click",function(){
- window.open( o2.filterUrl(MWF.xDesktop.getImageSrc( this.imageId )), "_blank" );
- }.bind(this));
- this.imageId = this.module.imageId = this.clipper.imageId;
- if( this.options.validImmediately ){
- this.module.verify( true )
- }
- }.bind(this)
- });
- this.clipper.load();
- }.bind(this)
- });
- },
- loadRead : function(){
- var value = this.options.value || this.options.defaultValue ;
- var parent = this.container ;
- this.imageId = this.module.imageId = value;
- if( value && parent ){
- this.image = new Element("img", {
- "src" : MWF.xDesktop.getImageSrc( value )
- }).inject( parent );
- var styles = this.options.style || {};
- if( styles.imageStyle )this.image.setStyles( styles.imageStyle );
- }
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var items;
- var value = this.imageId;
- if( vort == "value" )return value;
- if( vort == "text")return value;
- var result = {};
- result.value = value;
- result.text = value;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var styles = this.options.style || {};
- this.imageId = this.module.imageId = value;
- if( value ){
- if( this.image ){
- this.image.set("src", MWF.xDesktop.getImageSrc( value ))
- }else{
- if( styles.imageWrapStyle ){
- this.imageWrap = new Element("div", { styles : styles.imageWrapStyle}).inject( this.container )
- }
- this.image = new Element("img", {
- "src" : MWF.xDesktop.getImageSrc( value )
- }).inject( this.imageWrap || this.container );
- if( styles.imageStyle )this.image.setStyles( styles.imageStyle );
- }
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.uploadPictureNotice+":"+this.options.text ;
- }
- });
- MDomItem.Rtf = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( this.options.disable )return;
- if( this.options.isEdited ){
- this.loadEdit();
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var _self = this;
- var item;
- var name = this.options.name;
- var value = this.options.value || this.options.defaultValue ;
- var attr = this.options.attr || {};
- var parent = this.container ;
- window.COMMON.AjaxModule.load("ckeditor", function(){
- CKEDITOR.disableAutoInline = true;
- var item = new Element("div",{
- "name" : name,
- "id" : name
- });
- item.set( attr );
- if(parent)item.inject(parent);
- if( value )item.set("html", value);
- var editorConfig = {
- //"autoGrow_maxHeight": 400,
- //"autoGrow_minHeight": 300,
- "resize_enabled": true,
- //"resize_maxHeight": "3000",
- //"resize_minHeight": "200",
- "autoParagraph": true,
- "autoUpdateElement": true,
- "enterMode": 1,
- //"height": "200",
- //"width": "",
- "readOnly": false,
- "language": MWF.language || "zh-cn",
- "enablePreview": true,
- "removePlugins": ['image','easyimage','exportpdf','cloudservices'],
- "extraPlugins": [ 'lineheight','o2image','o2uploadimage','o2uploadremoteimage']
- // "extraAllowedContent " : "img[onerror,data-id]"
- };
- if( this.options.RTFConfig ){
- editorConfig = Object.merge( editorConfig, this.options.RTFConfig )
- }
- if( editorConfig.skin )editorConfig.skin = "moono-lisa";
- if( !editorConfig.filebrowserFilesImage && !editorConfig.cloudFileDisable ){
- editorConfig.filebrowserFilesImage = function( e, callback ){
- MWF.xDesktop.requireApp("File", "FileSelector", function(){
- _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
- "style" : "default",
- "title": MWF.xApplication.Template.LP.MDomItem.selectCoundPicture,
- "toBase64" : true,
- "listStyle": "preview",
- "selectType" : "images",
- "onPostSelectAttachment" : function(url, base64File){
- if(callback)callback(url, base64File);
- }
- });
- _self.selector_cloud.load();
- }, true);
- }
- }
- this.editor = this.module.editor = CKEDITOR.replace(item, editorConfig);
- var imgSrc = MWF.xDesktop.getImageSrc();
- var imgHost = imgSrc.split("/x_file_assemble_control/")[0];
- debugger;
- this.editor.on("instanceReady", function(e){
- debugger;
- var editable = e.editor.editable && e.editor.editable();
- if(!editable)return;
- var imgs = editable.find("img");
- for( var i=0; i<imgs.count(); i++ ){
- var img = imgs.getItem(i);
- var src = img.getAttribute("src");
- if( src && src.indexOf("/x_file_assemble_control/") > -1 ){
- if( imgHost !== src.split("/x_file_assemble_control/")[0] ){
- var id = img.getAttribute("data-id");
- if( id ){
- var newSrc = MWF.xDesktop.getImageSrc(id);
- if(newSrc){
- img.setAttribute("src" , newSrc );
- img.setAttribute("data-cke-saved-src" , newSrc );
- }
- }
- }
- }
- }
- });
- this.items.push( this.editor );
- }.bind(this));
- },
- loadRead : function(){
- var _self = this;
- var item;
- var name = this.options.name;
- var value = this.options.value || this.options.defaultValue ;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = null ;
- item = new Element( "span", {
- "name" : name
- // "html" : value
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- if(parent)item.inject(parent);
- this.loadLazyImage(item, value, function(){
- if( window.layout && layout.mobile ){
- }else if( this.options.enablePreview ) {
- this.loadImageViewer(item);
- }else if( this.options.RTFConfig && this.options.RTFConfig.enablePreview === false) {
- }else{
- this.loadImageViewer(item);
- }
- }.bind(this));
- this.items.push( item );
- },
- getAttrRegExp: function( attr ){
- return "\\s+" + attr + "\\s*=\\s*[\"|\'](.*?)[\"|\']";
- },
- getAttributeValue: function(str, attribute){
- var regexp = new RegExp( this.getAttrRegExp(attribute) , "i");
- var array = str.match( regexp );
- return (o2.typeOf(array) === "array" && array.length === 2) ? array[1] : "";
- },
- addAttribute: function(str, attribute, value){
- var regexp = new RegExp( "\\/*\\s*>" , "i");
- return str.replace( regexp, ' ' + attribute + '="' + value + '"' + " />");
- },
- removeAttribute: function(str, attribute){
- var regexp = new RegExp( this.getAttrRegExp(attribute) , "ig");
- return str.replace( regexp, "" );
- },
- parseHtml: function(html){
- html = this.replaceHrefJavascriptStr(html);
- html = this.replaceOnAttribute(html);
- html = this.parseOnerror(html);
- return html;
- },
- parseOnerror: function(html){
- var regexp_all = /(i?)(<img)([^>]+>)/gmi;
- var images = html.match(regexp_all);
- if(images){
- if (images.length){
- for (var i=0; i<images.length; i++){
- var image = images[i];
- var image1 = this.removeAttribute(image, "onerror");
- image1 = this.addAttribute(image1, "onerror", "MWF.xDesktop.setImageSrc()");
- html = html.replace(image, image1);
- }
- }
- }
- return html;
- },
- replaceHrefJavascriptStr: function( html ){
- var regexp_a_all = /(i?)(<a)([^>]+>)/gmi;
- var as = html.match(regexp_a_all);
- if(as){
- if (as.length){
- for (var i=0; i<as.length; i++){
- var a = as[i];
- var href = this.getAttributeValue(a, "href");
- if( href.indexOf('javascript:') > -1 ){
- var a1 = this.removeAttribute(a, "href");
- html = html.replace(a, a1);
- }
- }
- }
- }
- return html;
- },
- replaceOnAttribute: function (htmlString){
- var tempDiv = document.createElement('div');
- tempDiv.innerHTML = htmlString;
- var elements = tempDiv.getElementsByTagName('*');
- for (var i = 0; i < elements.length; i++) {
- var element = elements[i];
- var attributeNames = element.getAttributeNames();
- for (var j = 0; j < attributeNames.length; j++) {
- var attributeName = attributeNames[j];
- if (attributeName.substr(0,2).toLowerCase() === 'on') {
- element.removeAttribute(attributeName);
- }
- }
- }
- return tempDiv.innerHTML;
- },
- loadLazyImage: function(node, html, callback){
- if( this.options && this.options.imageLazyLoading) {
- o2.require("o2.widget.ImageLazyLoader", null, false);
- var loadder = new o2.widget.ImageLazyLoader(node, html);
- loadder.load(function () {
- if (callback) callback();
- }.bind(this));
- }else{
- node.set("html", this.parseHtml(html));
- if (callback) callback();
- }
- },
- loadImageViewer: function(node){
- o2.require("o2.widget.ImageViewer", null, false);
- var imageViewer = new o2.widget.ImageViewer(node);
- imageViewer.load();
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value;
- var text;
- if( this.options.isEdited ){
- if( this.options.RTFConfig && this.options.RTFConfig.isSetImageMaxWidth ){
- var div = new Element( "div" , {
- "styles" : { "display" : "none" },
- "html" : this.editor.getData()
- } ).inject( this.container );
- div.getElements( "img").each( function( el ){
- el.setStyle( "max-width" , "100%" );
- });
- value = div.get("html");
- div.destroy();
- }else{
- value = this.editor.getData();
- }
- }else{
- var item = this.mElement.getElement("[name='"+name+"']");
- value = item.get("html");
- }
- if( !value )value="";
- if( !text )text = value;
- if( vort == "value" )return value;
- if( vort == "text")return text;
- var result = {};
- result.value = value;
- result.text = text;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- if( this.options.isEdited ){
- this.editor.setData(value);
- }else{
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- item.set("html", value );
- }
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.emptyTip.replace("{text}",this.options.text);
- },
- getClassName : function(){
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- }
- return className;
- }
- });
- MDomItem.Org = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( this.options.disable )return;
- if( this.options.isEdited ){
- this.loadEdit();
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- var item;
- var name = this.options.name;
- var value = this.options.value || this.options.defaultValue ;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName() ;
- if( !value ){
- this.orgData = [];
- }else if( typeOf( value ) == "array" ){
- this.orgData = value;
- }else if( typeOf( value ) == "string" ){
- this.orgData = value.split( this.valSeparator )
- }else if( typeOf( value ) == "object" ){
- this.orgData = [value]
- }else{
- this.orgData = [];
- }
- item = new Element( "div", {
- "name" : name
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- this.loadOrgWidget( this.orgData, item, true );
- this.bindDefaultEvent( item );
- MDomItem.Util.bindEvent( this, item, this.options.event );
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- loadRead : function(){
- var item;
- var name = this.options.name;
- var value = this.options.value || this.options.defaultValue;
- var styles = this.options.style || {};
- var attr = this.options.attr || {};
- var parent = this.container ;
- var className = this.getClassName();
- if( !value ){
- this.orgData = [];
- }else if( typeOf( value ) == "array" ){
- this.orgData = value;
- }else if( typeOf( value ) == "string" ){
- this.orgData = value.split( this.valSeparator )
- }else{
- this.orgData = [];
- }
- this.module.orgData = this.orgData;
- item = new Element( "div", {
- "name" : name
- });
- item.set( attr );
- if( className && this.css && this.css[className] )item.setStyles( this.css[className] );
- item.setStyles( styles );
- if( this.options.clazz )item.addClass( this.options.clazz );
- this.loadOrgWidget( this.orgData, item , false);
- if(parent)item.inject(parent);
- this.items.push( item );
- },
- reset: function(){
- this.setValue( this.options.defaultValue || [] );
- },
- getData : function( parse ){
- var data = [];
- this.OrgWidgetList.each( function( widget ){
- data.push( parse ? MWF.org.parseOrgData(widget.data, true) : widget.data );
- }.bind(this));
- return data;
- },
- get : function( vort ){
- if( this.options.disable ){
- return ( vort == "value" || vort == "text" ) ? null : {
- value : null,
- text : null
- };
- }
- var value = this.orgData;
- if( vort == "value" )return value;
- if( vort == "text")return value;
- var result = {};
- result.value = value;
- result.text = value;
- return result;
- },
- setValue : function( value ){
- if( this.options.disable ){
- return;
- }
- var item = this.mElement.getElement("[name='"+ this.options.name + "']");
- if( !value ){
- this.orgData = [];
- }else if( typeOf( value ) == "array" ){
- this.orgData = value;
- }else if( typeOf( value ) == "string" ){
- this.orgData = value.split( this.valSeparator );
- }else{
- this.orgData = [];
- }
- this.orgObjData = null;
- item.empty();
- this.loadOrgWidget( this.orgData, item, this.options.isEdited );
- this.module.orgData = this.orgData
- },
- getErrorText : function(){
- return MWF.xApplication.Template.LP.MDomItem.selectTip.replace("{text}",this.options.text);
- },
- bindDefaultEvent : function( item ){
- if( this.options.unsetDefaultEvent )return;
- item.addEvent( "click" , function( ev ){
- debugger;
- this.module.fireEvent("querySelect", this.module );
- var options = this.options;
- var opt = {
- type : options.orgType,
- title : options.text,
- count : options.count,
- selectedValues : this.orgObjData || this.orgData,
- units : options.units,
- unitType : options.unitType,
- groups : options.groups,
- expand : options.expand,
- exclude : options.exclude,
- expandSubEnable : options.expandSubEnable
- };
- if( this.options.orgOptions ){
- opt.orgOptions = this.options.orgOptions;
- }
- MDomItem.Util.selectPerson( this.app.content, opt, function( array ){
- item.empty();
- this.orgData = this.module.orgData = [];
- this.orgObjData = [];
- this.orgObject = this.module.orgObject = array;
- array.each(function( it ){
- this.orgData.push( it.data.distinguishedName || it.data.name );
- this.orgObjData.push( it.data );
- }.bind(this));
- this.OrgWidgetList = [];
- this.loadOrgWidget( this.orgObjData, item, true );
- this.modified = true;
- this.items[0].fireEvent("change", [this.module, ev]);
- if( this.options.validImmediately )this.module.verify( true );
- }.bind(this))
- }.bind(this) );
- },
- getValueByType : function( type ){
- var types = typeOf( type ) == "string" ? type.split(",") : type;
- types = types.map( function( item, index ){
- switch (item.toLowerCase()) {
- case "person": return "p";
- case "identity": return "i";
- case "unit": return "u";
- case "group": return "g";
- case "role": return "r";
- default: return item.toLowerCase();
- }
- });
- var value = [];
- this.get("value").each( function( v ){
- var flag = v.substr(v.length-1, 1);
- if( types.contains( flag.toLowerCase() ) )value.push( v );
- });
- return value;
- },
- loadOrgWidget: function(value, node, canRemove){
- this.OrgWidgetList = this.OrgWidgetList || [];
- MWF.require("MWF.widget.O2Identity", null, false);
- var options = { "style": this.options.orgStyle || "xform", "canRemove": canRemove , "onRemove" : this.removeOrgItem, "lazy": true };
- if( this.options.orgWidgetOptions ){
- options = Object.merge( options, this.options.orgWidgetOptions );
- }
- value.each(function( v ){
- var data;
- var distinguishedName;
- if( typeOf(v) === "string" ){
- distinguishedName = v;
- if( distinguishedName.indexOf("@") > 0 ){
- data = {
- "distinguishedName" : distinguishedName,
- "name": distinguishedName.split("@")[0]
- }
- }else{
- data = {
- "id" : distinguishedName,
- "name": distinguishedName.split("@")[0]
- }
- }
- }else{
- distinguishedName = v.distinguishedName || v.name || "";
- if( !v.name )v.name = distinguishedName.split("@")[0];
- data = v;
- }
- var flag = distinguishedName.substr(distinguishedName.length-1, 1);
- switch (flag.toLowerCase()){
- case "i":
- var widget = new MWF.widget.O2Identity( data, node, options );
- break;
- case "p":
- var widget = new MWF.widget.O2Person(data, node, options);
- break;
- case "u":
- var widget = new MWF.widget.O2Unit(data, node, options);
- break;
- case "g":
- var widget = new MWF.widget.O2Group(data, node, options);
- break;
- //case "d":
- // var widget = new MWF.widget.O2Duty(data, node, options);
- // break;
- default:
- var orgType = this.options.orgType;
- var t = ( typeOf( orgType ) == "array" && orgType.length == 1 ) ? orgType[0] : orgType;
- t = typeOf( t ) == "string" ? t.toLowerCase() : "";
- if( t == "identity" ){
- var widget = new MWF.widget.O2Identity( data, node, options );
- }else if( t == "person" ){
- var widget = new MWF.widget.O2Person(data, node, options);
- }else if( t == "unit" ){
- var widget = new MWF.widget.O2Unit(data, node, options);
- }else if( t == "group" ){
- var widget = new MWF.widget.O2Group(data, node, options);
- }else if( t == "process" ){
- // var d = { id : distinguishedName };
- if( data.id === data.name )delete data.name;
- var widget = new MWF.widget.O2Process(data, node, options);
- //}else if( t == "duty" ){
- // var widget = new MWF.widget.O2Duty(data, node, options);
- }else if( t == "CMSView" ){
- // var d = { id : distinguishedName };
- var widget = new MWF.widget.O2CMSView(data, node, options);
- //}else if( t == "duty" ){
- // var widget = new MWF.widget.O2Duty(data, node, options);
- }else{
- var widget = new MWF.widget.O2Other( data, node, options);
- }
- }
- widget.field = this;
- this.OrgWidgetList.push( widget );
- }.bind(this));
- },
- removeOrgItem : function( widget, ev ){
- //this 是 MWF.widget.O2Identity 之类的对象
- var _self = this.field; //这个才是MDomItem 对象
- var dn = widget.data.distinguishedName || widget.data.name;
- var data = [];
- var index;
- _self.orgData.each( function ( d , i){
- if( d != dn )data.push( d )
- });
- _self.orgData = data;
- if( _self.orgObject ){
- data = [];
- _self.orgObject.each( function( d ){
- if( d.data ){
- if( d.data.distinguishedName ){
- if( d.data.distinguishedName != dn )data.push( d );
- }else{
- if( d.data.name != dn )data.push( d );
- }
- }
- });
- _self.orgObject = data;
- }
- if( _self.orgObjData ){
- data = [];
- _self.orgObjData.each( function( d ){
- if( d.distinguishedName ){
- if( d.distinguishedName != dn )data.push( d );
- }else{
- if( d.name != dn )data.push( d );
- }
- });
- _self.orgObjData = data;
- }
- this.node.destroy();
- _self.items[0].fireEvent("change");
- ev.stopPropagation();
- },
- getClassName : function(){
- var className = null ;
- if( this.options.className == "none" ){
- }else if( this.options.className != "") {
- className = this.options.className
- }else if( !this.options.isEdited ){
- }else {
- className = "inputPerson"
- }
- return className;
- }
- });
- MDomItem.File = new Class({
- initialize: function ( module ) {
- this.module = module;
- this.options = module.options;
- this.css = module.css;
- this.app = module.app;
- this.items = module.items;
- this.container = this.mElement = module.container;
- this.valSeparator = module.valSeparator;
- },
- load : function(){
- if( this.options.disable )return;
- if( this.options.isEdited ){
- this.loadEdit();
- }else{
- this.loadRead();
- }
- },
- loadEdit : function(){
- },
- loadRead : function(){
- },
- get : function( vort ){
- },
- setValue : function( value ){
- },
- getErrorText : function(){
- }
- });
|