Template.js 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177
  1. MWF.xApplication.CRM = MWF.xApplication.CRM || {};
  2. MWF.xApplication.CRM.Template = MWF.xApplication.CRM.Template || {};
  3. MWF.require("MWF.widget.O2Identity", null, false);
  4. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  5. String.implement({
  6. toDOM: function( container, callback ){
  7. var wrapper = this.test('^<the|^<tf|^<tb|^<colg|^<ca') && ['<table>', '</table>', 1] ||
  8. this.test('^<col') && ['<table><colgroup>', '</colgroup><tbody></tbody></table>',2] ||
  9. this.test('^<tr') && ['<table><tbody>', '</tbody></table>', 2] ||
  10. this.test('^<th|^<td') && ['<table><tbody><tr>', '</tr></tbody></table>', 3] ||
  11. this.test('^<li') && ['<ul>', '</ul>', 1] ||
  12. this.test('^<dt|^<dd') && ['<dl>', '</dl>', 1] ||
  13. this.test('^<le') && ['<fieldset>', '</fieldset>', 1] ||
  14. this.test('^<opt') && ['<select multiple="multiple">', '</select>', 1] ||
  15. ['', '', 0];
  16. if( container ){
  17. var el = new Element('div', {html: wrapper[0] + this + wrapper[1]}).getChildren();
  18. while(wrapper[2]--) el = el[0].getChildren();
  19. el.inject( container )
  20. if( callback )callback( container );
  21. return el;
  22. }else{
  23. var div = new Element('div', {html: wrapper[0] + this + wrapper[1]});
  24. div.setStyle("display","none").inject( $(document.body) );
  25. if( callback )callback( div );
  26. var el = div.getChildren();
  27. while(wrapper[2]--) el = el[0].getChildren();
  28. div.dispose();
  29. return el;
  30. }
  31. }
  32. });
  33. MWF.xApplication.CRM.Template.Select = new Class({
  34. Extends: MWF.widget.Common,
  35. Implements: [Options, Events],
  36. options: {
  37. "style": "default",
  38. "width": "800",
  39. "height": "100%"
  40. },
  41. initialize: function (node ,explorer, actions, options) {
  42. this.setOptions(options);
  43. this.app = explorer.app;
  44. this.explorer = explorer;
  45. this.lp = this.app.lp.template;
  46. this.actions = this.app.restActions;
  47. this.path = "../x_component_CRM/Template/";
  48. this.loadCss();
  49. this.node = $(node);
  50. this.actions = actions;
  51. },
  52. loadCss: function () {
  53. this.cssPath = "../x_component_CRM/$Template/" + this.options.style + "/css.wcss";
  54. this._loadCss();
  55. },
  56. load:function(data,callback){
  57. this._width = this.options.width?this.options.width:230;
  58. this._height = this.options.height?this.options.height:30;
  59. this._available = this.options.available?this.options.available:"yes";
  60. this.createDefault();
  61. this.explorer.allArrowArr.push(this.selectArrowDiv);
  62. //this.setList(data,callback);
  63. if(callback)callback();
  64. },
  65. createDefault:function(){
  66. if(this.node)this.node.empty();
  67. this.selectValueDiv = new Element("div.selectValueDiv",{
  68. "styles":this.css.selectValueDiv,
  69. "id":this.node.get("id")+"Value",
  70. "text":this.lp.defaultSelect
  71. }).inject(this.node);
  72. this.selectArrowDiv = new Element("div.selectArrowDiv",{
  73. "styles":this.css.selectArrowDiv
  74. }).inject(this.node);
  75. this.selectArrowDiv.setStyles({
  76. "width":this._height+"px",
  77. "height":this._height+"px"
  78. });
  79. this.node.setStyles(this.css.selectDiv);
  80. this.node.setStyles({
  81. "width":this._width+"px",
  82. "height":this._height+"px",
  83. "background-color":this._available=="no"?"#eeeeee":""
  84. });
  85. this.node.set("available",this._available);
  86. this.selectValueDiv.setStyles({
  87. "width":(this._width-this._height-10)+"px",
  88. "height":this._height+"px",
  89. "line-height":this._height+"px"
  90. });
  91. },
  92. setAddress:function(data,callback){
  93. data = data || {};
  94. var _self = this;
  95. this.node.removeEvents("click");
  96. this.node.addEvents({
  97. "click":function(e){
  98. if(!data)return false;
  99. if(_self.node.get("available")=="no") return false;
  100. _self.selectArrowDiv.setStyles({
  101. "background":"url(../x_component_CRM/$Template/default/icons/arrow-up.png) no-repeat center"
  102. });
  103. if(_self.explorer.listContentDiv)_self.explorer.listContentDiv.destroy();
  104. if(_self.explorer.listDiv)_self.explorer.listDiv.destroy();
  105. _self.explorer.listContentDiv = new Element("div.listContentDiv",{"styles":_self.css.listContentDiv,"id":"listContentDiv"}).inject(_self.node);
  106. _self.explorer.listContentDiv.setStyles({
  107. "width":_self.node.getSize().x+"px",
  108. "margin-top":(_self.node.getSize().y)+"px",
  109. "z-index":"300"
  110. });
  111. _self.listDiv = new Element("div.listDiv",{"styles":_self.css.listDiv}).inject(_self.explorer.listContentDiv);
  112. _self.app.setScrollBar(_self.listDiv);
  113. data.unshift({
  114. "cityname":_self.lp.defaultSelect
  115. });
  116. data.each(function(d){
  117. var listLi = new Element("li.listLi",{
  118. "styles":_self.css.listLi,
  119. "text": d.cityname
  120. }).inject(_self.listDiv);
  121. listLi.setStyles({
  122. "color":_self.selectValueDiv.get("text")==listLi.get("text")?"#ffffff":"",
  123. "background-color":_self.selectValueDiv.get("text")==listLi.get("text")?"#3d77c1":""
  124. });
  125. listLi.addEvents({
  126. "click":function(ev){
  127. _self.node.set("value",this.get("text"));
  128. _self.explorer.listContentDiv.destroy();
  129. _self.selectArrowDiv.setStyles({"background":"url(../x_component_CRM/$Template/default/icons/arrow.png) no-repeat center"});
  130. if(_self.selectValueDiv.get("text")!=this.get("text")){
  131. _self.selectValueDiv.set({"text":this.get("text")});
  132. if(callback)callback(d);
  133. }
  134. ev.stopPropagation();
  135. },
  136. "mouseover":function(){
  137. if(this.get("text") != _self.selectValueDiv.get("text")){
  138. this.setStyles({
  139. "background-color":"#ccc",
  140. "color":"#ffffff"
  141. });
  142. }
  143. },
  144. "mouseout":function(){
  145. if(this.get("text") != _self.selectValueDiv.get("text")){
  146. this.setStyles({
  147. "background-color":"",
  148. "color":""
  149. });
  150. }
  151. }
  152. });
  153. }.bind(_self));
  154. data.splice(0,1);
  155. e.stopPropagation();
  156. }.bind(this)
  157. })
  158. },
  159. setList:function(data,callback){
  160. data = data || {};
  161. var _self = this;
  162. this.node.removeEvents("click");
  163. this.node.addEvents({
  164. "click":function(e){
  165. if(!data.childNodes)return false;
  166. if(_self.node.get("available")=="no") return false;
  167. _self.selectArrowDiv.setStyles({
  168. "background":"url(../x_component_CRM/$Template/default/icons/arrow-up.png) no-repeat center"
  169. });
  170. if(_self.explorer.listContentDiv)_self.explorer.listContentDiv.destroy();
  171. if(_self.explorer.listDiv)_self.explorer.listDiv.destroy();
  172. _self.explorer.listContentDiv = new Element("div.listContentDiv",{"styles":_self.css.listContentDiv,"id":"listContentDiv"}).inject(_self.node);
  173. _self.explorer.listContentDiv.setStyles({
  174. "width":_self.node.getSize().x+"px",
  175. "margin-top":(_self.node.getSize().y)+"px",
  176. "z-index":"300"
  177. });
  178. _self.listDiv = new Element("div.listDiv",{"styles":_self.css.listDiv}).inject(_self.explorer.listContentDiv);
  179. _self.app.setScrollBar(_self.listDiv);
  180. data.childNodes.unshift({
  181. "configname":_self.lp.defaultSelect
  182. });
  183. data.childNodes.each(function(d){
  184. var listLi = new Element("li.listLi",{
  185. "styles":_self.css.listLi,
  186. "text": d.configname
  187. }).inject(_self.listDiv);
  188. listLi.setStyles({
  189. "color":_self.selectValueDiv.get("text")==listLi.get("text")?"#ffffff":"",
  190. "background-color":_self.selectValueDiv.get("text")==listLi.get("text")?"#3d77c1":""
  191. });
  192. listLi.addEvents({
  193. "click":function(ev){
  194. _self.selectValueDiv.set({"text":this.get("text")});
  195. _self.node.set("value",this.get("text"));
  196. _self.explorer.listContentDiv.destroy();
  197. _self.selectArrowDiv.setStyles({"background":"url(../x_component_CRM/$Template/default/icons/arrow.png) no-repeat center"});
  198. if(callback)callback(d);
  199. ev.stopPropagation();
  200. },
  201. "mouseover":function(){
  202. if(this.get("text") != _self.selectValueDiv.get("text")){
  203. this.setStyles({
  204. "background-color":"#ccc",
  205. "color":"#ffffff"
  206. });
  207. }
  208. },
  209. "mouseout":function(){
  210. if(this.get("text") != _self.selectValueDiv.get("text")){
  211. this.setStyles({
  212. "background-color":"",
  213. "color":""
  214. });
  215. }
  216. }
  217. });
  218. }.bind(_self));
  219. data.childNodes.splice(0,1);
  220. e.stopPropagation();
  221. }.bind(this)
  222. })
  223. }
  224. });
  225. MWF.xApplication.CRM.Template.PopupForm = new Class({
  226. Extends: MWF.widget.Common,
  227. Implements: [Options, Events],
  228. options: {
  229. "style": "default",
  230. "width": 500,
  231. "height": 450,
  232. "top": 0,
  233. "left": 0,
  234. "hasTop": false,
  235. "hasTopIcon" : false,
  236. "hasTopContent" : false,
  237. "hasIcon": true,
  238. "hasScroll" : true,
  239. "hasBottom": true,
  240. "hasMask" : true,
  241. "title": "",
  242. "draggable": false,
  243. "maxAction" : "false",
  244. "closeAction": true,
  245. "relativeToApp" : true,
  246. "sizeRelateTo" : "app" //desktop
  247. },
  248. initialize: function (explorer, data, options, para) {
  249. alert("xxx")
  250. this.setOptions(options);
  251. this.explorer = explorer;
  252. if( para ){
  253. if( this.options.relativeToApp ){
  254. this.app = para.app || this.explorer.app;
  255. this.container = para.container || this.app.content;
  256. this.lp = para.lp || this.explorer.lp || this.app.lp;
  257. this.css = para.css || this.explorer.css || this.app.css;
  258. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  259. }else{
  260. this.container = para.container;
  261. this.lp = para.lp || this.explorer.lp;
  262. this.css = para.css || this.explorer.css;
  263. this.actions = para.actions || this.explorer.actions;
  264. }
  265. }else{
  266. if( this.options.relativeToApp ){
  267. this.app = this.explorer.app;
  268. this.container = this.app.content;
  269. this.lp = this.explorer.lp || this.app.lp;
  270. this.css = this.explorer.css || this.app.css;
  271. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  272. }else{
  273. this.container = window.document.body;
  274. this.lp = this.explorer.lp;
  275. this.css = this.explorer.css;
  276. this.actions = this.explorer.actions;
  277. }
  278. }
  279. this.data = data || {};
  280. this.cssPath = "../x_component_CRM/$Template/"+this.options.style+"/popup.wcss";
  281. this.load();
  282. },
  283. load: function () {
  284. this._loadCss();
  285. },
  286. selectPerson: function (showContainer,nameId,fullNameId,count) {
  287. var options = {
  288. "type" : "",
  289. "types": ["person"],
  290. "values": [],
  291. "count": count,
  292. "zIndex": 50000,
  293. "onComplete": function(items){
  294. MWF.require("MWF.widget.O2Identity", function(){
  295. var invitePersonList = [];
  296. var fullPersonList = [];
  297. items.each(function(item){
  298. var _self = this;
  299. if( item.data.distinguishedName.split("@").getLast().toLowerCase() == "i" ){
  300. var person = new MWF.widget.O2Identity(item.data, it.form.getItem("invitePersonList").container, {"style": "room"});
  301. invitePersonList.push( item.data.distinguishedName );
  302. }else{
  303. //var person = new MWF.widget.O2Person(item.data, it.form.getItem("invitePersonList").container, {"style": "room"});
  304. invitePersonList.push(item.data.name);
  305. fullPersonList.push(item.data.distinguishedName);
  306. }
  307. }.bind(this));
  308. document.getElementById(nameId).innerHTML = invitePersonList.join(",");
  309. if(fullNameId!=""){
  310. document.getElementById(fullNameId).innerHTML = fullPersonList.join(",");
  311. }
  312. }.bind(this));
  313. }.bind(this)
  314. };
  315. var selector = new MWF.O2Selector(showContainer, options);
  316. },
  317. _loadCss: function(){
  318. var css = {};
  319. var r = new Request.JSON({
  320. url: this.cssPath,
  321. secure: false,
  322. async: false,
  323. method: "get",
  324. noCache: false,
  325. onSuccess: function(responseJSON, responseText){
  326. css = responseJSON;
  327. MWF.widget.css[key] = responseJSON;
  328. }.bind(this),
  329. onError: function(text, error){
  330. alert(error + text);
  331. }
  332. });
  333. r.send();
  334. var isEmptyObject = true;
  335. for( var key in css ){
  336. if(key)isEmptyObject = false
  337. }
  338. if( !isEmptyObject ){
  339. this.css = Object.merge( css, this.css );
  340. }
  341. },
  342. open: function (e) {
  343. this.fireEvent("queryOpen");
  344. this.isNew = false;
  345. this.isEdited = false;
  346. this._open();
  347. this.fireEvent("postOpen");
  348. },
  349. create: function () {
  350. this.fireEvent("queryCreate");
  351. this.isNew = true;
  352. this._open();
  353. this.fireEvent("postCreate");
  354. },
  355. edit: function () {
  356. this.fireEvent("queryEdit");
  357. this.isEdited = true;
  358. this._open();
  359. this.fireEvent("postEdit");
  360. },
  361. _open: function () {
  362. if( this.options.hasMask ){
  363. this.formMaskNode = new Element("div.formMaskNode", {
  364. "styles": this.css.formMaskNode,
  365. "events": {
  366. "mouseover": function (e) {
  367. e.stopPropagation();
  368. },
  369. "mouseout": function (e) {
  370. e.stopPropagation();
  371. },
  372. "click": function (e) {
  373. e.stopPropagation();
  374. }
  375. }
  376. }).inject( this.container || this.app.content);
  377. }
  378. this.formAreaNode = new Element("div.formAreaNode", {
  379. "styles": this.css.formAreaNode
  380. });
  381. this.createFormNode();
  382. this.formAreaNode.inject(this.formMaskNode || this.container || this.app.content, "after");
  383. this.formAreaNode.fade("in");
  384. this.setFormNodeSize();
  385. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  386. if( this.app )this.app.addEvent("resize", this.setFormNodeSizeFun);
  387. if (this.options.draggable && this.formTopNode) {
  388. var size = (this.container || this.app.content).getSize();
  389. var nodeSize = this.formAreaNode.getSize();
  390. this.formAreaNode.makeDraggable({
  391. "handle": this.formTopNode,
  392. "limit": {
  393. "x": [0, size.x - nodeSize.x],
  394. "y": [0, size.y - nodeSize.y]
  395. }
  396. });
  397. }
  398. },
  399. createFormNode: function () {
  400. var _self = this;
  401. this.formNode = new Element("div.formNode", {
  402. "styles": this.css.formNode
  403. }).inject(this.formAreaNode);
  404. if (this.options.hasTop) {
  405. this.createTopNode();
  406. }
  407. if (this.options.hasIcon) {
  408. this.formIconNode = new Element("div.formIconNode", {
  409. "styles": this.isNew ? this.css.formNewNode : this.css.formIconNode
  410. }).inject(this.formNode);
  411. }
  412. this.createContent();
  413. //formContentNode.set("html", html);
  414. if (this.options.hasBottom) {
  415. this.createBottomNode();
  416. }
  417. this._setCustom();
  418. if( this.options.hasScroll ){
  419. //this.setScrollBar(this.formTableContainer)
  420. MWF.require("MWF.widget.ScrollBar", function () {
  421. new MWF.widget.ScrollBar(this.formTableContainer, {
  422. "indent": false,
  423. "style": "default",
  424. "where": "before",
  425. "distance": 30,
  426. "friction": 4,
  427. "axis": {"x": false, "y": true},
  428. "onScroll": function (y) {
  429. //var scrollSize = _self.viewContainerNode.getScrollSize();
  430. //var clientSize = _self.viewContainerNode.getSize();
  431. //var scrollHeight = scrollSize.y - clientSize.y;
  432. //if (y + 200 > scrollHeight && _self.view && _self.view.loadElementList) {
  433. // if (!_self.view.isItemsLoaded) _self.view.loadElementList();
  434. //}
  435. }
  436. });
  437. }.bind(this));
  438. }
  439. },
  440. _setCustom : function(){
  441. },
  442. createTopNode: function () {
  443. if (!this.formTopNode) {
  444. this.formTopNode = new Element("div.formTopNode", {
  445. "styles": this.css.formTopNode
  446. }).inject(this.formNode);
  447. if(this.options.hasTopIcon){
  448. this.formTopIconNode = new Element("div", {
  449. "styles": this.css.formTopIconNode
  450. }).inject(this.formTopNode)
  451. }
  452. this.formTopTextNode = new Element("div", {
  453. "styles": this.css.formTopTextNode,
  454. "text": this.options.title
  455. }).inject(this.formTopNode);
  456. if (this.options.closeAction) {
  457. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  458. this.formTopCloseActionNode.addEvent("click", function () {
  459. this.close()
  460. }.bind(this))
  461. }
  462. if(this.options.hasTopContent){
  463. this.formTopContentNode = new Element("div.formTopContentNode", {
  464. "styles": this.css.formTopContentNode
  465. }).inject(this.formTopNode);
  466. this._createTopContent();
  467. }
  468. }
  469. },
  470. _createTopContent: function () {
  471. },
  472. createContent: function () {
  473. this.formContentNode = new Element("div.formContentNode", {
  474. "styles": this.css.formContentNode
  475. }).inject(this.formNode);
  476. this.formTableContainer = new Element("div.formTableContainer", {
  477. "styles": this.css.formTableContainer
  478. }).inject(this.formContentNode);
  479. this.formTableArea = new Element("div.formTableArea", {
  480. "styles": this.css.formTableArea,
  481. "text":"loading..."
  482. }).inject(this.formTableContainer);
  483. this._createTableContent();
  484. },
  485. _createTableContent: function () {
  486. },
  487. createBottomNode: function () {
  488. this.formBottomNode = new Element("div.formBottomNode", {
  489. "styles": this.css.formBottomNode
  490. }).inject(this.formNode);
  491. this._createBottomContent()
  492. },
  493. _createBottomContent: function () {
  494. this.cancelActionNode = new Element("div.formCancelActionNode", {
  495. "styles": this.css.formCancelActionNode,
  496. "text": this.lp.actionCancel
  497. }).inject(this.formBottomNode);
  498. this.cancelActionNode.addEvent("click", function (e) {
  499. this.cancel(e);
  500. }.bind(this));
  501. },
  502. cancel: function (e) {
  503. this.fireEvent("queryCancel");
  504. this.close();
  505. this.fireEvent("postCancel");
  506. },
  507. close: function (e) {
  508. this.fireEvent("queryClose");
  509. this._close();
  510. if(this.setFormNodeSizeFun && this.app ){
  511. this.app.removeEvent("resize",this.setFormNodeSizeFun);
  512. }
  513. if( this.formMaskNode )this.formMaskNode.destroy();
  514. this.formAreaNode.destroy();
  515. this.fireEvent("postClose");
  516. delete this;
  517. },
  518. _close: function(){
  519. },
  520. ok: function (e) {
  521. this.fireEvent("queryOk");
  522. var data = this.form.getResult(true, ",", true, false, true);
  523. if (data) {
  524. this._ok(data, function (json) {
  525. if (json.type == "error") {
  526. if( this.app )this.app.notice(json.message, "error");
  527. } else {
  528. if( this.formMaskNode )this.formMaskNode.destroy();
  529. this.formAreaNode.destroy();
  530. if (this.explorer && this.explorer.view)this.explorer.view.reload();
  531. if( this.app )this.app.notice(this.isNew ? this.lp.createSuccess : this.lp.updateSuccess, "success");
  532. this.fireEvent("postOk");
  533. }
  534. }.bind(this))
  535. }
  536. },
  537. _ok: function (data, callback) {
  538. //this.app.restActions.saveDocument( this.data.id, data, function(json){
  539. // if( callback )callback(json);
  540. //}.bind(this), function( errorObj ){
  541. // var error = JSON.parse( errorObj.responseText );
  542. // this.app.notice( error.message, error );
  543. //}.bind(this));
  544. },
  545. setFormNodeSize: function (width, height, top, left) {
  546. if (!width)width = this.options.width ? this.options.width : "50%";
  547. if (!height)height = this.options.height ? this.options.height : "50%";
  548. if (!top) top = this.options.top ? this.options.top : 0;
  549. if (!left) left = this.options.left ? this.options.left : 0;
  550. //var appTitleSize = this.app.window.title.getSize();
  551. var allSize = ( this.container || this.app.content).getSize();
  552. var limitWidth = allSize.x; //window.screen.width
  553. var limitHeight = allSize.y; //window.screen.height
  554. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  555. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  556. 300 > width && (width = 300);
  557. 220 > height && (height = 220);
  558. top = top || parseInt((limitHeight - height) / 2, 10); //+appTitleSize.y);
  559. left = left || parseInt((limitWidth - width) / 2, 10);
  560. this.formAreaNode.setStyles({
  561. "width": "" + width + "px",
  562. "height": "" + height + "px",
  563. "top": "" + top + "px",
  564. "left": "" + left + "px"
  565. });
  566. this.formNode.setStyles({
  567. "width": "" + width + "px",
  568. "height": "" + height + "px"
  569. });
  570. var iconSize = this.formIconNode ? this.formIconNode.getSize() : {x: 0, y: 0};
  571. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  572. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  573. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  574. //var formMargin = formHeight -iconSize.y;
  575. this.formContentNode.setStyles({
  576. "height": "" + contentHeight + "px"
  577. });
  578. this.formTableContainer.setStyles({
  579. "height": "" + contentHeight + "px"
  580. });
  581. }
  582. });
  583. MWF.xApplication.CRM.Template.ComplexView = new Class({
  584. Implements: [Options, Events],
  585. options: {
  586. "style": "default",
  587. "templateUrl": "",
  588. "scrollEnable" : false,
  589. "pagingEnable" : true,
  590. "documentKeyWord" : null,
  591. "pagingPar" : {
  592. position : [ "bottom" ], //分页条,上下
  593. countPerPage : 5,
  594. visiblePages : 10,
  595. currentPage : 1,
  596. currentItem : null,
  597. hasPagingBar : true,
  598. hasTruningBar : true,
  599. // hasNextPage : true,
  600. // hasPrevPage : true,
  601. hasReturn : false
  602. }
  603. },
  604. initialize: function (container, openDiv, app, explorer, options, para) {
  605. this.container = container;
  606. this.openDiv = openDiv;
  607. this.explorer = explorer;
  608. if( para ){
  609. this.app = app || para.app || this.explorer.app;
  610. this.lp = para.lp || this.explorer.lp || this.app.lp;
  611. this.css = para.css || this.explorer.css || this.app.css;
  612. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  613. this.isAdmin = para.isAdmin;
  614. }else{
  615. this.app = app || this.explorer.app;
  616. this.lp = this.explorer.lp || this.app.lp;
  617. this.css = this.explorer.css || this.app.css;
  618. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  619. }
  620. debugger
  621. if (!options.templateUrl) {
  622. options.templateUrl = this.explorer.path + "listItem.json"
  623. } else if (options.templateUrl.indexOf("/") == -1) {
  624. options.templateUrl = this.explorer.path + options.templateUrl;
  625. }
  626. this.setOptions(options);
  627. },
  628. initData: function () {
  629. this.items = [];
  630. this.documents = {};
  631. this.isItemsLoaded = false;
  632. this.isItemLoadding = false;
  633. this.loadItemQueue = 0;
  634. this.count = 0;
  635. //this.controllers =[];
  636. },
  637. load: function () {
  638. this.initData();
  639. this.ayalyseTemplate();
  640. this.getContentTemplateNode(); //获取template
  641. this.headTableNode = new Element("div.headTableNode", {
  642. "styles": this.css.viewContentListNode
  643. }).inject(this.container);
  644. //this.selectSearch = this.formatElement(this.headTableNode, this.template.selectSearch)
  645. this.contentTableNode = new Element("div.contentTableNode", {
  646. "styles": this.css.viewContentListNode
  647. }).inject(this.container);
  648. this.createViewNode();
  649. this.loadResource(function(){
  650. this.loadSearchCondition();
  651. this.useTablePlugins(1,"","");
  652. if (jQuery( ".headTableNode:has(div)" ).length==0){
  653. jQuery(".headTableNode").remove();
  654. }
  655. //搜索
  656. var that = this;
  657. jQuery(".headSearchBottonDiv").on("click", function () {
  658. var searchText = jQuery(".headSearchInput").val();
  659. if(searchText!=""){
  660. var spage = parseInt(jQuery(".page-active").attr("value"));
  661. //if(jQuery(".laytable-box").length > 0) jQuery(".laytable-box").remove();
  662. var searchType ="";
  663. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  664. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  665. }
  666. that.useTablePlugins(1,searchText,searchType);
  667. }
  668. });
  669. jQuery(".headSearchRemoveImg").on("click", function () {
  670. var spage = parseInt(jQuery(".page-active").attr("value"));
  671. var searchType ="";
  672. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  673. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  674. }
  675. that.useTablePlugins(spage,"",searchType);
  676. });
  677. }.bind(this))
  678. },
  679. loadResource: function ( callback ) {
  680. if(callback)callback();
  681. /*COMMON.AjaxModule.loadCss("../x_component_CRM/$Template/assets/css/notifyme.css", function(){
  682. }.bind(this))
  683. var baseUrls = [
  684. "../x_component_CRM/$Template/plugins/jquery.min.js",
  685. ];
  686. var fullcalendarUrl = "../x_component_CRM/$Template/plugins/layui/layui.js";
  687. var langUrl = "../x_component_CRM/$Template/plugins/table2/table2.js";
  688. COMMON.AjaxModule.loadCss("../x_component_CRM/$Template/plugins/table2/css/table2.css",function(){
  689. COMMON.AjaxModule.load(baseUrls, function(){
  690. jQuery.noConflict();
  691. COMMON.AjaxModule.load(fullcalendarUrl, function(){
  692. COMMON.AjaxModule.load(langUrl, function(){
  693. if(callback)callback();
  694. }.bind(this));
  695. }.bind(this));
  696. }.bind(this))
  697. }.bind(this))*/
  698. },
  699. useTablePlugins: function (cpage,searchText,searchType) {
  700. if(jQuery(".notify").length > 0) jQuery(".notify").remove();
  701. if(jQuery(".laytable-box").length > 0) jQuery(".laytable-box").remove();
  702. var that = this;
  703. var cdata = [];
  704. var cols = [];
  705. var col = [];
  706. var sortField = "";
  707. var sortType = "";
  708. var clueViewObject = this.lp;
  709. var clueListObject = clueViewObject.fieldList;
  710. var count = 15;
  711. sortField = clueViewObject.sortField;
  712. sortType = clueViewObject.sortType;
  713. var csize = this.container.getSize();
  714. var hsize = this.headTableNode.getSize();
  715. var tHeight = (csize.y-hsize.y-80);
  716. debugger
  717. if (!cpage)cpage = 1;
  718. for ( i in clueListObject){
  719. col.push(clueListObject[i]);
  720. }
  721. cols.push(col);
  722. this._getCurrentPageData(function (json) {
  723. json.data.each(function (data ) {
  724. if(data.createuser){
  725. var owneruser = data.owneruser;
  726. var createuser = data.createuser;
  727. data.owneruser = owneruser.split("@")[0];
  728. data.createuser = createuser.split("@")[0];
  729. }else{
  730. data.owneruser = "";
  731. data.createuser = "";
  732. }
  733. cdata.push(data);
  734. }.bind(this));
  735. layui.config({
  736. base: '../x_component_CRM/$Template/plugins/table2/'
  737. }).use(['table2', "table2"], function () {
  738. var table = layui.table2;
  739. debugger
  740. var tableIns = table.render({
  741. elem: "#contentTable",
  742. data: cdata,
  743. height: tHeight,
  744. width: '100%',
  745. page: {
  746. align: 'right',
  747. groups: 5,//显示连续页码数量
  748. curr:1,
  749. count: json.count,//总条数
  750. limit:15,
  751. limits:[15, 30, 45, 60, 75, 90]
  752. },
  753. initSort: {
  754. sortField: sortField,
  755. sortType: sortType
  756. },
  757. cols:cols
  758. });
  759. jQuery(".clueId").each(function(index,element){
  760. jQuery(element).on("click", function () {
  761. that._openDocument(jQuery(element).attr("id"),jQuery(element).text());
  762. });
  763. }
  764. );
  765. jQuery(".otherId").each(function(index,element){
  766. jQuery(element).on("click", function () {
  767. that._openOtherDocument(jQuery(element).attr("id"),jQuery(element).text());
  768. });
  769. }
  770. );
  771. jQuery(".laytable-page-pagination").find("a").each(function(index,element){
  772. jQuery(element).on("click", function () {
  773. //cpage = parseInt(jQuery(element).attr("value"))+cpage;
  774. var topage = 1;
  775. if(jQuery(element).attr("value")=="-1" || jQuery(element).attr("value")=="+1"){
  776. topage = parseInt(jQuery(element).attr("value"))+topage;
  777. }else{
  778. topage = parseInt(jQuery(element).text());
  779. }
  780. if(jQuery(element).attr("class")!="page-item page-last rayui-disabled" && jQuery(element).attr("class")!="page-item page-prev rayui-disabled"){
  781. //that.useTablePlugins(topage);
  782. var searchText = jQuery(".headSearchInput").val();
  783. var searchType ="";
  784. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  785. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  786. }
  787. if(searchText!=""){
  788. that.useTablePlugins(topage,searchText,searchType);
  789. }else{
  790. that.useTablePlugins(topage,"",searchType);
  791. }
  792. }
  793. });
  794. }
  795. );
  796. jQuery(".laytable-page-btnok").on("click", function () {
  797. var cpage = parseInt(jQuery(".laytable-page-input").val());
  798. var searchText = jQuery(".headSearchInput").val();
  799. var searchType ="";
  800. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  801. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  802. }
  803. if(searchText!=""){
  804. that.useTablePlugins(cpage,searchText,searchType);
  805. }else{
  806. that.useTablePlugins(cpage,"",searchType);
  807. }
  808. //that.useTablePlugins(cpage);
  809. });
  810. /* tableIns.on("tool",
  811. function (evt, obj) {
  812. if (evt === "del") {
  813. if (window.confirm("确定删除吗?"))
  814. obj.del();
  815. }else if (evt === "edit") {
  816. alert('您选中了第' + index + '行');
  817. }
  818. });*/
  819. jQuery(".page-item").each(function(index,element){
  820. if(jQuery(element).attr("value")==(cpage+"")){
  821. jQuery(element).attr("class","page-item page-active");
  822. }else{
  823. if(jQuery(element).attr("value")!="-1" && jQuery(element).attr("value")!="+1"){
  824. jQuery(element).attr("class","page-item");
  825. }
  826. }
  827. });
  828. var cCount = jQuery(".page-active").attr("value");
  829. var firstObj = jQuery(".page-prev").parent().next().find("a")[0];
  830. var lastObj = jQuery(".page-last").parent().prev().find("a")[0];
  831. if(parseInt(cCount)>parseInt(jQuery(firstObj).attr("value"))){
  832. jQuery(".page-prev").attr("class","page-item page-prev");
  833. }else{
  834. jQuery(".page-prev").attr("class","page-item page-prev rayui-disabled");
  835. }
  836. if(parseInt(cCount)==parseInt(jQuery(lastObj).attr("value"))){
  837. jQuery(".page-last").attr("class","page-item page-last rayui-disabled");
  838. }else{
  839. jQuery(".page-last").attr("class","page-item page-last");
  840. }
  841. jQuery(".laytable-page-input").attr("value",cpage+"");
  842. });
  843. }.bind(this),count, cpage,searchText,searchType);
  844. },
  845. loadSearchCondition: function () {
  846. //this.template.selectSearch
  847. var that = this;
  848. debugger
  849. if(this.template.selectSearch){
  850. var shtml = '<div class="vux-flexbox se-section vux-flex-row"><div class="se-name" style="font-size:15px;margin-left:10px;">筛选:</div><div class="el-dropdown" style="margin-right: 20px;">'+
  851. '<div class="vux-flexbox se-select vux-flex-row el-dropdown-selfdefine" style="border:0px;"><div class="se-select-name" style="font-size:15px;color:#333;">'+this.template.selectSearch.default+'</div>'+
  852. '<div class="el-icon-arrow-down el-icon--right"><img src="../x_component_CRM/$Clue/default/icons/arrow.png"></div></div></div></div>';
  853. var ulhtml = '<ul class="el-dropdown-type" style="display: none;top:170px;" tid="selectSearch">';
  854. this.template.selectSearch.items.each(function (item) {
  855. if(item.name){
  856. ulhtml = ulhtml+'<li class="el-dropdown-menu__item">'+item.name+'</li>';
  857. }
  858. }.bind(this));
  859. ulhtml = ulhtml+'<div class="popper__arrow" style="box-sizing: border-box !important;"></div></ul>'
  860. jQuery(".headTableNode").append(shtml+ulhtml);
  861. jQuery(".headTableNode").find(".se-select").click(function(){
  862. jQuery("[tid='selectSearch']").toggle(100);
  863. });
  864. jQuery('.el-dropdown-menu__item').click(function(){
  865. if(jQuery(this).parent().attr("tid")=="selectSearch"){
  866. jQuery(".se-select-name").text(jQuery(this).text());
  867. that.useTablePlugins(1,jQuery(".headSearchInput").val(),jQuery(".se-select-name").text());
  868. jQuery(this).parent().toggle(100);
  869. }
  870. });
  871. that.dropdown = jQuery("body")[0].getElement(".el-dropdown-type");
  872. if(that.dropdown) that.dropdown.setStyles({"top":(jQuery(".se-name").offset().top+30)+"px","left":jQuery(".se-name").offset().left+2});
  873. }
  874. var selectDiv = "";
  875. if(jQuery(".contentListDiv").find(".contentLeftItemSelectd").length>0){
  876. selectDiv = jQuery(".contentListDiv").find(".contentLeftItemSelectd").text();
  877. }
  878. if(selectDiv !=""){
  879. jQuery(".headTableNode").empty();
  880. if(selectDiv=="今日需联系客户"){
  881. var aHtml = "";
  882. var shtml = '<div class="vux-flexbox se-section vux-flex-row headTableNode-left"><div class="el-dropdown" style="margin-right: 20px;">'+
  883. '<div class="vux-flexbox se-select vux-flex-row el-dropdown-selfdefine" style="border:0px;"><div class="se-select-name" style="font-size:13px;color:#333;">'+this.template.selectContion1.record.default+'</div>'+
  884. '<div class="el-icon-arrow-down el-icon--right"><img src="../x_component_CRM/$Clue/default/icons/arrow.png"></div></div></div></div>';
  885. var ulhtml = '<ul class="el-dropdown-type selectSearch" style="display: none;top:170px;width: 160px;left:395px;" tid="selectSearch">';
  886. this.template.selectContion1.record.items.each(function (item) {
  887. if(item.name){
  888. ulhtml = ulhtml+'<li class="el-dropdown-menu__item">'+item.name+'</li>';
  889. }
  890. }.bind(this));
  891. ulhtml = ulhtml+'<div class="popper__arrow" style="box-sizing: border-box !important;"></div></ul>'
  892. aHtml = shtml+ulhtml;
  893. aHtml = aHtml+'<div class="vux-flexbox se-section vux-flex-row headTableNode-right"><div class="el-dropdown" style="margin-right: 20px;">'+
  894. '<div class="vux-flexbox se-select vux-flex-row el-dropdown-selfdefine" style="border:0px;"><div class="se-select-name" style="font-size:13px;color:#333;">'+this.template.selectContion1.competence.default+'</div>'+
  895. '<div class="el-icon-arrow-down el-icon--right"><img src="../x_component_CRM/$Clue/default/icons/arrow.png"></div></div></div></div>';
  896. aHtml = aHtml+'<ul class="el-dropdown-type selectSearch_right" style="display: none;top:170px;width: 120px;left:578px;" tid="selectSearch_right">';
  897. this.template.selectContion1.competence.items.each(function (item) {
  898. if(item.name){
  899. aHtml = aHtml+'<li class="el-dropdown-menu__item">'+item.name+'</li>';
  900. }
  901. }.bind(this));
  902. aHtml = aHtml+'<div class="popper__arrow" style="box-sizing: border-box !important;"></div></ul>'
  903. jQuery(".headTableNode").append(aHtml);
  904. }
  905. if(selectDiv=="分配给我的线索"){
  906. var shtml = '<div class="vux-flexbox se-section vux-flex-row headTableNode-left"><div class="el-dropdown" style="margin-right: 20px;">'+
  907. '<div class="vux-flexbox se-select vux-flex-row el-dropdown-selfdefine" style="border:0px;"><div class="se-select-name" style="font-size:13px;color:#333;">'+this.template.selectContion2.record.default+'</div>'+
  908. '<div class="el-icon-arrow-down el-icon--right"><img src="../x_component_CRM/$Clue/default/icons/arrow.png"></div></div></div></div>';
  909. var ulhtml = '<ul class="el-dropdown-type selectSearch" style="display: none;top:170px;width: 160px;left:395px;" tid="selectSearch">';
  910. this.template.selectContion2.record.items.each(function (item) {
  911. if(item.name){
  912. ulhtml = ulhtml+'<li class="el-dropdown-menu__item">'+item.name+'</li>';
  913. }
  914. }.bind(this));
  915. ulhtml = ulhtml+'<div class="popper__arrow" style="box-sizing: border-box !important;"></div></ul>'
  916. jQuery(".headTableNode").append(shtml+ulhtml);
  917. }
  918. if(selectDiv=="分配给我的客户"){
  919. var shtml = '<div class="vux-flexbox se-section vux-flex-row headTableNode-left"><div class="el-dropdown" style="margin-right: 20px;">'+
  920. '<div class="vux-flexbox se-select vux-flex-row el-dropdown-selfdefine" style="border:0px;"><div class="se-select-name" style="font-size:13px;color:#333;">'+this.template.selectContion3.record.default+'</div>'+
  921. '<div class="el-icon-arrow-down el-icon--right"><img src="../x_component_CRM/$Clue/default/icons/arrow.png"></div></div></div></div>';
  922. var ulhtml = '<ul class="el-dropdown-type selectSearch" style="display: none;top:170px;width: 160px;left:395px;" tid="selectSearch">';
  923. this.template.selectContion3.record.items.each(function (item) {
  924. if(item.name){
  925. ulhtml = ulhtml+'<li class="el-dropdown-menu__item">'+item.name+'</li>';
  926. }
  927. }.bind(this));
  928. ulhtml = ulhtml+'<div class="popper__arrow" style="box-sizing: border-box !important;"></div></ul>'
  929. jQuery(".headTableNode").append(shtml+ulhtml);
  930. }
  931. if(selectDiv=="待进入公海的客户"){
  932. var shtml = '<div class="vux-flexbox se-section vux-flex-row headTableNode-right" style="margin-left:20px;"><div class="el-dropdown" style="margin-right: 20px;">'+
  933. '<div class="vux-flexbox se-select vux-flex-row el-dropdown-selfdefine" style="border:0px;"><div class="se-select-name" style="font-size:13px;color:#333;">'+this.template.selectContion4.competence.default+'</div>'+
  934. '<div class="el-icon-arrow-down el-icon--right"><img src="../x_component_CRM/$Clue/default/icons/arrow.png"></div></div></div></div>';
  935. var ulhtml = '<ul class="el-dropdown-type selectSearch" style="display: none;top:170px;width: 120px;left:395px;" tid="selectSearch_right">';
  936. this.template.selectContion4.competence.items.each(function (item) {
  937. if(item.name){
  938. ulhtml = ulhtml+'<li class="el-dropdown-menu__item">'+item.name+'</li>';
  939. }
  940. }.bind(this));
  941. ulhtml = ulhtml+'<div class="popper__arrow" style="box-sizing: border-box !important;"></div></ul>'
  942. jQuery(".headTableNode").append(shtml+ulhtml);
  943. }
  944. jQuery(".headTableNode-left").find(".se-select").click(function(){
  945. jQuery("[tid='selectSearch']").toggle(100);
  946. });
  947. jQuery(".headTableNode-right").find(".se-select").click(function(){
  948. jQuery("[tid='selectSearch_right']").toggle(100);
  949. });
  950. jQuery('.el-dropdown-menu__item').click(function(){
  951. if(jQuery(this).parent().attr("tid")=="selectSearch"){
  952. jQuery(".headTableNode-left").find(".se-select-name").text(jQuery(this).text());
  953. that.useTablePlugins(1,"",jQuery(".headTableNode-left").find(".se-select-name").text());
  954. jQuery(this).parent().toggle(100);
  955. }
  956. if(jQuery(this).parent().attr("tid")=="selectSearch_right"){
  957. jQuery(".headTableNode-right").find(".se-select-name").text(jQuery(this).text());
  958. that.useTablePlugins(1,"",jQuery(".headTableNode-right").find(".se-select-name").text());
  959. jQuery(this).parent().toggle(0);
  960. }
  961. });
  962. that.dropdown = jQuery("body")[0].getElement(".selectSearch");
  963. that.dropdownRight = jQuery("body")[0].getElement(".selectSearch_right");
  964. if(that.dropdown) that.dropdown.setStyles({"top":(jQuery(".headTableNode").offset().top+45)+"px","left":jQuery(".headTableNode").offset().left-30});
  965. if(that.dropdownRight) that.dropdownRight.setStyles({"top":(jQuery(".headTableNode").offset().top+45)+"px","left":jQuery(".headTableNode").offset().left+152});
  966. }
  967. },
  968. //格局化日期:yyyy-MM-dd
  969. formatDate:function(date) {
  970. var myyear = date.getFullYear();
  971. var mymonth = date.getMonth()+1;
  972. var myweekday = date.getDate();
  973. if(mymonth < 10){
  974. mymonth = "0" + mymonth;
  975. }
  976. if(myweekday < 10){
  977. myweekday = "0" + myweekday;
  978. }
  979. return (myyear+"-"+mymonth + "-" + myweekday);
  980. },
  981. reload: function () {
  982. this.clear();
  983. this.node = new Element("div", {
  984. "styles": this.css.viewContentListNode
  985. }).inject(this.container);
  986. this.createViewNode();
  987. this.createViewHead();
  988. this.createViewBody();
  989. },
  990. initSortData: function () {
  991. this.sortField = null;
  992. this.sortType = null;
  993. this.sortFieldDefault = null;
  994. this.sortTypeDefault = null;
  995. },
  996. destroy: function(){
  997. if(this.documentNodeTemplate){
  998. delete this.documentNodeTemplate;
  999. }
  1000. if(this.template)delete this.template;
  1001. if( this.scrollBar ){
  1002. if(this.scrollBar.scrollVAreaNode){
  1003. this.scrollBar.scrollVAreaNode.destroy();
  1004. }
  1005. delete this.scrollBar;
  1006. }
  1007. if(this.pagingContainerTop ){
  1008. if( this.pagingContainerTopCreated ){
  1009. this.pagingContainerTop.destroy();
  1010. }else{
  1011. this.pagingContainerTop.empty();
  1012. }
  1013. }
  1014. if( this.pagingContainerBottom ){
  1015. if( this.pagingContainerBottomCreated ){
  1016. this.pagingContainerBottom.destroy();
  1017. }else{
  1018. this.pagingContainerBottom.empty();
  1019. }
  1020. }
  1021. if( this.paging )this.paging.destroy();
  1022. this.clear();
  1023. delete this;
  1024. },
  1025. clear: function () {
  1026. //if( this.options.pagingEnable ){
  1027. // this.documents = null;
  1028. // MWF.release(this.items);
  1029. // this.items = [];
  1030. // this.documents = {};
  1031. // this.node.destroy();
  1032. // this.container.empty();
  1033. // this.node.destroy();
  1034. // this.container.empty();
  1035. //}else{
  1036. // this.documents = null;
  1037. // MWF.release(this.items);
  1038. // this.items = [];
  1039. // this.documents = {};
  1040. // this.node.destroy();
  1041. // this.container.empty();
  1042. // this.isItemsLoaded = false;
  1043. // this.isItemLoadding = false;
  1044. // this.loadItemQueue = 0;
  1045. //}
  1046. this.documents = null;
  1047. MWF.release(this.items);
  1048. this.items = [];
  1049. this.documents = {};
  1050. this.node.destroy();
  1051. this.container.empty();
  1052. this.isItemsLoaded = false;
  1053. this.isItemLoadding = false;
  1054. this.loadItemQueue = 0;
  1055. },
  1056. clearBody : function(){
  1057. this.items.each( function(item,i){
  1058. item.destroy();
  1059. });
  1060. this.documents = null;
  1061. MWF.release(this.items);
  1062. this.items = [];
  1063. this.documents = {};
  1064. },
  1065. resort: function (el) {
  1066. this.sortField = el.retrieve("sortField");
  1067. var sortType = el.retrieve("sortType");
  1068. if (sortType == "") {
  1069. this.sortType = "asc";
  1070. } else if (this.sortType == "asc") {
  1071. this.sortType = "desc";
  1072. } else {
  1073. this.sortField = null;
  1074. this.sortType = null;
  1075. }
  1076. this.reload();
  1077. },
  1078. setScroll: function(){
  1079. MWF.require("MWF.widget.ScrollBar", function () {
  1080. this.scrollBar = new MWF.widget.ScrollBar(this.container, {
  1081. "indent": false,
  1082. "style": "xApp_TaskList",
  1083. "where": "before",
  1084. "distance": 60,
  1085. "friction": 4,
  1086. "axis": {"x": false, "y": true},
  1087. "onScroll": function (y) {
  1088. if( !this.options.pagingEnable ){
  1089. var scrollSize = this.container.getScrollSize();
  1090. var clientSize = this.container.getSize();
  1091. var scrollHeight = scrollSize.y - clientSize.y;
  1092. if (y + 200 > scrollHeight ) {
  1093. if (! this.isItemsLoaded) this.loadElementList();
  1094. }
  1095. }
  1096. }.bind(this)
  1097. });
  1098. }.bind(this));
  1099. },
  1100. ayalyseTemplate: function () {
  1101. MWF.getJSON(this.options.templateUrl, function (json) {
  1102. this.template = json;
  1103. }.bind(this), false)
  1104. },
  1105. formatElement: function (container, setting, clear ) {
  1106. //container.appendHTML(setting.html);
  1107. var el = setting.html.toDOM( container, function( c , el ){
  1108. this.formatStyles(c);
  1109. this.formatLable(c);
  1110. if(container)this.setEventStyle(c, setting);
  1111. }.bind(this) )[0];
  1112. if( setting.width ){
  1113. el.set("width",setting.width );
  1114. }
  1115. if( clear && container ){
  1116. container.empty();
  1117. }
  1118. return el;
  1119. },
  1120. formatStyles: function ( container ) {
  1121. container.getElements("[class]").each(function (el) {
  1122. var className = el.get("class");
  1123. if (className && this.css[className]) {
  1124. el.setStyles(this.css[className])
  1125. }
  1126. }.bind(this))
  1127. container.getElements("[styles]").each(function (el) {
  1128. var styles = el.get("styles");
  1129. if (styles && this.css[styles]) {
  1130. el.setStyles(this.css[styles])
  1131. }
  1132. }.bind(this))
  1133. },
  1134. formatLable: function (container) {
  1135. container.getElements("[lable]").each(function (el) {
  1136. var lable = el.get("lable");
  1137. if (lable && this.lp[lable]) {
  1138. el.set("text", this.lp[lable] + (el.get("colon") ? ":" : "") )
  1139. }
  1140. }.bind(this))
  1141. },
  1142. createViewHeadNode: function () {
  1143. this.fireEvent("queryCreateViewHeadNode");
  1144. this._queryCreateViewHeadNode();
  1145. this.viewHeadNode = this.formatElement(this.headTableNode, this.template.viewHeadSetting);
  1146. this._postCreateViewHeadNode( this.viewHeadNode );
  1147. this.fireEvent("postCreateViewHeadNode");
  1148. if (!this.viewHeadNode)return;
  1149. },
  1150. createViewNode: function () {
  1151. this.fireEvent("queryCreateViewNode");
  1152. this._queryCreateViewNode();
  1153. this.viewNode = this.formatElement(this.contentTableNode, this.template.viewSetting);
  1154. this._postCreateViewNode( this.viewNode );
  1155. this.fireEvent("postCreateViewNode");
  1156. if (!this.viewNode)return;
  1157. },
  1158. getContentTemplateNode: function(){
  1159. this.documentNodeTemplate = this.formatElement(null, this.template.documentSetting);
  1160. this.template.items.each(function (item) {
  1161. item.nodeTemplate = this.formatElement(null, item.content);
  1162. }.bind(this))
  1163. },
  1164. createViewHead: function () {
  1165. this.fireEvent("queryCreateViewHead");
  1166. this._queryCreateViewHead( );
  1167. if (this.template) {
  1168. if (!this.template.headSetting || this.template.headSetting.disable || !this.template.headSetting.html) {
  1169. return;
  1170. }
  1171. }
  1172. var _self = this;
  1173. var headNode = this.headNode = this.formatElement(this.viewHeadNode, this.template.headSetting);
  1174. this.template.items.each(function (item) {
  1175. if( !item.head )return;
  1176. ////如果设置了权限,那么options里需要有 对应的设置项才会展现
  1177. // 比如 item.access == isAdmin 那么 this.options.isAdmin要为true才展现
  1178. if (item.access && !this.options[item.access])return;
  1179. if (item.head.access && !this.options[item.head.access])return;
  1180. var headItemNode = this.formatElement(headNode, item.head);
  1181. if (item.name == "$checkbox") {
  1182. this.checkboxElement = new Element("input", {
  1183. "type": "checkbox"
  1184. }).inject(headItemNode);
  1185. this.checkboxElement.addEvent("click", function () {
  1186. this.selectAllCheckbox()
  1187. }.bind(this))
  1188. }
  1189. if (item.defaultSort && item.defaultSort != "") {
  1190. this.sortFieldDefault = item.name;
  1191. this.sortTypeDefault = item.defaultSort;
  1192. }
  1193. if (item.sort && item.sort != "") {
  1194. headItemNode.store("sortField", item.name);
  1195. if (this.sortField == item.name && this.sortType != "") {
  1196. headItemNode.store("sortType", this.sortType);
  1197. this.sortIconNode = new Element("div", {
  1198. "styles": this.sortType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  1199. }).inject(headItemNode, "top");
  1200. } else {
  1201. headItemNode.store("sortType", "");
  1202. this.sortIconNode = new Element("div", {"styles": this.css.sortIconNode}).inject(headItemNode, "top");
  1203. }
  1204. headItemNode.setStyle("cursor", "pointer");
  1205. headItemNode.addEvent("click", function () {
  1206. _self.resort(this);
  1207. })
  1208. }
  1209. }.bind(this));
  1210. this.fireEvent("postCreateViewHead");
  1211. this._postCreateViewHead( headNode )
  1212. },
  1213. createViewHeadGroup:function(){
  1214. var tab = this.headTableNode.getElement("table");
  1215. if(tab){
  1216. this.headColGroup = new Element("colgroup.headColGroup").inject(tab);
  1217. this.headWidthAll = 0;
  1218. var headCol = null;
  1219. this.template.items.each(function (item) {
  1220. if(item.head && item.head.width){
  1221. headCol = new Element("col.headCol",{
  1222. "width":item.head.width
  1223. }).inject(this.headColGroup);
  1224. this.headWidthAll = this.headWidthAll + parseInt(item.head.width.substring(0,item.head.width.length-2));
  1225. }
  1226. }.bind(this));
  1227. //alert(this.headWidthAll);
  1228. //alert(this.headWidthAll>this.container.getWidth()?this.headWidthAll:this.container.getWidth())
  1229. tab.setStyles({"width":(this.headWidthAll>this.container.getWidth()?this.headWidthAll:this.container.getWidth())+"px"});
  1230. }
  1231. },
  1232. createViewContentGroup:function(){
  1233. var tab = this.contentTableNode.getElement("table");
  1234. if(tab){
  1235. this.contentColGroup = new Element("colgroup.contentColGroup").inject(tab);
  1236. this.contentWidthAll = 0;
  1237. var contentCol = null;
  1238. this.template.items.each(function (item) {
  1239. if(item.content && item.content.width){
  1240. contentCol = new Element("col.contentCol",{
  1241. "width":item.content.width
  1242. }).inject(this.contentColGroup);
  1243. this.contentWidthAll = this.contentWidthAll + parseInt(item.content.width.substring(0,item.content.width.length-2));
  1244. }
  1245. }.bind(this));
  1246. //alert(this.contentWidthAll>this.container.getWidth()?this.contentWidthAll:this.container.getWidth())
  1247. tab.setStyles({"width":(this.contentWidthAll>this.container.getWidth()?this.contentWidthAll:this.container.getWidth())+"px"});
  1248. }
  1249. },
  1250. setEventStyle: function (node, setting, bingObj, data) {
  1251. var _self = this;
  1252. var styles, overStyles, downStyles;
  1253. var styleStr = setting.styles;
  1254. if (typeOf(styleStr) == "string"){
  1255. if (styleStr && styleStr.substr(0, "function".length) == "function") {
  1256. eval("var fun = " + styleStr );
  1257. styles = fun.call(bingObj, data);
  1258. }else{
  1259. styles = this.css[styleStr];
  1260. }
  1261. }else if (typeOf(styleStr) == "object"){
  1262. styles = styleStr;
  1263. }else if (typeOf(styleStr) == "function"){
  1264. eval("var fun = " + styleStr );
  1265. styles = fun.call(bingObj, data);
  1266. }
  1267. if (!styles) {
  1268. var s = node.get("styles");
  1269. if (!s)node.get("class");
  1270. if (s)styles = this.css[s]
  1271. }
  1272. if (setting.icon) {
  1273. if (!styles)styles = {};
  1274. styles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.icon + ")";
  1275. }
  1276. if (typeOf(setting.mouseoverStyles) == "string")overStyles = this.css[setting.mouseoverStyles];
  1277. if (typeOf(setting.mouseoverStyles) == "object") overStyles = setting.mouseoverStyles;
  1278. if (setting.mouseoverIcon) {
  1279. if (!overStyles)overStyles = {};
  1280. overStyles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.mouseoverIcon + ")"
  1281. }
  1282. if (typeOf(setting.mousedownStyles) == "string")downStyles = this.css[setting.mousedownStyles];
  1283. if (typeOf(setting.mousedownStyles) == "object") downStyles = setting.mousedownStyles;
  1284. if (setting.mousedownIcon) {
  1285. if (!downStyles)downStyles = {};
  1286. downStyles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.mousedownIcon + ")"
  1287. }
  1288. if (styles)node.setStyles(styles);
  1289. if (overStyles && styles) {
  1290. node.addEvent("mouseover", function (ev) {
  1291. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  1292. }.bind({"styles": overStyles, "node":node }));
  1293. node.addEvent("mouseout", function (ev) {
  1294. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  1295. }.bind({"styles": styles, "node":node}));
  1296. }
  1297. if (downStyles && ( overStyles || styles)) {
  1298. node.addEvent("mousedown", function (ev) {
  1299. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  1300. }.bind({"styles": downStyles, "node":node}));
  1301. node.addEvent("mouseup", function (ev) {
  1302. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  1303. }.bind({"styles": overStyles || styles, "node":node}))
  1304. }
  1305. },
  1306. selectAllCheckbox: function () {
  1307. var flag = this.checkboxElement.get("checked");
  1308. this.items.each(function (it) {
  1309. if (it.checkboxElement)it.checkboxElement.set("checked", flag)
  1310. }.bind(this))
  1311. },
  1312. getCheckedItems : function(){
  1313. var checkedItems = [];
  1314. this.items.each(function (it) {
  1315. if (it.checkboxElement.get("checked")) {
  1316. checkedItems.push( it )
  1317. }
  1318. }.bind(this));
  1319. return checkedItems;
  1320. },
  1321. createViewBody : function(){
  1322. //jQuery("#headTable").attr("class","testc");<script>
  1323. //jQuery("head").append(scriptStr);
  1324. this.loadElementList();
  1325. },
  1326. loadElementList: function (count) {
  1327. if( this.options.pagingEnable ){
  1328. var currentItem = this.options.pagingPar.currentItem;
  1329. var countPerPage = this.options.pagingPar.countPerPage;
  1330. debugger;
  1331. if( currentItem ){
  1332. var pageNum = Math.ceil( currentItem / countPerPage );
  1333. var itemNum = currentItem % countPerPage;
  1334. this.loadPagingElementList( count , pageNum, currentItem );
  1335. }else{
  1336. this.loadPagingElementList( count , this.options.pagingPar.currentPage ); //使用分页的方式
  1337. }
  1338. }else{
  1339. this.loadScrollElementList( count ); //滚动条下拉取下一页
  1340. }
  1341. },
  1342. loadScrollElementList : function( count ){
  1343. if (!this.isItemsLoaded) {
  1344. if (!this.isItemLoadding) {
  1345. this.isItemLoadding = true;
  1346. this._getCurrentPageData(function (json) {
  1347. var length = this.dataCount = json.count; //|| json.data.length;
  1348. if (length <= this.items.length) {
  1349. this.isItemsLoaded = true;
  1350. }
  1351. if( json.data && typeOf( json.data )=="array" ){
  1352. json.data.each(function (data ) {
  1353. var key = data[ this.options.documentKeyWord || "id" ];
  1354. if (!this.documents[key]) {
  1355. var item = this._createDocument(data, this.items.length);
  1356. this.items.push(item);
  1357. this.documents[key] = item;
  1358. }
  1359. }.bind(this));
  1360. }
  1361. this.isItemLoadding = false;
  1362. if (this.loadItemQueue > 0) {
  1363. this.loadItemQueue--;
  1364. this.loadElementList();
  1365. }
  1366. }.bind(this), count);
  1367. } else {
  1368. this.loadItemQueue++;
  1369. }
  1370. }
  1371. },
  1372. loadPagingElementList : function( count, pageNum, itemNum ){
  1373. this.currentPage = pageNum || 1;
  1374. this._getCurrentPageData(function (json) {
  1375. //this.documents = {};
  1376. //this.items = [];
  1377. this.viewNode.empty();
  1378. this.dataCount = json.count;
  1379. this.createPaging( json.count, pageNum );
  1380. json.data.each(function (data ) {
  1381. debugger
  1382. var item = this._createDocument(data, this.items.length);
  1383. this.items.push(item);
  1384. var key = data[ this.options.documentKeyWord || "id" ];
  1385. this.documents[key] = item;
  1386. }.bind(this));
  1387. debugger
  1388. if( itemNum ){
  1389. if( this.options.documentKeyWord ){
  1390. var top = this.documents[ itemNum ].node.getTop();
  1391. }else{
  1392. var top = this.items[itemNum-1].node.getTop();
  1393. }
  1394. this.fireEvent( "gotoItem", top );
  1395. }
  1396. }.bind(this), count, pageNum );
  1397. },
  1398. createPaging : function( itemSize, pageNum ){
  1399. if( !this.options.pagingEnable || this.paging )return;
  1400. if( this.options.pagingPar.position.indexOf("top") > -1 ){
  1401. if( !this.pagingContainerTop ){
  1402. this.pagingContainerTopCreated = true;
  1403. this.pagingContainerTop = new Element("div", {"styles":this.css.pagingContainer}).inject( this.viewNode, "before" );
  1404. }
  1405. }
  1406. if( this.options.pagingPar.position.indexOf("bottom") > -1 ){
  1407. debugger
  1408. if( !this.pagingContainerBottom ){
  1409. this.pagingContainerBottomCreated = true;
  1410. this.pagingContainerBottom = new Element("div", {"styles":this.css.pagingContainer}).inject( this.viewNode, "after" );
  1411. }
  1412. }
  1413. debugger
  1414. var par = Object.merge( this.options.pagingPar, {
  1415. itemSize : itemSize,
  1416. onJumpingPage : function( par ){
  1417. debugger
  1418. this.loadPagingElementList( this.options.pagingPar.countPerPage, par.pageNum, par.itemNum );
  1419. }.bind(this)
  1420. });
  1421. if( pageNum )par.currentPage = pageNum;
  1422. if( this.options.pagingPar.hasPagingBar ){
  1423. debugger
  1424. this.paging = new MWF.xApplication.CRM.Template.Paging(this.pagingContainerTop, this.pagingContainerBottom, par, this.css);
  1425. debugger
  1426. this.paging.load();
  1427. }
  1428. },
  1429. _getCurrentPageData: function (callback, count, page) {
  1430. debugger
  1431. if( this.options.pagingEnable ){
  1432. this.actions.listDetailFilter(page, count, filter, function (json) {
  1433. if (callback)callback(json);
  1434. }.bind(this))
  1435. }else{
  1436. if (!count)count = 20;
  1437. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  1438. var filter = this.filterData || {};
  1439. this.actions.listDetailFilterNext(id, count, filter, function (json) {
  1440. if (callback)callback(json);
  1441. }.bind(this))
  1442. }
  1443. },
  1444. getCurrentPageNum: function(){
  1445. return this.paging.options.currentPage;
  1446. },
  1447. getPageSize: function(){
  1448. return this.paging.options.pageSize;
  1449. },
  1450. gotoPage : function( page ){
  1451. this.paging.gotoPage( page );
  1452. },
  1453. _createDocument: function (data, index) {
  1454. return new MWF.xApplication.CRM.Template.ComplexDocument(this.viewNode, data, this.explorer, this, null,index);
  1455. },
  1456. _openDocument: function () {
  1457. },
  1458. _openOtherDocument: function () {
  1459. },
  1460. _removeDocument: function (documentData, all) {
  1461. //var id = document.data.id;
  1462. //this.actions.removeDocument(id, function(json){
  1463. // //json.data.each(function(item){
  1464. // this.items.erase(this.documents[id]);
  1465. // this.documents[id].destroy();
  1466. // MWF.release(this.documents[id]);
  1467. // delete this.documents[id];
  1468. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  1469. // // }.bind(this));
  1470. //}.bind(this));
  1471. },
  1472. _create: function () {
  1473. this.from = new MPopupForm(this.explorer);
  1474. this.from.create();
  1475. },
  1476. _queryCreateViewHeadNode: function(){
  1477. },
  1478. _postCreateViewHeadNode: function( viewNode ){
  1479. },
  1480. _queryCreateViewNode: function(){
  1481. },
  1482. _postCreateViewNode: function( viewNode ){
  1483. },
  1484. _queryCreateViewHead:function(){
  1485. },
  1486. _postCreateViewHead: function( headNode ){
  1487. }
  1488. });
  1489. MWF.xApplication.CRM.Template.ComplexViewOpen = new Class({
  1490. Implements: [Options, Events],
  1491. options: {
  1492. "style": "default",
  1493. "templateUrl": "",
  1494. "scrollEnable" : false,
  1495. "pagingEnable" : true,
  1496. "documentKeyWord" : null,
  1497. "pagingPar" : {
  1498. position : [ "bottom" ], //分页条,上下
  1499. countPerPage : 5,
  1500. visiblePages : 10,
  1501. currentPage : 1,
  1502. currentItem : null,
  1503. hasPagingBar : true,
  1504. hasTruningBar : true,
  1505. // hasNextPage : true,
  1506. // hasPrevPage : true,
  1507. hasReturn : false
  1508. }
  1509. },
  1510. initialize: function (container, openDiv, app, explorer, options, para) {
  1511. this.container = container;
  1512. this.openDiv = openDiv;
  1513. this.explorer = explorer;
  1514. if( para ){
  1515. this.app = app || para.app || this.explorer.app;
  1516. this.lp = para.lp || this.explorer.lp || this.app.lp;
  1517. this.css = para.css || this.explorer.css || this.app.css;
  1518. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  1519. this.isAdmin = para.isAdmin;
  1520. }else{
  1521. this.app = app || this.explorer.app;
  1522. this.lp = this.explorer.lp || this.app.lp;
  1523. this.css = this.explorer.css || this.app.css;
  1524. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  1525. }
  1526. debugger
  1527. if (!options.templateUrl) {
  1528. options.templateUrl = this.explorer.path + "listItem.json"
  1529. } else if (options.templateUrl.indexOf("/") == -1) {
  1530. options.templateUrl = this.explorer.path + options.templateUrl;
  1531. }
  1532. this.setOptions(options);
  1533. },
  1534. initData: function () {
  1535. this.items = [];
  1536. this.documents = {};
  1537. this.isItemsLoaded = false;
  1538. this.isItemLoadding = false;
  1539. this.loadItemQueue = 0;
  1540. this.count = 0;
  1541. //this.controllers =[];
  1542. },
  1543. load: function () {
  1544. this.initData();
  1545. this.ayalyseTemplate();
  1546. this.getContentTemplateNode(); //获取template
  1547. debugger
  1548. this.headNode = new Element("div.headNode", {
  1549. "styles": this.css.viewContentListNode
  1550. }).inject(this.container);
  1551. this.contentTableNode = new Element("div.contentTableNode", {
  1552. "styles": this.css.viewContentListNode
  1553. }).inject(this.container);
  1554. this.createViewNode();
  1555. this.loadResource(function(){
  1556. this.loadSearchCondition();
  1557. this.useTablePlugins(1,"","");
  1558. debugger
  1559. if (jQuery( ".headTableNode:has(div)" ).length==0){
  1560. jQuery(".headTableNode").remove();
  1561. }
  1562. //搜索
  1563. var that = this;
  1564. jQuery(".headSearchBottonDiv").on("click", function () {
  1565. var searchText = jQuery(".headSearchInput").val();
  1566. if(searchText!=""){
  1567. var spage = parseInt(jQuery(".page-active").attr("value"));
  1568. //if(jQuery(".laytable-box").length > 0) jQuery(".laytable-box").remove();
  1569. var searchType ="";
  1570. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  1571. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  1572. }
  1573. debugger
  1574. that.useTablePlugins(1,searchText,searchType);
  1575. }
  1576. });
  1577. jQuery(".headSearchRemoveImg").on("click", function () {
  1578. var spage = parseInt(jQuery(".page-active").attr("value"));
  1579. var searchType ="";
  1580. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  1581. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  1582. }
  1583. that.useTablePlugins(spage,"",searchType);
  1584. });
  1585. }.bind(this))
  1586. },
  1587. loadResource: function ( callback ) {
  1588. if(callback)callback();
  1589. },
  1590. useTablePlugins: function (cpage,searchText,searchType) {
  1591. if(jQuery(".notify").length > 0) jQuery(".notify").remove();
  1592. if(jQuery(".laytable-box").length > 0) jQuery(".laytable-box").remove();
  1593. var that = this;
  1594. var cdata = [];
  1595. var cols = [];
  1596. var col = [];
  1597. var sortField = "";
  1598. var sortType = "";
  1599. var clueViewObject = this.lp;
  1600. var clueListObject = clueViewObject.fieldList;
  1601. var count = 15;
  1602. sortField = clueViewObject.sortField;
  1603. sortType = clueViewObject.sortType;
  1604. debugger
  1605. if (!cpage)cpage = 1;
  1606. for ( i in clueListObject){
  1607. col.push(clueListObject[i]);
  1608. }
  1609. cols.push(col);
  1610. this._getCurrentPageData(function (json) {
  1611. json.data.each(function (data ) {
  1612. if(data.owneruser){
  1613. var owneruser = data.owneruser;
  1614. var createuser = data.createuser;
  1615. data.owneruser = owneruser.split("@")[0];
  1616. data.createuser = createuser.split("@")[0];
  1617. }else{
  1618. data.owneruser = "";
  1619. data.createuser = "";
  1620. }
  1621. cdata.push(data);
  1622. }.bind(this));
  1623. layui.config({
  1624. base: '../x_component_CRM/$Template/plugins/table2/'
  1625. }).use(['table2', "table2"], function () {
  1626. var table = layui.table2;
  1627. debugger
  1628. var tableIns = table.render({
  1629. elem: "#contentTable",
  1630. data: cdata,
  1631. height: 850,
  1632. width: '100%',
  1633. page: {
  1634. align: 'right',
  1635. groups: 5,//显示连续页码数量
  1636. curr:1,
  1637. count: json.count,//总条数
  1638. limit:15,
  1639. limits:[15, 30, 45, 60, 75, 90]
  1640. },
  1641. initSort: {
  1642. sortField: sortField,
  1643. sortType: sortType
  1644. },
  1645. cols:cols
  1646. });
  1647. jQuery(".clueId").each(function(index,element){
  1648. jQuery(element).on("click", function () {
  1649. that._openDocument(jQuery(element).attr("id"),jQuery(element).text());
  1650. });
  1651. }
  1652. );
  1653. jQuery(".otherId").each(function(index,element){
  1654. jQuery(element).on("click", function () {
  1655. that._openOtherDocument(jQuery(element).attr("id"),jQuery(element).text());
  1656. });
  1657. }
  1658. );
  1659. jQuery(".laytable-page-pagination").find("a").each(function(index,element){
  1660. jQuery(element).on("click", function () {
  1661. //cpage = parseInt(jQuery(element).attr("value"))+cpage;
  1662. var topage = 1;
  1663. if(jQuery(element).attr("value")=="-1" || jQuery(element).attr("value")=="+1"){
  1664. topage = parseInt(jQuery(element).attr("value"))+topage;
  1665. }else{
  1666. topage = parseInt(jQuery(element).text());
  1667. }
  1668. if(jQuery(element).attr("class")!="page-item page-last rayui-disabled" && jQuery(element).attr("class")!="page-item page-prev rayui-disabled"){
  1669. //that.useTablePlugins(topage);
  1670. var searchText = jQuery(".headSearchInput").val();
  1671. var searchType ="";
  1672. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  1673. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  1674. }
  1675. if(searchText!=""){
  1676. that.useTablePlugins(topage,searchText,searchType);
  1677. }else{
  1678. that.useTablePlugins(topage,"",searchType);
  1679. }
  1680. }
  1681. });
  1682. }
  1683. );
  1684. jQuery(".laytable-page-btnok").on("click", function () {
  1685. var cpage = parseInt(jQuery(".laytable-page-input").val());
  1686. var searchText = jQuery(".headSearchInput").val();
  1687. var searchType ="";
  1688. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  1689. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  1690. }
  1691. if(searchText!=""){
  1692. that.useTablePlugins(cpage,searchText,searchType);
  1693. }else{
  1694. that.useTablePlugins(cpage,"",searchType);
  1695. }
  1696. //that.useTablePlugins(cpage);
  1697. });
  1698. /* tableIns.on("tool",
  1699. function (evt, obj) {
  1700. if (evt === "del") {
  1701. if (window.confirm("确定删除吗?"))
  1702. obj.del();
  1703. }else if (evt === "edit") {
  1704. alert('您选中了第' + index + '行');
  1705. }
  1706. });*/
  1707. jQuery(".page-item").each(function(index,element){
  1708. if(jQuery(element).attr("value")==(cpage+"")){
  1709. jQuery(element).attr("class","page-item page-active");
  1710. }else{
  1711. if(jQuery(element).attr("value")!="-1" && jQuery(element).attr("value")!="+1"){
  1712. jQuery(element).attr("class","page-item");
  1713. }
  1714. }
  1715. });
  1716. var cCount = jQuery(".page-active").attr("value");
  1717. var firstObj = jQuery(".page-prev").parent().next().find("a")[0];
  1718. var lastObj = jQuery(".page-last").parent().prev().find("a")[0];
  1719. if(parseInt(cCount)>parseInt(jQuery(firstObj).attr("value"))){
  1720. jQuery(".page-prev").attr("class","page-item page-prev");
  1721. }else{
  1722. jQuery(".page-prev").attr("class","page-item page-prev rayui-disabled");
  1723. }
  1724. if(parseInt(cCount)==parseInt(jQuery(lastObj).attr("value"))){
  1725. jQuery(".page-last").attr("class","page-item page-last rayui-disabled");
  1726. }else{
  1727. jQuery(".page-last").attr("class","page-item page-last");
  1728. }
  1729. jQuery(".laytable-page-input").attr("value",cpage+"");
  1730. });
  1731. }.bind(this),count, cpage,searchText,searchType);
  1732. },
  1733. loadSearchCondition: function () {
  1734. //this.template.selectSearch
  1735. var that = this;
  1736. debugger
  1737. //if(this.template.selectSearch){
  1738. var shtml = '<span class="title">'+this.lp.title+'</span><div class="search-input">'+
  1739. '<input type="text" autocomplete="off" placeholder="'+this.lp.searchText+'" class="el-input__inner">'+
  1740. '<div class="el-input-group__append"><img src="../x_component_CRM/$Template/search.png" class="searchimg"></div>'+
  1741. '</div><img src="../x_component_CRM/$Template/close.png" class="close"></div>';
  1742. jQuery(".headNode").append(shtml);
  1743. jQuery(".headNode").find(".el-input-group__append").click(function(){
  1744. var searchText = jQuery(".el-input__inner").val();
  1745. that.useTablePlugins(1,searchText);
  1746. });
  1747. jQuery(".headNode").find(".close").click(function(){
  1748. jQuery(".openDiv").empty();
  1749. jQuery(".openDiv").hide();
  1750. });
  1751. //}
  1752. },
  1753. openx: function (objx) {
  1754. debugger
  1755. },
  1756. reload: function () {
  1757. this.clear();
  1758. this.node = new Element("div", {
  1759. "styles": this.css.viewContentListNode
  1760. }).inject(this.container);
  1761. this.createViewNode();
  1762. this.createViewHead();
  1763. this.createViewBody();
  1764. },
  1765. initSortData: function () {
  1766. this.sortField = null;
  1767. this.sortType = null;
  1768. this.sortFieldDefault = null;
  1769. this.sortTypeDefault = null;
  1770. },
  1771. destroy: function(){
  1772. if(this.documentNodeTemplate){
  1773. delete this.documentNodeTemplate;
  1774. }
  1775. if(this.template)delete this.template;
  1776. if( this.scrollBar ){
  1777. if(this.scrollBar.scrollVAreaNode){
  1778. this.scrollBar.scrollVAreaNode.destroy();
  1779. }
  1780. delete this.scrollBar;
  1781. }
  1782. if(this.pagingContainerTop ){
  1783. if( this.pagingContainerTopCreated ){
  1784. this.pagingContainerTop.destroy();
  1785. }else{
  1786. this.pagingContainerTop.empty();
  1787. }
  1788. }
  1789. if( this.pagingContainerBottom ){
  1790. if( this.pagingContainerBottomCreated ){
  1791. this.pagingContainerBottom.destroy();
  1792. }else{
  1793. this.pagingContainerBottom.empty();
  1794. }
  1795. }
  1796. if( this.paging )this.paging.destroy();
  1797. this.clear();
  1798. delete this;
  1799. },
  1800. clear: function () {
  1801. //if( this.options.pagingEnable ){
  1802. // this.documents = null;
  1803. // MWF.release(this.items);
  1804. // this.items = [];
  1805. // this.documents = {};
  1806. // this.node.destroy();
  1807. // this.container.empty();
  1808. // this.node.destroy();
  1809. // this.container.empty();
  1810. //}else{
  1811. // this.documents = null;
  1812. // MWF.release(this.items);
  1813. // this.items = [];
  1814. // this.documents = {};
  1815. // this.node.destroy();
  1816. // this.container.empty();
  1817. // this.isItemsLoaded = false;
  1818. // this.isItemLoadding = false;
  1819. // this.loadItemQueue = 0;
  1820. //}
  1821. this.documents = null;
  1822. MWF.release(this.items);
  1823. this.items = [];
  1824. this.documents = {};
  1825. this.node.destroy();
  1826. this.container.empty();
  1827. this.isItemsLoaded = false;
  1828. this.isItemLoadding = false;
  1829. this.loadItemQueue = 0;
  1830. },
  1831. clearBody : function(){
  1832. this.items.each( function(item,i){
  1833. item.destroy();
  1834. });
  1835. this.documents = null;
  1836. MWF.release(this.items);
  1837. this.items = [];
  1838. this.documents = {};
  1839. },
  1840. resort: function (el) {
  1841. this.sortField = el.retrieve("sortField");
  1842. var sortType = el.retrieve("sortType");
  1843. if (sortType == "") {
  1844. this.sortType = "asc";
  1845. } else if (this.sortType == "asc") {
  1846. this.sortType = "desc";
  1847. } else {
  1848. this.sortField = null;
  1849. this.sortType = null;
  1850. }
  1851. this.reload();
  1852. },
  1853. setScroll: function(){
  1854. MWF.require("MWF.widget.ScrollBar", function () {
  1855. this.scrollBar = new MWF.widget.ScrollBar(this.container, {
  1856. "indent": false,
  1857. "style": "xApp_TaskList",
  1858. "where": "before",
  1859. "distance": 60,
  1860. "friction": 4,
  1861. "axis": {"x": false, "y": true},
  1862. "onScroll": function (y) {
  1863. if( !this.options.pagingEnable ){
  1864. var scrollSize = this.container.getScrollSize();
  1865. var clientSize = this.container.getSize();
  1866. var scrollHeight = scrollSize.y - clientSize.y;
  1867. if (y + 200 > scrollHeight ) {
  1868. if (! this.isItemsLoaded) this.loadElementList();
  1869. }
  1870. }
  1871. }.bind(this)
  1872. });
  1873. }.bind(this));
  1874. },
  1875. ayalyseTemplate: function () {
  1876. MWF.getJSON(this.options.templateUrl, function (json) {
  1877. this.template = json;
  1878. }.bind(this), false)
  1879. },
  1880. formatElement: function (container, setting, clear ) {
  1881. //container.appendHTML(setting.html);
  1882. var el = setting.html.toDOM( container, function( c , el ){
  1883. this.formatStyles(c);
  1884. this.formatLable(c);
  1885. if(container)this.setEventStyle(c, setting);
  1886. }.bind(this) )[0];
  1887. if( setting.width ){
  1888. el.set("width",setting.width );
  1889. }
  1890. if( clear && container ){
  1891. container.empty();
  1892. }
  1893. return el;
  1894. },
  1895. formatStyles: function ( container ) {
  1896. container.getElements("[class]").each(function (el) {
  1897. var className = el.get("class");
  1898. if (className && this.css[className]) {
  1899. el.setStyles(this.css[className])
  1900. }
  1901. }.bind(this))
  1902. container.getElements("[styles]").each(function (el) {
  1903. var styles = el.get("styles");
  1904. if (styles && this.css[styles]) {
  1905. el.setStyles(this.css[styles])
  1906. }
  1907. }.bind(this))
  1908. },
  1909. formatLable: function (container) {
  1910. container.getElements("[lable]").each(function (el) {
  1911. var lable = el.get("lable");
  1912. if (lable && this.lp[lable]) {
  1913. el.set("text", this.lp[lable] + (el.get("colon") ? ":" : "") )
  1914. }
  1915. }.bind(this))
  1916. },
  1917. createViewHeadNode: function () {
  1918. this.fireEvent("queryCreateViewHeadNode");
  1919. this._queryCreateViewHeadNode();
  1920. this.viewHeadNode = this.formatElement(this.headTableNode, this.template.viewHeadSetting);
  1921. this._postCreateViewHeadNode( this.viewHeadNode );
  1922. this.fireEvent("postCreateViewHeadNode");
  1923. if (!this.viewHeadNode)return;
  1924. },
  1925. createViewNode: function () {
  1926. this.fireEvent("queryCreateViewNode");
  1927. this._queryCreateViewNode();
  1928. this.viewNode = this.formatElement(this.contentTableNode, this.template.viewSetting);
  1929. this._postCreateViewNode( this.viewNode );
  1930. this.fireEvent("postCreateViewNode");
  1931. if (!this.viewNode)return;
  1932. },
  1933. getContentTemplateNode: function(){
  1934. this.documentNodeTemplate = this.formatElement(null, this.template.documentSetting);
  1935. this.template.items.each(function (item) {
  1936. item.nodeTemplate = this.formatElement(null, item.content);
  1937. }.bind(this))
  1938. },
  1939. createViewHead: function () {
  1940. this.fireEvent("queryCreateViewHead");
  1941. this._queryCreateViewHead( );
  1942. if (this.template) {
  1943. if (!this.template.headSetting || this.template.headSetting.disable || !this.template.headSetting.html) {
  1944. return;
  1945. }
  1946. }
  1947. var _self = this;
  1948. var headNode = this.headNode = this.formatElement(this.viewHeadNode, this.template.headSetting);
  1949. this.template.items.each(function (item) {
  1950. if( !item.head )return;
  1951. ////如果设置了权限,那么options里需要有 对应的设置项才会展现
  1952. // 比如 item.access == isAdmin 那么 this.options.isAdmin要为true才展现
  1953. if (item.access && !this.options[item.access])return;
  1954. if (item.head.access && !this.options[item.head.access])return;
  1955. var headItemNode = this.formatElement(headNode, item.head);
  1956. if (item.name == "$checkbox") {
  1957. this.checkboxElement = new Element("input", {
  1958. "type": "checkbox"
  1959. }).inject(headItemNode);
  1960. this.checkboxElement.addEvent("click", function () {
  1961. this.selectAllCheckbox()
  1962. }.bind(this))
  1963. }
  1964. if (item.defaultSort && item.defaultSort != "") {
  1965. this.sortFieldDefault = item.name;
  1966. this.sortTypeDefault = item.defaultSort;
  1967. }
  1968. if (item.sort && item.sort != "") {
  1969. headItemNode.store("sortField", item.name);
  1970. if (this.sortField == item.name && this.sortType != "") {
  1971. headItemNode.store("sortType", this.sortType);
  1972. this.sortIconNode = new Element("div", {
  1973. "styles": this.sortType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  1974. }).inject(headItemNode, "top");
  1975. } else {
  1976. headItemNode.store("sortType", "");
  1977. this.sortIconNode = new Element("div", {"styles": this.css.sortIconNode}).inject(headItemNode, "top");
  1978. }
  1979. headItemNode.setStyle("cursor", "pointer");
  1980. headItemNode.addEvent("click", function () {
  1981. _self.resort(this);
  1982. })
  1983. }
  1984. }.bind(this));
  1985. this.fireEvent("postCreateViewHead");
  1986. this._postCreateViewHead( headNode )
  1987. },
  1988. createViewHeadGroup:function(){
  1989. var tab = this.headTableNode.getElement("table");
  1990. if(tab){
  1991. this.headColGroup = new Element("colgroup.headColGroup").inject(tab);
  1992. this.headWidthAll = 0;
  1993. var headCol = null;
  1994. this.template.items.each(function (item) {
  1995. if(item.head && item.head.width){
  1996. headCol = new Element("col.headCol",{
  1997. "width":item.head.width
  1998. }).inject(this.headColGroup);
  1999. this.headWidthAll = this.headWidthAll + parseInt(item.head.width.substring(0,item.head.width.length-2));
  2000. }
  2001. }.bind(this));
  2002. //alert(this.headWidthAll);
  2003. //alert(this.headWidthAll>this.container.getWidth()?this.headWidthAll:this.container.getWidth())
  2004. tab.setStyles({"width":(this.headWidthAll>this.container.getWidth()?this.headWidthAll:this.container.getWidth())+"px"});
  2005. }
  2006. },
  2007. createViewContentGroup:function(){
  2008. var tab = this.contentTableNode.getElement("table");
  2009. if(tab){
  2010. this.contentColGroup = new Element("colgroup.contentColGroup").inject(tab);
  2011. this.contentWidthAll = 0;
  2012. var contentCol = null;
  2013. this.template.items.each(function (item) {
  2014. if(item.content && item.content.width){
  2015. contentCol = new Element("col.contentCol",{
  2016. "width":item.content.width
  2017. }).inject(this.contentColGroup);
  2018. this.contentWidthAll = this.contentWidthAll + parseInt(item.content.width.substring(0,item.content.width.length-2));
  2019. }
  2020. }.bind(this));
  2021. //alert(this.contentWidthAll>this.container.getWidth()?this.contentWidthAll:this.container.getWidth())
  2022. tab.setStyles({"width":(this.contentWidthAll>this.container.getWidth()?this.contentWidthAll:this.container.getWidth())+"px"});
  2023. }
  2024. },
  2025. setEventStyle: function (node, setting, bingObj, data) {
  2026. var _self = this;
  2027. var styles, overStyles, downStyles;
  2028. var styleStr = setting.styles;
  2029. if (typeOf(styleStr) == "string"){
  2030. if (styleStr && styleStr.substr(0, "function".length) == "function") {
  2031. eval("var fun = " + styleStr );
  2032. styles = fun.call(bingObj, data);
  2033. }else{
  2034. styles = this.css[styleStr];
  2035. }
  2036. }else if (typeOf(styleStr) == "object"){
  2037. styles = styleStr;
  2038. }else if (typeOf(styleStr) == "function"){
  2039. eval("var fun = " + styleStr );
  2040. styles = fun.call(bingObj, data);
  2041. }
  2042. if (!styles) {
  2043. var s = node.get("styles");
  2044. if (!s)node.get("class");
  2045. if (s)styles = this.css[s]
  2046. }
  2047. if (setting.icon) {
  2048. if (!styles)styles = {};
  2049. styles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.icon + ")";
  2050. }
  2051. if (typeOf(setting.mouseoverStyles) == "string")overStyles = this.css[setting.mouseoverStyles];
  2052. if (typeOf(setting.mouseoverStyles) == "object") overStyles = setting.mouseoverStyles;
  2053. if (setting.mouseoverIcon) {
  2054. if (!overStyles)overStyles = {};
  2055. overStyles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.mouseoverIcon + ")"
  2056. }
  2057. if (typeOf(setting.mousedownStyles) == "string")downStyles = this.css[setting.mousedownStyles];
  2058. if (typeOf(setting.mousedownStyles) == "object") downStyles = setting.mousedownStyles;
  2059. if (setting.mousedownIcon) {
  2060. if (!downStyles)downStyles = {};
  2061. downStyles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.mousedownIcon + ")"
  2062. }
  2063. if (styles)node.setStyles(styles);
  2064. if (overStyles && styles) {
  2065. node.addEvent("mouseover", function (ev) {
  2066. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  2067. }.bind({"styles": overStyles, "node":node }));
  2068. node.addEvent("mouseout", function (ev) {
  2069. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  2070. }.bind({"styles": styles, "node":node}));
  2071. }
  2072. if (downStyles && ( overStyles || styles)) {
  2073. node.addEvent("mousedown", function (ev) {
  2074. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  2075. }.bind({"styles": downStyles, "node":node}));
  2076. node.addEvent("mouseup", function (ev) {
  2077. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  2078. }.bind({"styles": overStyles || styles, "node":node}))
  2079. }
  2080. },
  2081. selectAllCheckbox: function () {
  2082. var flag = this.checkboxElement.get("checked");
  2083. this.items.each(function (it) {
  2084. if (it.checkboxElement)it.checkboxElement.set("checked", flag)
  2085. }.bind(this))
  2086. },
  2087. getCheckedItems : function(){
  2088. var checkedItems = [];
  2089. this.items.each(function (it) {
  2090. if (it.checkboxElement.get("checked")) {
  2091. checkedItems.push( it )
  2092. }
  2093. }.bind(this));
  2094. return checkedItems;
  2095. },
  2096. createViewBody : function(){
  2097. //jQuery("#headTable").attr("class","testc");<script>
  2098. //jQuery("head").append(scriptStr);
  2099. this.loadElementList();
  2100. },
  2101. loadElementList: function (count) {
  2102. if( this.options.pagingEnable ){
  2103. var currentItem = this.options.pagingPar.currentItem;
  2104. var countPerPage = this.options.pagingPar.countPerPage;
  2105. debugger;
  2106. if( currentItem ){
  2107. var pageNum = Math.ceil( currentItem / countPerPage );
  2108. var itemNum = currentItem % countPerPage;
  2109. this.loadPagingElementList( count , pageNum, currentItem );
  2110. }else{
  2111. this.loadPagingElementList( count , this.options.pagingPar.currentPage ); //使用分页的方式
  2112. }
  2113. }else{
  2114. this.loadScrollElementList( count ); //滚动条下拉取下一页
  2115. }
  2116. },
  2117. loadScrollElementList : function( count ){
  2118. if (!this.isItemsLoaded) {
  2119. if (!this.isItemLoadding) {
  2120. this.isItemLoadding = true;
  2121. this._getCurrentPageData(function (json) {
  2122. var length = this.dataCount = json.count; //|| json.data.length;
  2123. if (length <= this.items.length) {
  2124. this.isItemsLoaded = true;
  2125. }
  2126. if( json.data && typeOf( json.data )=="array" ){
  2127. json.data.each(function (data ) {
  2128. var key = data[ this.options.documentKeyWord || "id" ];
  2129. if (!this.documents[key]) {
  2130. var item = this._createDocument(data, this.items.length);
  2131. this.items.push(item);
  2132. this.documents[key] = item;
  2133. }
  2134. }.bind(this));
  2135. }
  2136. this.isItemLoadding = false;
  2137. if (this.loadItemQueue > 0) {
  2138. this.loadItemQueue--;
  2139. this.loadElementList();
  2140. }
  2141. }.bind(this), count);
  2142. } else {
  2143. this.loadItemQueue++;
  2144. }
  2145. }
  2146. },
  2147. loadPagingElementList : function( count, pageNum, itemNum ){
  2148. this.currentPage = pageNum || 1;
  2149. this._getCurrentPageData(function (json) {
  2150. //this.documents = {};
  2151. //this.items = [];
  2152. this.viewNode.empty();
  2153. this.dataCount = json.count;
  2154. this.createPaging( json.count, pageNum );
  2155. json.data.each(function (data ) {
  2156. debugger
  2157. var item = this._createDocument(data, this.items.length);
  2158. this.items.push(item);
  2159. var key = data[ this.options.documentKeyWord || "id" ];
  2160. this.documents[key] = item;
  2161. }.bind(this));
  2162. debugger
  2163. if( itemNum ){
  2164. if( this.options.documentKeyWord ){
  2165. var top = this.documents[ itemNum ].node.getTop();
  2166. }else{
  2167. var top = this.items[itemNum-1].node.getTop();
  2168. }
  2169. this.fireEvent( "gotoItem", top );
  2170. }
  2171. }.bind(this), count, pageNum );
  2172. },
  2173. createPaging : function( itemSize, pageNum ){
  2174. if( !this.options.pagingEnable || this.paging )return;
  2175. if( this.options.pagingPar.position.indexOf("top") > -1 ){
  2176. if( !this.pagingContainerTop ){
  2177. this.pagingContainerTopCreated = true;
  2178. this.pagingContainerTop = new Element("div", {"styles":this.css.pagingContainer}).inject( this.viewNode, "before" );
  2179. }
  2180. }
  2181. if( this.options.pagingPar.position.indexOf("bottom") > -1 ){
  2182. debugger
  2183. if( !this.pagingContainerBottom ){
  2184. this.pagingContainerBottomCreated = true;
  2185. this.pagingContainerBottom = new Element("div", {"styles":this.css.pagingContainer}).inject( this.viewNode, "after" );
  2186. }
  2187. }
  2188. debugger
  2189. var par = Object.merge( this.options.pagingPar, {
  2190. itemSize : itemSize,
  2191. onJumpingPage : function( par ){
  2192. debugger
  2193. this.loadPagingElementList( this.options.pagingPar.countPerPage, par.pageNum, par.itemNum );
  2194. }.bind(this)
  2195. });
  2196. if( pageNum )par.currentPage = pageNum;
  2197. if( this.options.pagingPar.hasPagingBar ){
  2198. debugger
  2199. this.paging = new MWF.xApplication.CRM.Template.Paging(this.pagingContainerTop, this.pagingContainerBottom, par, this.css);
  2200. debugger
  2201. this.paging.load();
  2202. }
  2203. },
  2204. _getCurrentPageData: function (callback, count, page) {
  2205. debugger
  2206. if( this.options.pagingEnable ){
  2207. this.actions.listDetailFilter(page, count, filter, function (json) {
  2208. if (callback)callback(json);
  2209. }.bind(this))
  2210. }else{
  2211. if (!count)count = 20;
  2212. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  2213. var filter = this.filterData || {};
  2214. this.actions.listDetailFilterNext(id, count, filter, function (json) {
  2215. if (callback)callback(json);
  2216. }.bind(this))
  2217. }
  2218. },
  2219. getCurrentPageNum: function(){
  2220. return this.paging.options.currentPage;
  2221. },
  2222. getPageSize: function(){
  2223. return this.paging.options.pageSize;
  2224. },
  2225. gotoPage : function( page ){
  2226. this.paging.gotoPage( page );
  2227. },
  2228. _createDocument: function (data, index) {
  2229. return new MWF.xApplication.CRM.Template.ComplexDocument(this.viewNode, data, this.explorer, this, null,index);
  2230. },
  2231. _openDocument: function () {
  2232. },
  2233. _openOtherDocument: function () {
  2234. },
  2235. _removeDocument: function (documentData, all) {
  2236. //var id = document.data.id;
  2237. //this.actions.removeDocument(id, function(json){
  2238. // //json.data.each(function(item){
  2239. // this.items.erase(this.documents[id]);
  2240. // this.documents[id].destroy();
  2241. // MWF.release(this.documents[id]);
  2242. // delete this.documents[id];
  2243. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  2244. // // }.bind(this));
  2245. //}.bind(this));
  2246. },
  2247. _create: function () {
  2248. this.from = new MPopupForm(this.explorer);
  2249. this.from.create();
  2250. },
  2251. _queryCreateViewHeadNode: function(){
  2252. },
  2253. _postCreateViewHeadNode: function( viewNode ){
  2254. },
  2255. _queryCreateViewNode: function(){
  2256. },
  2257. _postCreateViewNode: function( viewNode ){
  2258. },
  2259. _queryCreateViewHead:function(){
  2260. },
  2261. _postCreateViewHead: function( headNode ){
  2262. }
  2263. });
  2264. MWF.xApplication.CRM.Template.ComplexDocument = new Class({
  2265. Implements: [Options, Events],
  2266. initialize: function (container, data, explorer, view, para, index) {
  2267. this.explorer = explorer;
  2268. this.data = data;
  2269. this.container = container;
  2270. this.view = view;
  2271. this.index = index;
  2272. if( para ){
  2273. this.app = para.app || this.view.app || this.explorer.app;
  2274. this.lp = para.lp || this.view.lp || this.explorer.lp || this.app.lp;
  2275. this.css = para.css || this.view.css || this.explorer.css || this.app.css;
  2276. this.actions = para.actions || this.view.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  2277. }else{
  2278. this.app = this.view.app || this.explorer.app;
  2279. this.lp = this.view.lp || this.explorer.lp || this.app.lp;
  2280. this.css = this.view.css || this.explorer.css || this.app.css;
  2281. this.actions = this.view.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  2282. }
  2283. debugger;
  2284. //container为openDiv
  2285. this.load();
  2286. },
  2287. load: function () {
  2288. this.fireEvent("queryCreateDocumentNode");
  2289. this._queryCreateDocumentNode( this.data );
  2290. var _self = this;
  2291. this.loadResource(function(){
  2292. this.loadClueForm(this.data);
  2293. }.bind(this))
  2294. /*
  2295. this.node = this.view.documentNodeTemplate.clone().inject(this.container);
  2296. //this.documentAreaNode = new Element("td", {"styles": this.css.documentNode}).inject(this.node);
  2297. this.view.template.items.each(function (item) {
  2298. if( item.access && this._getItemAccess(item) ){
  2299. this.loadItem(item.name, item.content, item.nodeTemplate)
  2300. }else{
  2301. this.loadItem(item.name, item.content, item.nodeTemplate)
  2302. }
  2303. }.bind(this));
  2304. var setting = this.view.template.documentSetting;
  2305. if( setting.styles || setting.mouseoverStyles || setting.mousedownStyles || setting.icon || setting.mouseoverIcon || setting.mousedownIcon ){
  2306. this.view.setEventStyle( this.node, setting, this, this.data );
  2307. }
  2308. var available = this.getConditionResult(setting.condition);
  2309. if( setting.action && this[setting.action] ){
  2310. if ( available ){
  2311. this.node.addEvent("click", function (ev) {
  2312. this.fun.call(_self, this.node, ev);
  2313. ev.stopPropagation();
  2314. }.bind({fun: this[setting.action], node : this.node}))
  2315. }
  2316. }
  2317. if( setting.event && available ){
  2318. this.bindEvent( this.node, setting.event );
  2319. }
  2320. */
  2321. this.fireEvent("postCreateDocumentNode");
  2322. this._postCreateDocumentNode( this.node, this.data )
  2323. },
  2324. loadResource: function ( callback ) {
  2325. var baseUrls = [
  2326. "../x_component_CRM/$Template/plugins/jquery.min.js",
  2327. ];
  2328. var fullcalendarUrl = "../x_component_CRM/$Template/form/js/bootstrap.min.js";
  2329. var langUrl = "../x_component_CRM/$Template/form/js/mejs.js";
  2330. COMMON.AjaxModule.loadCss("../x_component_CRM/$Template/form/css/bootstrap.min.css",function(){
  2331. COMMON.AjaxModule.load(baseUrls, function(){
  2332. jQuery.noConflict();
  2333. COMMON.AjaxModule.load(fullcalendarUrl, function(){
  2334. COMMON.AjaxModule.load(langUrl, function(){
  2335. if(callback)callback();
  2336. }.bind(this))
  2337. }.bind(this));
  2338. }.bind(this))
  2339. }.bind(this))
  2340. },
  2341. loadClueForm: function (name) {
  2342. alert(name);
  2343. },
  2344. loadItem: function (name, item, nodeTemplate ) {
  2345. var itemNode = this[name] = nodeTemplate.clone();
  2346. if( this.format(itemNode, name, item) ){
  2347. itemNode.inject(this.node);
  2348. }
  2349. if (item.items) {
  2350. var elements = itemNode.getElements("[item]");
  2351. if( itemNode.get("item") )elements.push(itemNode);
  2352. elements.each(function (el) {
  2353. var key = el.get("item");
  2354. var sub = item.items[key];
  2355. if( sub ){
  2356. if( !sub.value && sub.value!="" )sub.value = key;
  2357. if( !this.format(el, name, sub) ){
  2358. el.dispose()
  2359. }
  2360. }
  2361. }.bind(this))
  2362. }
  2363. },
  2364. format: function (itemNode, name, item) {
  2365. var _self = this;
  2366. if (item.access) {
  2367. if (!this._getItemAccess(item))return false;
  2368. }
  2369. //if (item.condition) {
  2370. // if (!this.getConditionResult(item.condition))return false;
  2371. //}
  2372. var show = this.getConditionResult( item.show );
  2373. if( !show )itemNode.setStyle("display","none");
  2374. var available = this.getConditionResult(item.condition);
  2375. if (item.text) {
  2376. var text = this.getExecuteResult( item.text );
  2377. //var text = item.text;
  2378. itemNode.set("text", this.view.lp && this.view.lp[text] ? this.view.lp[text] : text);
  2379. }
  2380. if (item.title) {
  2381. var title = this.getExecuteResult( item.title );
  2382. //var title = item.title;
  2383. itemNode.set("title", this.view.lp && this.view.lp[title] ? this.view.lp[title] : title);
  2384. }
  2385. if ( !item.text && item.value && item.value != "") {
  2386. if( item.type == "html" ){
  2387. itemNode.set("html", this.getValue(item.value));
  2388. }else{
  2389. itemNode.set("text", this.getValue(item.value));
  2390. }
  2391. }
  2392. if( item.styles || item.mouseoverStyles || item.mousedownStyles || item.icon || item.mouseoverIcon || item.mousedownIcon ){
  2393. this.view.setEventStyle( itemNode, item, this, this.data );
  2394. }
  2395. if (item.action && this[item.action]) {
  2396. if ( available ){
  2397. itemNode.addEvent("click", function (ev) {
  2398. this.fun.call(_self, this.node, ev);
  2399. ev.stopPropagation();
  2400. }.bind({fun: this[item.action], node : itemNode}))
  2401. }else{
  2402. return false;
  2403. }
  2404. }
  2405. if( item.event && available ){
  2406. this.bindEvent( itemNode, item.event );
  2407. }
  2408. if( item.attr ){
  2409. this.setAttr( itemNode, item.attr );
  2410. }
  2411. if ( name == "$checkbox" ) {
  2412. if ( available ){
  2413. this.checkboxElement = new Element("input", {
  2414. "type": "checkbox"
  2415. }).inject(itemNode);
  2416. this.checkboxElement.addEvent("click", function (ev) {
  2417. ev.stopPropagation();
  2418. }.bind(this));
  2419. itemNode.addEvent("click", function (ev) {
  2420. this.checkboxElement.set("checked", !this.checkboxElement.get("checked"));
  2421. ev.stopPropagation();
  2422. }.bind(this))
  2423. }else{
  2424. //return false;
  2425. }
  2426. }
  2427. return true;
  2428. },
  2429. getExecuteResult : function( str ){
  2430. var result = str;
  2431. if (str && str.substr(0, 8) == "function") { //"function".length
  2432. eval("var fun = " + str);
  2433. result = fun.call(this, this.data);
  2434. }
  2435. return result;
  2436. },
  2437. getValue: function (str) {
  2438. if (str.substr(0, 8 ) == "function") { //"function".length
  2439. eval("var fun = " + str);
  2440. return fun.call(this, this.data);
  2441. } else if (typeOf(this.data[str]) == "number") {
  2442. return this.data[str];
  2443. } else {
  2444. return this.data[str] ? this.data[str] : "";
  2445. }
  2446. },
  2447. getConditionResult: function (str) {
  2448. var flag = true;
  2449. if (str && str.substr(0, 8) == "function") { //"function".length
  2450. eval("var fun = " + str);
  2451. flag = fun.call(this, this.data);
  2452. }
  2453. return flag;
  2454. },
  2455. setAttr: function(item, attr){
  2456. if( !attr || attr == "" || attr == "$none" )return;
  2457. if( typeof attr == "string" ){
  2458. if( attr.indexOf("^^") > -1 ){
  2459. var attrsArr = attr.split("##");
  2460. if( attrsArr[0].split("^^").length != 2 )return;
  2461. attrs = {};
  2462. for(var i=0;i<attrsArr.length;i++){
  2463. var aname = attrsArr[i].split("^^")[0];
  2464. var afunction = attrsArr[i].split("^^")[1];
  2465. if( afunction.substr(0, "function".length) == "function" ){
  2466. eval("var fun = " + afunction );
  2467. attrs[ aname ] = fun.call(this, this.data); //字符串变对象或function,方法1
  2468. }else{
  2469. attrs[ aname ] = afunction;
  2470. }
  2471. }
  2472. }else{
  2473. //字符串变对象或function,方法2
  2474. eval( "var attrs = " + attr );
  2475. }
  2476. }
  2477. if( typeOf(attrs) == "object" ){
  2478. for( var a in attrs ){
  2479. item.set( a, attrs[a] );
  2480. }
  2481. }
  2482. },
  2483. bindEvent: function(item,events){
  2484. if( !events || events == "" || events == "$none" )return;
  2485. if( typeof events == "string" ){
  2486. if( events.indexOf("^^") > -1 ){
  2487. var eventsArr = events.split("##");
  2488. if( eventsArr[0].split("^^").length != 2 )return;
  2489. events = {};
  2490. for(var i=0;i<eventsArr.length;i++){
  2491. var ename = eventsArr[i].split("^^")[0];
  2492. var efunction = eventsArr[i].split("^^")[1];
  2493. events[ ename ] = eval( "(function(){ return "+ efunction +" })()" ); //字符串变对象或function,方法1
  2494. }
  2495. }else{
  2496. //字符串变对象或function,方法2
  2497. eval( "var events = " + events );
  2498. }
  2499. }
  2500. if( typeOf(events) == "object" ){
  2501. for( var e in events ){
  2502. item.addEvent( e, function(ev){
  2503. this.fun.call( this.bingObj, this.target, ev );
  2504. ev.stopPropagation();
  2505. }.bind({bingObj : this, target: item, fun : events[e]}));
  2506. }
  2507. }
  2508. },
  2509. _getItemAccess: function (item) {
  2510. if (item.access && !this.explorer.options[item.access]) {
  2511. return false;
  2512. } else {
  2513. return true;
  2514. }
  2515. },
  2516. _getActionAccess: function (actionData) {
  2517. return true;
  2518. },
  2519. open: function (e) {
  2520. //var options = {"documentId": this.data.id }//this.explorer.app.options.application.allowControl};
  2521. //this.explorer.app.desktop.openApplication(e, "cms.Document", options);
  2522. this.view._openDocument(this.data);
  2523. },
  2524. remove: function (e) {
  2525. var lp = this.app.lp;
  2526. var text = lp.deleteDocument.replace(/{title}/g, this.data.title);
  2527. var _self = this;
  2528. this.node.setStyles(this.css.documentNode_remove);
  2529. this.readyRemove = true;
  2530. this.view.lockNodeStyle = true;
  2531. //this.explorer.app.confirm("warn", e, lp.deleteDocumentTitle, text, 350, 120, function () {
  2532. this.app.confirm("warn", e, lp.deleteDocumentTitle, text, 350, 120, function () {
  2533. //var inputs = this.content.getElements("input");
  2534. //var flag = "";
  2535. //for (var i=0; i<inputs.length; i++){
  2536. // if (inputs[i].checked){
  2537. // flag = inputs[i].get("value");
  2538. // break;
  2539. // }
  2540. //}
  2541. //if (flag){
  2542. //if (flag=="all"){
  2543. //_self.explorer.removeDocument(_self, true);
  2544. //}else{
  2545. _self.view._removeDocument(_self.data, false);
  2546. _self.view.lockNodeStyle = false;
  2547. //}
  2548. this.close();
  2549. //}else{
  2550. // this.content.getElement("#deleteDocument_checkInfor").set("text", lp.deleteAllDocumentCheck).setStyle("color", "red");
  2551. //}
  2552. }, function () {
  2553. _self.node.setStyles(_self.css.documentNode);
  2554. _self.readyRemove = false;
  2555. _self.view.lockNodeStyle = false;
  2556. this.close();
  2557. });
  2558. },
  2559. destroy: function () {
  2560. this.node.destroy();
  2561. delete this;
  2562. },
  2563. _queryCreateDocumentNode:function( itemData ){
  2564. },
  2565. _postCreateDocumentNode: function( itemNode, itemData ){
  2566. }
  2567. });
  2568. MWF.xApplication.CRM.Template.Paging = new Class({
  2569. Implements: [Options, Events],
  2570. options : {
  2571. position : ["bottom"],
  2572. countPerPage : 5,
  2573. visiblePages : 10,
  2574. currentPage : 1,
  2575. itemSize : 0,
  2576. pageSize : 0,
  2577. //hasNextPage : true,
  2578. //hasPrevPage : true,
  2579. hasTruningBar : true,
  2580. hasJumper : true,
  2581. hasReturn : false,
  2582. //returnText : "返回首页",
  2583. hiddenWithDisable: true,
  2584. text : {
  2585. prePage : "",
  2586. nextPage : "",
  2587. firstPage : "",
  2588. lastPage : ""
  2589. }
  2590. },
  2591. initialize: function (topContainer, bottomContainer, options, css) {
  2592. this.setOptions( options || {});
  2593. this.topContainer = topContainer;
  2594. this.bottomContainer = bottomContainer;
  2595. this.css = css;
  2596. },
  2597. load : function(){
  2598. debugger;
  2599. this.fireEvent( "queryLoad", this);
  2600. this.options.pageSize = Math.ceil(this.options.itemSize/this.options.countPerPage);
  2601. if( ( (this.options.pageSize == 1 || this.options.pageSize == 0) && this.options.hiddenWithDisable ) && !this.options.hasReturn )return;
  2602. debugger;
  2603. if( this.topContainer ){
  2604. this.topContainer.empty();
  2605. if( this.options.hasTruningBar && this.options.position.indexOf("top") > -1 ){
  2606. this.createNode( this.topContainer );
  2607. }
  2608. }
  2609. if( this.bottomContainer ){
  2610. this.bottomContainer.empty();
  2611. if( this.options.hasPrevPage ){
  2612. this.createPrevPageNode( this.bottomContainer );
  2613. }
  2614. if( this.options.hasNextPage ){
  2615. this.createNextPageNode( this.bottomContainer );
  2616. }
  2617. if( this.options.hasTruningBar && this.options.position.indexOf("bottom") > -1 ){
  2618. this.createNode( this.bottomContainer );
  2619. }
  2620. }
  2621. this.fireEvent( "postLoad", this);
  2622. },
  2623. createNode : function( container ){
  2624. var _self = this;
  2625. var visiblePages = this.options.visiblePages;
  2626. var pageSize = this.options.pageSize;
  2627. var currentPage = this.options.currentPage;
  2628. var halfCount = Math.floor( visiblePages / 2);
  2629. var i, max, min;
  2630. if( pageSize <= visiblePages ){
  2631. min = 1;
  2632. max = pageSize;
  2633. }else if( currentPage + halfCount > pageSize ){
  2634. min = pageSize - visiblePages;
  2635. max = pageSize;
  2636. }else if( currentPage - halfCount < 1 ){
  2637. min = 1;
  2638. max = visiblePages;
  2639. }else{
  2640. min = currentPage - halfCount;
  2641. max = currentPage + halfCount;
  2642. }
  2643. debugger;
  2644. var node = this.node = new Element("div.pagingBar", { styles : this.css.pagingBar } ).inject( container );
  2645. if( this.options.hasReturn ){
  2646. var pageReturn = this.pageReturn = new Element( "div.pageReturn" , { styles : this.css.pageReturn , "text" : this.options.returnText } ).inject(node);
  2647. pageReturn.addEvents( {
  2648. "mouseover" : function( ev ){ ev.target.setStyles( this.css.pageReturn_over ) }.bind(this),
  2649. "mouseout" : function( ev ){ ev.target.setStyles( this.css.pageReturn ) }.bind(this),
  2650. "click" : function(){ this.fireEvent( "pageReturn" , this ) }.bind(this)
  2651. })
  2652. }
  2653. if( (pageSize != 1 && pageSize != 0) || !this.options.hiddenWithDisable ){
  2654. if( min > 1 || !this.options.hiddenWithDisable){
  2655. var firstPage = this.firstPage = new Element( "div.firstPage" , { styles : this.css.firstPage, text : "1..." }).inject(node);
  2656. if( this.options.text.firstPage )firstPage.set( "text", this.options.text.firstPage );
  2657. firstPage.addEvents( {
  2658. "mouseover" : function( ev ){ ev.target.setStyles( this.css.firstPage_over ) }.bind(this),
  2659. "mouseout" : function( ev ){ ev.target.setStyles( this.css.firstPage ) }.bind(this),
  2660. "click" : function(){ this.gotoPage(1) }.bind(this)
  2661. } )
  2662. }
  2663. if( currentPage != 1 || !this.options.hiddenWithDisable){
  2664. var prePage = this.prePage = new Element( "div.prePage" , { styles : this.css.prePage } ).inject(node);
  2665. if( this.options.text.prePage )prePage.set( "text", this.options.text.prePage );
  2666. prePage.addEvents( {
  2667. "mouseover" : function( ev ){ ev.target.setStyles( this.css.prePage_over ) }.bind(this),
  2668. "mouseout" : function( ev ){ ev.target.setStyles( this.css.prePage ) }.bind(this),
  2669. "click" : function(){ this.gotoPage( currentPage-1 ) }.bind(this)
  2670. } )
  2671. }
  2672. this.pageTurnNodes = [];
  2673. for( i=min; i<=max; i++ ){
  2674. if( currentPage == i ){
  2675. this.currentPage = new Element("div.currentPage", {"styles" : this.css.currentPage, "text" : i }).inject(node);
  2676. }else{
  2677. var pageTurnNode = new Element("div.pageItem", {"styles" : this.css.pageItem, "text" : i }).inject(node);
  2678. pageTurnNode.addEvents( {
  2679. "mouseover" : function( ev ){ ev.target.setStyles( this.css.pageItem_over ) }.bind(this),
  2680. "mouseout" : function( ev ){ ev.target.setStyles( this.css.pageItem ) }.bind(this),
  2681. "click" : function(){ this.obj.gotoPage( this.num ) }.bind({ obj : this, num : i })
  2682. });
  2683. this.pageTurnNodes.push( pageTurnNode );
  2684. }
  2685. }
  2686. if( this.options.hasJumper ){
  2687. var pageJumper = this.pageJumper = new Element("input.pageJumper", {"styles" : this.css.pageJumper , "title" : "输入页码,按回车跳转"}).inject( node );
  2688. new Element( "div.pageText", {"styles" : this.css.pageText , "text" : "/" + pageSize }).inject( node );
  2689. pageJumper.addEvents( {
  2690. "focus" : function( ev ){ ev.target.setStyles( this.css.pageJumper_over ) }.bind(this),
  2691. "blur" : function( ev ){ ev.target.setStyles( this.css.pageJumper ) }.bind(this),
  2692. "keyup" : function(e){
  2693. this.value=this.value.replace(/[^0-9_]/g,'')
  2694. },
  2695. "keydown" : function(e){
  2696. if(e.code==13 && this.value!="" ){
  2697. _self.gotoPage( this.value );
  2698. e.stopPropagation();
  2699. //e.preventDefault();
  2700. }
  2701. }
  2702. });
  2703. }
  2704. if( currentPage != pageSize || !this.options.hiddenWithDisable){
  2705. var nextPage = this.nextPage = new Element( "div.nextPage" , { styles : this.css.nextPage } ).inject(node);
  2706. if( this.options.text.nextPage )nextPage.set( "text", this.options.text.nextPage );
  2707. nextPage.addEvents( {
  2708. "mouseover" : function( ev ){ ev.target.setStyles( this.css.nextPage_over ) }.bind(this),
  2709. "mouseout" : function( ev ){ ev.target.setStyles( this.css.nextPage ) }.bind(this),
  2710. "click" : function(){ this.gotoPage( currentPage+1 ) }.bind(this)
  2711. } )
  2712. }
  2713. if( max < pageSize || !this.options.hiddenWithDisable){
  2714. var lastPage = this.lastPage = new Element( "div.lastPage" , { styles : this.css.lastPage, text : "..." + pageSize }).inject(node);
  2715. if( this.options.text.lastPage )lastPage.set( "text", this.options.text.lastPage );
  2716. lastPage.addEvents( {
  2717. "mouseover" : function( ev ){ ev.target.setStyles( this.css.lastPage_over ) }.bind(this),
  2718. "mouseout" : function( ev ){ ev.target.setStyles( this.css.lastPage ) }.bind(this),
  2719. "click" : function(){ this.gotoPage( pageSize ) }.bind(this)
  2720. } )
  2721. }
  2722. }
  2723. },
  2724. createNextPageNode : function( container ){
  2725. if( this.nextPageNode ){
  2726. this.nextPageNode.destroy();
  2727. delete this.nextPageNode;
  2728. }
  2729. var pageSize = this.options.pageSize;
  2730. if( this.options.currentPage != pageSize && pageSize != 1 && pageSize != 0 ){
  2731. this.nextPageNode = new Element("div.nextPageNode", {
  2732. "styles" : this.css.nextPageNode,
  2733. "text" : "下一页"
  2734. }).inject(container);
  2735. this.nextPageNode.addEvents( {
  2736. "mouseover" : function( ev ){ ev.target.setStyles( this.css.nextPageNode_over ) }.bind(this),
  2737. "mouseout" : function( ev ){ ev.target.setStyles( this.css.nextPageNode ) }.bind(this),
  2738. "click" : function(){ this.gotoPage( this.options.currentPage+1 ) }.bind(this)
  2739. })
  2740. }
  2741. },
  2742. createPrevPageNode : function( container ){
  2743. if( this.prevPageNode ){
  2744. this.prevPageNode.destroy();
  2745. delete this.prevPageNode;
  2746. }
  2747. var pageSize = this.options.pageSize;
  2748. if( this.options.currentPage != 1 && pageSize != 1 && pageSize != 0 ){
  2749. this.prevPageNode = new Element("div.prevPageNode", {
  2750. "styles" : this.css.prevPageNode,
  2751. "text" : "上一页"
  2752. }).inject(container);
  2753. this.prevPageNode.addEvents( {
  2754. "mouseover" : function( ev ){ ev.target.setStyles( this.css.prevPageNode_over ) }.bind(this),
  2755. "mouseout" : function( ev ){ ev.target.setStyles( this.css.prevPageNode ) }.bind(this),
  2756. "click" : function(){ this.gotoPage( this.options.currentPage-1 ) }.bind(this)
  2757. })
  2758. }
  2759. },
  2760. gotoPage : function( num ){
  2761. if( num < 1 || num > this.options.pageSize )return;
  2762. this.fireEvent( "jumpingPage", { pageNum : num } );
  2763. this.options.currentPage = num;
  2764. this.load();
  2765. },
  2766. gotoItem : function( itemNum ){
  2767. var pageNum = Math.ceil( itemNum / this.options.countPerPage );
  2768. var index = itemNum % this.options.countPerPage;
  2769. this.fireEvent( "jumpingPage", { pageNum : pageNum, itemNum : itemNum, index : index } );
  2770. this.options.currentPage = pageNum;
  2771. this.load();
  2772. },
  2773. destroy : function(){
  2774. if( this.nextPageNode )this.nextPageNode.destroy();
  2775. //delete this;
  2776. }
  2777. });
  2778. MWF.xApplication.CRM.Template.SelectForm = new Class({
  2779. Extends: MWF.xApplication.CRM.Template.ComplexView,
  2780. initialize: function (container, data, app, explorer, options, para) {
  2781. this.container = container;
  2782. this.data = data||{};
  2783. this.explorer = explorer;
  2784. if( para ){
  2785. this.app = app || para.app || this.explorer.app;
  2786. this.lp = para.lp || this.explorer.lp || this.app.lp;
  2787. this.css = para.css || this.explorer.css || this.app.css;
  2788. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  2789. }else{
  2790. this.app = app || this.explorer.app;
  2791. this.lp = this.explorer.lp || this.app.lp;
  2792. this.css = this.explorer.css || this.app.css;
  2793. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  2794. }
  2795. /*template 外边传进来*/
  2796. if (!options.templateUrl) {
  2797. options.templateUrl = this.explorer.path + "listItem.json"
  2798. } else if (options.templateUrl.indexOf("/") == -1) {
  2799. options.templateUrl = this.explorer.path + options.templateUrl;
  2800. }
  2801. console.log(options);
  2802. this.setOptions(options);
  2803. this.container.setAttribute("id","selectForm");
  2804. this.container.setStyle("padding",0);
  2805. },
  2806. _createDocument: function(data){
  2807. return new MWF.xApplication.CRM.Clue.Document(this.viewNode, data, this.explorer, this);
  2808. },
  2809. ayalyseTemplate: function () {
  2810. MWF.getJSON(this.options.templateUrl, function (json) {
  2811. this.template = json;
  2812. console.log("this is template,",json);
  2813. }.bind(this), false)
  2814. },
  2815. //一般需要重写分页方法
  2816. _getCurrentPageData: function(callback, count, page, searchText){
  2817. var category = this.category = this.options.category;
  2818. if (!count)count = 10;
  2819. if (!page)page = 1;
  2820. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  2821. //if(id=="(0)")this.app.createShade();
  2822. var filter = this.options.filterData || {};
  2823. if(searchText){
  2824. filter = {
  2825. key:searchText
  2826. };
  2827. }
  2828. this.actions.getCustomerListPage(page, count, filter, function (json) {
  2829. if (callback)callback(json);
  2830. }.bind(this));
  2831. },
  2832. getResult : function(){
  2833. var reslult = {};
  2834. console.log(this.dataList,this.selectData);
  2835. for(index in this.dataList){
  2836. var data = this.dataList[index];
  2837. if(data.id == this.selectData){
  2838. reslult = data;
  2839. break;
  2840. }
  2841. }
  2842. return reslult;
  2843. },
  2844. useTablePlugins: function (cpage,searchText) {
  2845. if(this.container.getNext(".laytable-box")) this.container.getNext(".laytable-box").destroy();;
  2846. var that = this;
  2847. var cdata = [];
  2848. var cols = [];
  2849. var col = [];
  2850. var sortField = "";
  2851. var sortType = "";
  2852. var selectObject = this.template;
  2853. var count = 10;
  2854. sortField = selectObject.sortField;
  2855. sortType = selectObject.sortType;
  2856. if (!cpage)cpage = 1;
  2857. cols = selectObject.field;
  2858. //cols.push(col);
  2859. this._getCurrentPageData(function (json) {
  2860. json.data.each(function (data ) {
  2861. cdata.push(data);
  2862. }.bind(this));
  2863. layui.config({
  2864. base: '../x_component_CRM/$Template/plugins/table2/'
  2865. }).use(['table2', "table2"], function () {
  2866. var table = layui.table2;
  2867. console.log(cols);
  2868. var tableIns = table.render({
  2869. elem: "#selectForm",
  2870. data: cdata,
  2871. height: 310,
  2872. width: '100%',
  2873. page: {
  2874. align: 'right',
  2875. groups: 5,//显示连续页码数量
  2876. curr:1,
  2877. count: json.count,//总条数
  2878. limit:10,
  2879. limits:[10, 20, 30, 40, 50, 60, 70, 80, 90]
  2880. },
  2881. initSort: {
  2882. sortField: sortField,
  2883. sortType: sortType
  2884. },
  2885. cols:[cols]
  2886. });
  2887. });
  2888. var self = this;
  2889. this.dataList = cdata;
  2890. this.selectData = {};
  2891. var tableform=this.container.getNext("div");
  2892. tableform.getElements(".laytable-body tr").forEach(function(e,i){
  2893. e.addEvents({
  2894. mouseover:function(){
  2895. this.addClass("laytable-tr-hover");
  2896. }.bind(e),
  2897. click:function () {
  2898. var ele = this.getElement(".checkbox");
  2899. if(ele.hasClass("checked")){
  2900. self.selectCheckbox = null;
  2901. self.selectData = {};
  2902. ele.removeClass("checked");
  2903. }else{
  2904. if(!self.selectCheckbox){
  2905. }else{
  2906. self.selectCheckbox.removeClass("checked");
  2907. }
  2908. self.selectData = ele.getAttribute("sid");//self.dataList[i];
  2909. self.selectCheckbox = ele;
  2910. ele.addClass("checked");
  2911. }
  2912. }.bind(e),
  2913. mouseleave:function () {
  2914. this.removeClass("laytable-tr-hover");
  2915. }.bind(e)
  2916. });
  2917. }.bind(this));
  2918. jQuery(tableform).find(".laytable-page-pagination a").each(function(index,element){
  2919. jQuery(element).on("click", function () {
  2920. //cpage = parseInt(jQuery(element).attr("value"))+cpage;
  2921. var topage = 1;
  2922. if(jQuery(element).attr("value")=="-1" || jQuery(element).attr("value")=="+1"){
  2923. topage = parseInt(jQuery(element).attr("value"))+topage;
  2924. }else{
  2925. topage = parseInt(jQuery(element).text());
  2926. }
  2927. if(jQuery(element).attr("class")!="page-item page-last rayui-disabled" && jQuery(element).attr("class")!="page-item page-prev rayui-disabled"){
  2928. //that.useTablePlugins(topage);
  2929. var searchText = jQuery(".headSearchInput").val();
  2930. if(searchText!=""){
  2931. that.useTablePlugins(topage,searchText);
  2932. }else{
  2933. that.useTablePlugins(topage);
  2934. }
  2935. }
  2936. });
  2937. }
  2938. );
  2939. jQuery(tableform).find(".laytable-page-btnok").on("click", function () {
  2940. var cpage = parseInt(jQuery(".laytable-page-input").val());
  2941. var searchText = jQuery(".headSearchInput").val();
  2942. if(searchText!=""){
  2943. that.useTablePlugins(cpage,searchText);
  2944. }else{
  2945. that.useTablePlugins(cpage);
  2946. }
  2947. //that.useTablePlugins(cpage);
  2948. });
  2949. jQuery(tableform).find(".page-item").each(function(index,element){
  2950. if(jQuery(element).attr("value")==(cpage+"")){
  2951. jQuery(element).attr("class","page-item page-active");
  2952. }else{
  2953. if(jQuery(element).attr("value")!="-1" && jQuery(element).attr("value")!="+1"){
  2954. jQuery(element).attr("class","page-item");
  2955. }
  2956. }
  2957. });
  2958. }.bind(this),count, cpage,searchText);
  2959. }
  2960. });