Template.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. MWF.xApplication.Strategy = MWF.xApplication.Strategy || {};
  2. MWF.xApplication.Strategy.Template = MWF.xApplication.Strategy.Template || {};
  3. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  4. String.implement({
  5. toDOM: function( container, callback ){
  6. var wrapper = this.test('^<the|^<tf|^<tb|^<colg|^<ca') && ['<table>', '</table>', 1] ||
  7. this.test('^<col') && ['<table><colgroup>', '</colgroup><tbody></tbody></table>',2] ||
  8. this.test('^<tr') && ['<table><tbody>', '</tbody></table>', 2] ||
  9. this.test('^<th|^<td') && ['<table><tbody><tr>', '</tr></tbody></table>', 3] ||
  10. this.test('^<li') && ['<ul>', '</ul>', 1] ||
  11. this.test('^<dt|^<dd') && ['<dl>', '</dl>', 1] ||
  12. this.test('^<le') && ['<fieldset>', '</fieldset>', 1] ||
  13. this.test('^<opt') && ['<select multiple="multiple">', '</select>', 1] ||
  14. ['', '', 0];
  15. if( container ){
  16. var el = new Element('div', {html: wrapper[0] + this + wrapper[1]}).getChildren();
  17. while(wrapper[2]--) el = el[0].getChildren();
  18. el.inject( container );
  19. if( callback )callback( container );
  20. return el;
  21. }else{
  22. var div = new Element('div', {html: wrapper[0] + this + wrapper[1]});
  23. div.setStyle("display","none").inject( $(document.body) );
  24. if( callback )callback( div );
  25. var el = div.getChildren();
  26. while(wrapper[2]--) el = el[0].getChildren();
  27. div.dispose();
  28. return el;
  29. }
  30. }
  31. });
  32. MWF.xApplication.Strategy.Template.Select = new Class({
  33. Extends: MWF.widget.Common,
  34. Implements: [Options, Events],
  35. options: {
  36. "style": "default",
  37. "width": "800",
  38. "height": "100%"
  39. },
  40. initialize: function (node ,explorer, actions, options) {
  41. this.setOptions(options);
  42. this.app = explorer.app;
  43. this.explorer = explorer;
  44. this.lp = this.app.lp.template;
  45. this.actions = this.app.restActions;
  46. this.path = "../x_component_Strategy/Template/";
  47. this.loadCss();
  48. this.node = $(node);
  49. this.actions = actions;
  50. },
  51. loadCss: function () {
  52. this.cssPath = "../x_component_Strategy/$Template/" + this.options.style + "/css.wcss";
  53. this._loadCss();
  54. },
  55. load:function(data,callback){
  56. this._width = this.options.width?this.options.width:230;
  57. this._height = this.options.height?this.options.height:30;
  58. this._available = this.options.available?this.options.available:"yes";
  59. this.createDefault();
  60. this.explorer.allArrowArr.push(this.selectArrowDiv);
  61. //this.setList(data,callback);
  62. if(callback)callback();
  63. },
  64. createDefault:function(){
  65. if(this.node)this.node.empty();
  66. this.selectValueDiv = new Element("div.selectValueDiv",{
  67. "styles":this.css.selectValueDiv,
  68. "id":this.node.get("id")+"Value",
  69. "text":this.lp.defaultSelect
  70. }).inject(this.node);
  71. this.selectArrowDiv = new Element("div.selectArrowDiv",{
  72. "styles":this.css.selectArrowDiv
  73. }).inject(this.node);
  74. this.selectArrowDiv.setStyles({
  75. "width":this._height+"px",
  76. "height":this._height+"px"
  77. });
  78. this.node.setStyles(this.css.selectDiv);
  79. this.node.setStyles({
  80. "width":this._width+"px",
  81. "height":this._height+"px",
  82. "background-color":this._available=="no"?"#eeeeee":""
  83. });
  84. this.node.set("available",this._available);
  85. this.selectValueDiv.setStyles({
  86. "width":(this._width-this._height-10)+"px",
  87. "height":this._height+"px",
  88. "line-height":this._height+"px"
  89. });
  90. },
  91. setAddress:function(data,callback){
  92. data = data || {};
  93. var _self = this;
  94. this.node.removeEvents("click");
  95. this.node.addEvents({
  96. "click":function(e){
  97. if(!data)return false;
  98. if(_self.node.get("available")=="no") return false;
  99. _self.selectArrowDiv.setStyles({
  100. "background":"url(../x_component_Strategy/$Template/default/icons/arrow-up.png) no-repeat center"
  101. });
  102. //if(_self.explorer.listContentDiv)_self.explorer.listContentDiv.destroy();
  103. //if(_self.explorer.listDiv)_self.explorer.listDiv.destroy();
  104. _self.explorer.listContentDiv = new Element("div.listContentDiv",{"styles":_self.css.listContentDiv,"id":"listContentDiv"}).inject(_self.node);
  105. _self.explorer.listContentDiv.setStyles({
  106. "width":_self.node.getSize().x+"px",
  107. "margin-top":(_self.node.getSize().y)+"px",
  108. "z-index":"300"
  109. });
  110. _self.listDiv = new Element("div.listDiv",{"styles":_self.css.listDiv}).inject(_self.explorer.listContentDiv);
  111. _self.app.setScrollBar(_self.listDiv);
  112. data.unshift({
  113. "cityname":_self.lp.defaultSelect
  114. });
  115. data.each(function(d){
  116. var listLi = new Element("li.listLi",{
  117. "styles":_self.css.listLi,
  118. "text": d.cityname
  119. }).inject(_self.listDiv);
  120. listLi.setStyles({
  121. "color":_self.selectValueDiv.get("text")==listLi.get("text")?"#ffffff":"",
  122. "background-color":_self.selectValueDiv.get("text")==listLi.get("text")?"#3d77c1":""
  123. });
  124. listLi.addEvents({
  125. "click":function(ev){
  126. _self.node.set("value",this.get("text"));
  127. _self.explorer.listContentDiv.destroy();
  128. _self.selectArrowDiv.setStyles({"background":"url(../x_component_Strategy/$Template/default/icons/arrow.png) no-repeat center"});
  129. if(_self.selectValueDiv.get("text")!=this.get("text")){
  130. _self.selectValueDiv.set({"text":this.get("text")});
  131. if(callback)callback(d);
  132. }
  133. ev.stopPropagation();
  134. },
  135. "mouseover":function(){
  136. if(this.get("text") != _self.selectValueDiv.get("text")){
  137. this.setStyles({
  138. "background-color":"#ccc",
  139. "color":"#ffffff"
  140. });
  141. }
  142. },
  143. "mouseout":function(){
  144. if(this.get("text") != _self.selectValueDiv.get("text")){
  145. this.setStyles({
  146. "background-color":"",
  147. "color":""
  148. });
  149. }
  150. }
  151. });
  152. }.bind(_self));
  153. data.splice(0,1);
  154. e.stopPropagation();
  155. }.bind(this)
  156. })
  157. },
  158. setDeptList:function(data,callback){
  159. data = data || {};
  160. var _self = this;
  161. this.node.removeEvents("click");
  162. this.node.addEvents({
  163. "click":function(e){
  164. //if(!data.childNodes)return false;
  165. if(_self.node.get("available")=="no") return false;
  166. _self.selectArrowDiv.setStyles({
  167. "background":"url(../x_component_Strategy/$Template/default/icons/arrow-up.png) no-repeat center"
  168. });
  169. //if(_self.explorer.listContentDiv)_self.explorer.listContentDiv.destroy();
  170. //if(_self.explorer.listDiv)_self.explorer.listDiv.destroy();
  171. _self.explorer.listContentDiv = new Element("div.listContentDiv",{"styles":_self.css.listContentDiv,"id":"listContentDiv"}).inject(_self.node);
  172. _self.explorer.listContentDiv.setStyles({
  173. "width":_self.node.getSize().x+"px",
  174. "margin-top":(_self.node.getSize().y)+"px",
  175. "z-index":"300"
  176. });
  177. _self.listDiv = new Element("div.listDiv",{"styles":_self.css.listDiv}).inject(_self.explorer.listContentDiv);
  178. _self.app.setScrollBar(_self.listDiv);
  179. data.unshift(_self.lp.defaultSelect);
  180. data.each(function(d){
  181. var listLi = new Element("li.listLi",{
  182. "styles":_self.css.listLi,
  183. "unit":d==_self.lp.defaultSelect ? _self.lp.defaultSelect : d,
  184. "text": d.split("@")[0]
  185. }).inject(_self.listDiv);
  186. listLi.setStyles({
  187. "color":_self.selectValueDiv.get("unit")==listLi.get("unit")?"#ffffff":"",
  188. "background-color":_self.selectValueDiv.get("unit")==listLi.get("unit")?"#3d77c1":""
  189. });
  190. listLi.addEvents({
  191. "click":function(ev){
  192. _self.selectValueDiv.set({
  193. "text":this.get("text"),
  194. "unit":this.get("unit")
  195. });
  196. _self.node.set("unit",this.get("unit"));
  197. _self.explorer.listContentDiv.destroy();
  198. _self.selectArrowDiv.setStyles({"background":"url(../x_component_Strategy/$Template/default/icons/arrow.png) no-repeat center"});
  199. if(callback)callback(d);
  200. ev.stopPropagation();
  201. },
  202. "mouseover":function(){
  203. if(this.get("unit") != _self.selectValueDiv.get("unit")){
  204. this.setStyles({
  205. "background-color":"#ccc",
  206. "color":"#ffffff"
  207. });
  208. }
  209. },
  210. "mouseout":function(){
  211. if(this.get("unit") != _self.selectValueDiv.get("unit")){
  212. this.setStyles({
  213. "background-color":"",
  214. "color":""
  215. });
  216. }
  217. }
  218. });
  219. }.bind(_self));
  220. data.splice(0,1);
  221. e.stopPropagation();
  222. }.bind(this)
  223. })
  224. },
  225. setPerPageList:function(data,callback){
  226. data = data || {};
  227. var _self = this;
  228. this.node.removeEvents("click");
  229. this.node.addEvents({
  230. "click":function(e){
  231. if(!data.value || !data.text)return false;
  232. if(_self.node.get("available")=="no") return false;
  233. _self.selectArrowDiv.setStyles({
  234. "background":"url(../x_component_Strategy/$Template/default/icons/arrow-up.png) no-repeat center"
  235. });
  236. //if(_self.explorer.listContentDiv)_self.explorer.listContentDiv.destroy();
  237. //if(_self.explorer.listDiv)_self.explorer.listDiv.destroy();
  238. _self.explorer.listContentDiv = new Element("div.listContentDiv",{"styles":_self.css.listContentDiv,"id":"listContentDiv"}).inject(_self.node);
  239. _self.explorer.listContentDiv.setStyles({
  240. "width":_self.node.getSize().x+"px",
  241. "margin-top":(_self.node.getSize().y)+"px",
  242. "z-index":"300"
  243. });
  244. _self.listDiv = new Element("div.listDiv",{"styles":_self.css.listDiv}).inject(_self.explorer.listContentDiv);
  245. _self.app.setScrollBar(_self.listDiv);
  246. data.text.unshift({
  247. "configname":_self.lp.defaultSelect
  248. });
  249. data.text.each(function(d){
  250. var listLi = new Element("li.listLi",{
  251. "styles":_self.css.listLi,
  252. "text": d.configname
  253. }).inject(_self.listDiv);
  254. listLi.setStyles({
  255. "color":_self.selectValueDiv.get("text")==listLi.get("text")?"#ffffff":"",
  256. "background-color":_self.selectValueDiv.get("text")==listLi.get("text")?"#3d77c1":""
  257. });
  258. listLi.addEvents({
  259. "click":function(ev){
  260. _self.selectValueDiv.set({"text":this.get("text")});
  261. _self.node.set("value",this.get("text"));
  262. _self.explorer.listContentDiv.destroy();
  263. _self.selectArrowDiv.setStyles({"background":"url(../x_component_Strategy/$Template/default/icons/arrow.png) no-repeat center"});
  264. if(callback)callback(d);
  265. ev.stopPropagation();
  266. },
  267. "mouseover":function(){
  268. if(this.get("text") != _self.selectValueDiv.get("text")){
  269. this.setStyles({
  270. "background-color":"#ccc",
  271. "color":"#ffffff"
  272. });
  273. }
  274. },
  275. "mouseout":function(){
  276. if(this.get("text") != _self.selectValueDiv.get("text")){
  277. this.setStyles({
  278. "background-color":"",
  279. "color":""
  280. });
  281. }
  282. }
  283. });
  284. }.bind(_self));
  285. data.text.splice(0,1);
  286. e.stopPropagation();
  287. }.bind(this)
  288. })
  289. },
  290. setList:function(data,callback){
  291. data = data || {};
  292. var _self = this;
  293. this.node.removeEvents("click");
  294. this.node.addEvents({
  295. "click":function(e){
  296. if(!data.childNodes)return false;
  297. if(_self.node.get("available")=="no") return false;
  298. _self.selectArrowDiv.setStyles({
  299. "background":"url(../x_component_Strategy/$Template/default/icons/arrow-up.png) no-repeat center"
  300. });
  301. //if(_self.explorer.listContentDiv)_self.explorer.listContentDiv.destroy();
  302. //if(_self.explorer.listDiv)_self.explorer.listDiv.destroy();
  303. _self.explorer.listContentDiv = new Element("div.listContentDiv",{"styles":_self.css.listContentDiv,"id":"listContentDiv"}).inject(_self.node);
  304. _self.explorer.listContentDiv.setStyles({
  305. "width":_self.node.getSize().x+"px",
  306. "margin-top":(_self.node.getSize().y)+"px",
  307. "z-index":"300"
  308. });
  309. _self.listDiv = new Element("div.listDiv",{"styles":_self.css.listDiv}).inject(_self.explorer.listContentDiv);
  310. _self.app.setScrollBar(_self.listDiv);
  311. data.childNodes.unshift({
  312. "configname":_self.lp.defaultSelect
  313. });
  314. data.childNodes.each(function(d){
  315. var listLi = new Element("li.listLi",{
  316. "styles":_self.css.listLi,
  317. "text": d.configname
  318. }).inject(_self.listDiv);
  319. listLi.setStyles({
  320. "color":_self.selectValueDiv.get("text")==listLi.get("text")?"#ffffff":"",
  321. "background-color":_self.selectValueDiv.get("text")==listLi.get("text")?"#3d77c1":""
  322. });
  323. listLi.addEvents({
  324. "click":function(ev){
  325. _self.selectValueDiv.set({"text":this.get("text")});
  326. _self.node.set("value",this.get("text"));
  327. _self.explorer.listContentDiv.destroy();
  328. _self.selectArrowDiv.setStyles({"background":"url(../x_component_Strategy/$Template/default/icons/arrow.png) no-repeat center"});
  329. if(callback)callback(d);
  330. ev.stopPropagation();
  331. },
  332. "mouseover":function(){
  333. if(this.get("text") != _self.selectValueDiv.get("text")){
  334. this.setStyles({
  335. "background-color":"#ccc",
  336. "color":"#ffffff"
  337. });
  338. }
  339. },
  340. "mouseout":function(){
  341. if(this.get("text") != _self.selectValueDiv.get("text")){
  342. this.setStyles({
  343. "background-color":"",
  344. "color":""
  345. });
  346. }
  347. }
  348. });
  349. }.bind(_self));
  350. data.childNodes.splice(0,1);
  351. e.stopPropagation();
  352. }.bind(this)
  353. })
  354. }
  355. });
  356. MWF.xApplication.Strategy.Template.PopupForm = new Class({
  357. Extends: MWF.widget.Common,
  358. Implements: [Options, Events],
  359. options: {
  360. "style": "default",
  361. "width": 500,
  362. "height": 450,
  363. "top": 0,
  364. "left": 0,
  365. "hasTop": false,
  366. "hasTopIcon" : false,
  367. "hasTopContent" : false,
  368. "hasIcon": true,
  369. "hasScroll" : true,
  370. "hasBottom": true,
  371. "hasMark" : true,
  372. "title": "",
  373. "draggable": false,
  374. "maxAction" : "false",
  375. "closeAction": true,
  376. "relativeToApp" : true,
  377. "sizeRelateTo" : "app" //desktop
  378. },
  379. initialize: function (explorer, data, options, para) {
  380. this.setOptions(options);
  381. this.explorer = explorer;
  382. if( para ){
  383. if( this.options.relativeToApp ){
  384. this.app = para.app || this.explorer.app;
  385. this.container = para.container || this.app.content;
  386. this.lp = para.lp || this.explorer.lp || this.app.lp;
  387. this.css = para.css || this.explorer.css || this.app.css;
  388. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  389. }else{
  390. this.container = para.container;
  391. this.lp = para.lp || this.explorer.lp;
  392. this.css = para.css || this.explorer.css;
  393. this.actions = para.actions || this.explorer.actions;
  394. }
  395. }else{
  396. if( this.options.relativeToApp ){
  397. this.app = this.explorer.app;
  398. this.container = this.app.content;
  399. this.lp = this.explorer.lp || this.app.lp;
  400. this.css = this.explorer.css || this.app.css;
  401. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  402. }else{
  403. this.container = window.document.body;
  404. this.lp = this.explorer.lp;
  405. this.css = this.explorer.css;
  406. this.actions = this.explorer.actions;
  407. }
  408. }
  409. this.data = data || {};
  410. this.cssPath = "../x_component_Strategy/$Template/"+this.options.style+"/popup.wcss";
  411. this.load();
  412. },
  413. load: function () {
  414. this._loadCss();
  415. },
  416. _loadCss: function(){
  417. var css = {};
  418. var r = new Request.JSON({
  419. url: this.cssPath,
  420. secure: false,
  421. async: false,
  422. method: "get",
  423. noCache: false,
  424. onSuccess: function(responseJSON, responseText){
  425. css = responseJSON;
  426. MWF.widget.css[key] = responseJSON;
  427. }.bind(this),
  428. onError: function(text, error){
  429. alert(error + text);
  430. }
  431. });
  432. r.send();
  433. var isEmptyObject = true;
  434. for( var key in css ){
  435. if(key)isEmptyObject = false;
  436. }
  437. if( !isEmptyObject ){
  438. this.css = Object.merge( css, this.css );
  439. }
  440. },
  441. open: function (e) {
  442. this.fireEvent("queryOpen");
  443. this.isNew = false;
  444. this.isEdited = false;
  445. this._open();
  446. this.fireEvent("postOpen");
  447. },
  448. create: function () {
  449. this.fireEvent("queryCreate");
  450. this.isNew = true;
  451. this._open();
  452. this.fireEvent("postCreate");
  453. },
  454. edit: function () {
  455. this.fireEvent("queryEdit");
  456. this.isEdited = true;
  457. this._open();
  458. this.fireEvent("postEdit");
  459. },
  460. _open: function () {
  461. if( this.options.hasMask ){
  462. this.formMaskNode = new Element("div.formMaskNode", {
  463. "styles": this.css.formMaskNode,
  464. "events": {
  465. "mouseover": function (e) {
  466. e.stopPropagation();
  467. },
  468. "mouseout": function (e) {
  469. e.stopPropagation();
  470. },
  471. "click": function (e) {
  472. e.stopPropagation();
  473. }
  474. }
  475. }).inject( this.container || this.app.content);
  476. }
  477. this.formAreaNode = new Element("div.formAreaNode", {
  478. "styles": this.css.formAreaNode
  479. });
  480. this.createFormNode();
  481. this.formAreaNode.inject(this.formMaskNode || this.container || this.app.content, "after");
  482. this.formAreaNode.fade("in");
  483. this.setFormNodeSize();
  484. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  485. if( this.app )this.app.addEvent("resize", this.setFormNodeSizeFun);
  486. if (this.options.draggable && this.formTopNode) {
  487. var size = (this.container || this.app.content).getSize();
  488. var nodeSize = this.formAreaNode.getSize();
  489. this.formAreaNode.makeDraggable({
  490. "handle": this.formTopNode,
  491. "limit": {
  492. "x": [0, size.x - nodeSize.x],
  493. "y": [0, size.y - nodeSize.y]
  494. }
  495. });
  496. }
  497. },
  498. createFormNode: function () {
  499. var _self = this;
  500. this.formNode = new Element("div.formNode", {
  501. "styles": this.css.formNode
  502. }).inject(this.formAreaNode);
  503. if (this.options.hasTop) {
  504. this.createTopNode();
  505. }
  506. if (this.options.hasIcon) {
  507. this.formIconNode = new Element("div.formIconNode", {
  508. "styles": this.isNew ? this.css.formNewNode : this.css.formIconNode
  509. }).inject(this.formNode);
  510. }
  511. this.createContent();
  512. //formContentNode.set("html", html);
  513. if (this.options.hasBottom) {
  514. this.createBottomNode();
  515. }
  516. this._setCustom();
  517. if( this.options.hasScroll ){
  518. //this.setScrollBar(this.formTableContainer)
  519. MWF.require("MWF.widget.ScrollBar", function () {
  520. new MWF.widget.ScrollBar(this.formTableContainer, {
  521. "indent": false,
  522. "style": "default",
  523. "where": "before",
  524. "distance": 30,
  525. "friction": 4,
  526. "axis": {"x": false, "y": true},
  527. "onScroll": function (y) {
  528. //var scrollSize = _self.viewContainerNode.getScrollSize();
  529. //var clientSize = _self.viewContainerNode.getSize();
  530. //var scrollHeight = scrollSize.y - clientSize.y;
  531. //if (y + 200 > scrollHeight && _self.view && _self.view.loadElementList) {
  532. // if (!_self.view.isItemsLoaded) _self.view.loadElementList();
  533. //}
  534. }
  535. });
  536. }.bind(this));
  537. }
  538. },
  539. _setCustom : function(){
  540. },
  541. createTopNode: function () {
  542. if (!this.formTopNode) {
  543. this.formTopNode = new Element("div.formTopNode", {
  544. "styles": this.css.formTopNode
  545. }).inject(this.formNode);
  546. if(this.options.hasTopIcon){
  547. this.formTopIconNode = new Element("div", {
  548. "styles": this.css.formTopIconNode
  549. }).inject(this.formTopNode)
  550. }
  551. this.formTopTextNode = new Element("div", {
  552. "styles": this.css.formTopTextNode,
  553. "text": this.options.title
  554. }).inject(this.formTopNode);
  555. if (this.options.closeAction) {
  556. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  557. this.formTopCloseActionNode.addEvent("click", function () {
  558. this.close()
  559. }.bind(this))
  560. }
  561. if(this.options.hasTopContent){
  562. this.formTopContentNode = new Element("div.formTopContentNode", {
  563. "styles": this.css.formTopContentNode
  564. }).inject(this.formTopNode);
  565. this._createTopContent();
  566. }
  567. }
  568. },
  569. _createTopContent: function () {
  570. },
  571. createContent: function () {
  572. this.formContentNode = new Element("div.formContentNode", {
  573. "styles": this.css.formContentNode
  574. }).inject(this.formNode);
  575. this.formTableContainer = new Element("div.formTableContainer", {
  576. "styles": this.css.formTableContainer
  577. }).inject(this.formContentNode);
  578. this.formTableArea = new Element("div.formTableArea", {
  579. "styles": this.css.formTableArea,
  580. "text":"loading..."
  581. }).inject(this.formTableContainer);
  582. this._createTableContent();
  583. },
  584. _createTableContent: function () {
  585. },
  586. createBottomNode: function () {
  587. this.formBottomNode = new Element("div.formBottomNode", {
  588. "styles": this.css.formBottomNode
  589. }).inject(this.formNode);
  590. this._createBottomContent()
  591. },
  592. _createBottomContent: function () {
  593. this.cancelActionNode = new Element("div.formCancelActionNode", {
  594. "styles": this.css.formCancelActionNode,
  595. "text": this.lp.actionCancel
  596. }).inject(this.formBottomNode);
  597. this.cancelActionNode.addEvent("click", function (e) {
  598. this.cancel(e);
  599. }.bind(this));
  600. },
  601. cancel: function (e) {
  602. this.fireEvent("queryCancel");
  603. this.close();
  604. this.fireEvent("postCancel");
  605. },
  606. close: function (e) {
  607. this.fireEvent("queryClose");
  608. this._close();
  609. if(this.setFormNodeSizeFun && this.app ){
  610. this.app.removeEvent("resize",this.setFormNodeSizeFun);
  611. }
  612. if( this.formMaskNode )this.formMaskNode.destroy();
  613. this.formAreaNode.destroy();
  614. this.fireEvent("postClose");
  615. delete this;
  616. },
  617. _close: function(){
  618. },
  619. ok: function (e) {
  620. this.fireEvent("queryOk");
  621. var data = this.form.getResult(true, ",", true, false, true);
  622. if (data) {
  623. this._ok(data, function (json) {
  624. if (json.type == "error") {
  625. if( this.app )this.app.notice(json.message, "error");
  626. } else {
  627. if( this.formMaskNode )this.formMaskNode.destroy();
  628. this.formAreaNode.destroy();
  629. if (this.explorer && this.explorer.view)this.explorer.view.reload();
  630. if( this.app )this.app.notice(this.isNew ? this.lp.createSuccess : this.lp.updateSuccess, "success");
  631. this.fireEvent("postOk");
  632. }
  633. }.bind(this))
  634. }
  635. },
  636. _ok: function (data, callback) {
  637. //this.app.restActions.saveDocument( this.data.id, data, function(json){
  638. // if( callback )callback(json);
  639. //}.bind(this), function( errorObj ){
  640. // var error = JSON.parse( errorObj.responseText );
  641. // this.app.notice( error.message, error );
  642. //}.bind(this));
  643. },
  644. setFormNodeSize: function (width, height, top, left) {
  645. if (!width)width = this.options.width ? this.options.width : "50%";
  646. if (!height)height = this.options.height ? this.options.height : "50%";
  647. if (!top) top = this.options.top ? this.options.top : 0;
  648. if (!left) left = this.options.left ? this.options.left : 0;
  649. //var appTitleSize = this.app.window.title.getSize();
  650. var allSize = ( this.container || this.app.content).getSize();
  651. var limitWidth = allSize.x; //window.screen.width
  652. var limitHeight = allSize.y; //window.screen.height
  653. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  654. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  655. 300 > width && (width = 300);
  656. 220 > height && (height = 220);
  657. top = top || parseInt((limitHeight - height) / 2, 10); //+appTitleSize.y);
  658. left = left || parseInt((limitWidth - width) / 2, 10);
  659. this.formAreaNode.setStyles({
  660. "width": "" + width + "px",
  661. "height": "" + height + "px",
  662. "top": "" + top + "px",
  663. "left": "" + left + "px"
  664. });
  665. this.formNode.setStyles({
  666. "width": "" + width + "px",
  667. "height": "" + height + "px"
  668. });
  669. var iconSize = this.formIconNode ? this.formIconNode.getSize() : {x: 0, y: 0};
  670. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  671. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  672. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  673. //var formMargin = formHeight -iconSize.y;
  674. this.formContentNode.setStyles({
  675. "height": "" + contentHeight + "px"
  676. });
  677. this.formTableContainer.setStyles({
  678. "height": "" + contentHeight + "px"
  679. });
  680. }
  681. });
  682. MWF.xApplication.Strategy.Template.view = new Class({
  683. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  684. Implements: [Options, Events],
  685. createViewHead: function () {
  686. this.fireEvent("queryCreateViewHead");
  687. this._queryCreateViewHead( );
  688. if (this.template) {
  689. if (!this.template.headSetting || this.template.headSetting.disable || !this.template.headSetting.html) {
  690. return;
  691. }
  692. }
  693. var _self = this;
  694. ////////////修改 增加thead,tbody//////////////////
  695. this.viewHeadNode = this.formatElement(this.viewNode, this.template.viewHeadSetting);
  696. //this.viewBodyNode = this.formatElement(this.viewNode, this.template.viewBodySetting);
  697. var headNode = this.headNode = this.formatElement(this.viewHeadNode, this.template.headSetting);
  698. //var headNode = this.headNode = this.formatElement(this.viewNode, this.template.headSetting);
  699. ////////////修改 增加thead,tbody//////////////////
  700. this.template.items.each(function (item) {
  701. if( !item.head )return;
  702. ////如果设置了权限,那么options里需要有 对应的设置项才会展现
  703. // 比如 item.access == isAdmin 那么 this.options.isAdmin要为true才展现
  704. if (item.access && !this.options[item.access])return;
  705. if (item.head.access && !this.options[item.head.access])return;
  706. var headItemNode = this.formatElement(headNode, item.head);
  707. if (item.name == "$checkbox") {
  708. this.checkboxElement = new Element("input", {
  709. "type": "checkbox"
  710. }).inject(headItemNode);
  711. this.checkboxElement.addEvent("click", function () {
  712. this.selectAllCheckbox();
  713. }.bind(this))
  714. }
  715. if (item.defaultSort && item.defaultSort != "") {
  716. this.sortFieldDefault = item.name;
  717. this.sortTypeDefault = item.defaultSort;
  718. }
  719. if (item.sort && item.sort != "") {
  720. headItemNode.store("sortField", item.name);
  721. if (this.sortField == item.name && this.sortType != "") {
  722. headItemNode.store("sortType", this.sortType);
  723. this.sortIconNode = new Element("div", {
  724. "styles": this.sortType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  725. }).inject(headItemNode, "top");
  726. } else {
  727. headItemNode.store("sortType", "");
  728. this.sortIconNode = new Element("div", {"styles": this.css.sortIconNode}).inject(headItemNode, "top");
  729. }
  730. headItemNode.setStyle("cursor", "pointer");
  731. headItemNode.addEvent("click", function () {
  732. _self.resort(this);
  733. })
  734. }
  735. }.bind(this));
  736. this.fireEvent("postCreateViewHead");
  737. this._postCreateViewHead( headNode );
  738. },
  739. createViewBody : function(){
  740. this.viewBodyNode = this.formatElement(this.viewNode, this.template.viewBodySetting);
  741. this.loadElementList();
  742. }
  743. });
  744. MWF.xApplication.Strategy.Template.Document = new Class({
  745. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  746. Implements: [Options, Events]
  747. });
  748. MWF.xApplication.Strategy.Template.Paging = new Class({
  749. Extends: MWF.xApplication.Template.Explorer.Paging,
  750. Implements: [Options, Events]
  751. });