MeasureList.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. MWF.xApplication.Strategy = MWF.xApplication.Strategy || {};
  2. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  3. MWF.xDesktop.requireApp("Strategy", "Template", null, false);
  4. MWF.require("MWF.widget.Identity", null,false);
  5. MWF.xApplication.Strategy.MeasureList = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default"
  10. },
  11. initialize: function (node, app, actions, options) {
  12. this.setOptions(options);
  13. this.app = app;
  14. this.lp = app.lp.measure;
  15. this.path = "../x_component_Strategy/$MeasureList/";
  16. this.loadCss();
  17. this.actions = actions;
  18. this.node = $(node);
  19. },
  20. loadCss: function () {
  21. this.cssPath = this.path + this.options.style + "/css.wcss";
  22. this._loadCss();
  23. },
  24. load: function () {
  25. this.allArrowArr = [];
  26. this.node.addEvents({
  27. "click": function () {
  28. if(this.listContentDiv){
  29. $(this.listContentDiv).destroy();
  30. }
  31. if(this.allArrowArr.length>0){
  32. this.allArrowArr.each(function(d){
  33. $(d).setStyles({
  34. "background":"url(../x_component_Strategy/$Template/default/icons/arrow.png) no-repeat center"
  35. });
  36. }.bind(this))
  37. }
  38. }.bind(this)
  39. });
  40. this.createYearContent(function(){
  41. this.resizeContent();
  42. }.bind(this));
  43. this.app.addEvent("resize", function(){
  44. this.resizeContent();
  45. }.bind(this));
  46. },
  47. reload:function(year){
  48. this.currentYear = year;
  49. this.createYearContent();
  50. },
  51. createYearContent:function(callback){
  52. this.node.empty();
  53. this.yearContent = new Element("div.yearContent",{"styles":this.css.yearContent}).inject(this.node);
  54. this.yearContentList = new Element("div.yearContentList",{"styles":this.css.yearContentList}).inject(this.yearContent);
  55. this.actions.getMeasureListYear(function(json){
  56. if(json.type=="success"){
  57. if(json.data && json.data.valueList){
  58. this.yearList = json.data.valueList;
  59. this.yearList.each(function(d,i){
  60. if(i<3){
  61. new Element("div.year",{
  62. "styles":this.css.year,
  63. "value":d,
  64. "name":d,
  65. "text":d
  66. }).inject(this.yearContentList).
  67. addEvents({
  68. "click":function(){
  69. this.changeYearSelected(d);
  70. this.openList(d);
  71. }.bind(this)
  72. })
  73. }
  74. }.bind(this));
  75. if(this.yearList.length>3){
  76. new Element("div.yearMore",{"styles":this.css.year,"id":"yearMore"}).inject(this.yearContentList).
  77. setStyles({"width":"30px"}).set({"text":"..."}).
  78. addEvents({
  79. "click":function(){
  80. this.expandYears()
  81. }.bind(this)
  82. })
  83. }
  84. if(this.currentYear){
  85. if(this.yearContentList.getElements("div[name='"+this.currentYear+"']").length>0){
  86. this.yearContentList.getElements("div[name='"+this.currentYear+"']")[0].click();
  87. }
  88. }else{
  89. if(this.yearContentList.getElements("div").length>0){
  90. this.yearContentList.getElements("div")[0].click();
  91. }
  92. }
  93. if(callback)callback()
  94. }
  95. }
  96. }.bind(this));
  97. //*******************************************
  98. // 去掉新建等按钮 在应用中不操作
  99. //*******************************************
  100. ////新增
  101. //this.actions.getMeasureAddAuthorize(
  102. // function(json){
  103. // if(json.type=="success" && json.data && json.data.value){
  104. // this.addContent = new Element("div.addContent",{"styles":this.css.addContent}).inject(this.yearContent).
  105. // addEvents({
  106. // "click":function(){
  107. // MWF.xDesktop.requireApp("Strategy", "MeasureForm", function(){
  108. // this.measureform = new MWF.xApplication.Strategy.MeasureForm(this, this.app.actions,{},{
  109. // "year":this.currentYear||"",
  110. // "isNew": true,
  111. // "onPostSave" : function(){
  112. // //this.openList(this.currentYear)
  113. // this.reload(this.currentYear);
  114. // }.bind(this)
  115. // });
  116. //
  117. // this.measureform.load();
  118. // }.bind(this));
  119. // }.bind(this)
  120. // });
  121. // this.addContentImg = new Element("div.addContentImg",{"styles":this.css.addContentImg}).inject(this.addContent);
  122. // this.addContentLabel = new Element("div.addContentLabel",{
  123. // "styles":this.css.addContentLabel,
  124. // "text":this.lp.add
  125. // }).inject(this.addContent);
  126. // }
  127. // }.bind(this)
  128. //);
  129. },
  130. expandYears:function(){
  131. this.yearContentList.getElementById("yearMore").destroy();
  132. this.yearList.each(function(d,i){
  133. if(i>2){
  134. new Element("div.year",{
  135. "styles":this.css.year,
  136. "value":d,
  137. "name":d,
  138. "text":d
  139. }).inject(this.yearContentList).
  140. addEvents({
  141. "click":function(){
  142. this.changeYearSelected(d);
  143. this.openList(d)
  144. }.bind(this)
  145. })
  146. }
  147. }.bind(this))
  148. },
  149. openList:function(v){
  150. this.currentYear = v;
  151. this.createSearch();
  152. this.createViewContent();
  153. this.resizeContent();
  154. },
  155. changeYearSelected:function(str){
  156. this.yearContentList.getElements("div").each(function(d){
  157. if(d.get("text") == str){
  158. d.setStyles({"background-color":"#4990E2","color":"#FFFFFF"})
  159. }else{
  160. d.setStyles({"background-color":"","color":"#666666"})
  161. }
  162. }.bind(this))
  163. },
  164. createSearch:function(){
  165. if(this.searchContent) this.searchContent.destroy();
  166. this.searchContent = new Element("div.searchContent",{"styles":this.css.searchContent}).inject(this.node);
  167. this.searchBar = new Element("div.searchBar",{"styles":this.css.searchBar}).inject(this.searchContent);
  168. this.searchIn = new Element("input.searchIn",{
  169. "styles":this.css.searchIn,
  170. "placeholder":this.lp.defaultSearchIn
  171. }).inject(this.searchBar).
  172. addEvents({
  173. "keydown":function(e){
  174. if(this.searchIn.get("value")!="" && e.event.keyCode=="13"){
  175. this.searchReset.setStyles({"display":""});
  176. this.createViewContent({"measuresinfotitle":this.searchIn.get("value")});
  177. }
  178. }.bind(this)
  179. });
  180. this.searchImg = new Element("div.searchImg",{"styles":this.css.searchImg}).inject(this.searchBar);
  181. this.searchImg.addEvents({
  182. "click":function(){
  183. if(this.searchIn.get("value")!=""){
  184. this.searchReset.setStyles({"display":""});
  185. this.createViewContent({"measuresinfotitle":this.searchIn.get("value")})
  186. }
  187. }.bind(this)
  188. });
  189. this.searchReset = new Element("div.searchReset",{"styles":this.css.searchReset}).inject(this.searchBar).
  190. addEvents({
  191. "click":function(){
  192. this.searchIn.set("value","");
  193. this.searchReset.setStyles({"display":"none"});
  194. this.createViewContent();
  195. }.bind(this)
  196. });
  197. this.searchDeptBar = new Element("div.searchDeptBar",{"styles":this.css.searchDeptBar}).inject(this.searchContent);
  198. this.searchDeptLabel = new Element("div.searchDeptBar",{
  199. "styles":this.css.searchDeptLabel,
  200. "text":this.lp.deptList
  201. }).inject(this.searchDeptBar);
  202. //部门列表
  203. this.searchDeptList = new Element("div.searchDeptList",{"styles":this.css.searchDeptList}).inject(this.searchDeptBar);
  204. var size = {"width":230,"height":30};
  205. this.searchDeptSelector = new MWF.xApplication.Strategy.Template.Select(this.searchDeptList,this, this.actions, size);
  206. this.searchDeptSelector.load();
  207. this.actions.getMeasureDepartmentByYear(this.currentYear,function(json){
  208. if(json.type=="success" && json.data.valueList){
  209. this.searchDeptSelector.setDeptList(json.data.valueList,function(d){
  210. this.createViewContent({"deptlist":[d]},this.currentCountPerPage)
  211. }.bind(this));
  212. }
  213. }.bind(this));
  214. //this.TCustomerTypeSelector.setList(["abc","eeee","eeee2"]);
  215. //if(this.customerData && this.customerData.customertype){
  216. // this.TCustomerTypeSelector.selectValueDiv.set(["abc","eeee","eeee2"]);
  217. // this.TCustomerTypeSelector.node.set("value",["abc","eeee","eeee2"]);
  218. //}
  219. },
  220. //视图
  221. createViewContent:function(searchObj,perPage,curPage){
  222. this.searchObj = searchObj;
  223. this.perPageJson = {
  224. "text":this.app.lp.template.paging.perPageText.split(","),
  225. "value":this.app.lp.template.paging.perPageValue.split(",")
  226. };
  227. this.currentCountPerPage = perPage || this.perPageJson.value[0];
  228. if(this.viewContent)this.viewContent.destroy();
  229. this.viewContent = new Element("div.viewContent",{"styles":this.css.viewContent}).inject(this.node);
  230. this.viewContentList = new Element("div.viewContentList",{"styles":this.css.viewContentList}).inject(this.viewContent);
  231. this.createPageContent();
  232. this.filter = {
  233. "measuresinfoyear":this.currentYear,
  234. "ordersymbol":"ASC"
  235. };
  236. //if(!perPage){
  237. for(var item in searchObj){
  238. if(searchObj[item]!=this.app.lp.template.defaultSelect){
  239. this.filter[item] = searchObj[item];
  240. }
  241. }
  242. //}
  243. var templateUrl = this.path + "Measure.json";
  244. this.view = new MWF.xApplication.Strategy.MeasureList.View(this.viewContentList, this.app,
  245. { lp : this.lp.view, css : this.css, actions : this.actions },
  246. {
  247. pagingEnable : true,
  248. pagingPar : {
  249. currentPage : curPage || this.options.viewPageNum,
  250. countPerPage : this.currentCountPerPage || this.perPageJson.value[0],
  251. hasJumper:false,
  252. hasNextPage:false,
  253. hasReturn:false,
  254. position : [ "bottom" ],
  255. hiddenWithDisable : false,
  256. text : {
  257. prePage : this.app.lp.template.paging.prePage,
  258. nextPage : this.app.lp.template.paging.nextPage,
  259. firstPage : this.app.lp.template.paging.firstPage,
  260. lastPage : this.app.lp.template.paging.lastPage
  261. },
  262. onPostLoad:function(){
  263. //显示每页几条select
  264. if(this.view && this.view.paging){
  265. //var size = {"width":70,"height":24};
  266. this.perPageChangeContent = new Element("div.perPageChangeContent",{"styles":this.css.perPageChangeContent}).inject(this.view.paging.node);
  267. this.countPerPageItem = new MDomItem(this.perPageChangeContent,{
  268. "name":"countPerPageSelect",
  269. "type":"select",
  270. "selectValue":this.perPageJson.value,
  271. "selectText":this.perPageJson.text,
  272. "defaultValue":this.currentCountPerPage || this.perPageJson.value[0],
  273. "attr":{"style":"border-radius:2px;border:1px solid #cccccc;height:24px"},
  274. "event":{
  275. change: function (item, ev) {
  276. if(item.get("value")!=""){
  277. this.currentCountPerPage = item.get("value");
  278. this.createViewContent(this.searchObj,item.get("value"))
  279. }
  280. }.bind(this)
  281. }
  282. } , this, this.app, this.css);
  283. this.countPerPageItem.load();
  284. }
  285. }.bind(this)
  286. },
  287. templateUrl : templateUrl,
  288. filterData:this.filter
  289. }
  290. );
  291. this.view.pagingContainerBottom = this.pageContent;
  292. this.view.load();
  293. this.resizeContent();
  294. },
  295. //分页
  296. createPageContent:function(){
  297. if(this.pageContent)$(this.pageContent).destroy();
  298. this.pageContent = new Element("div.pageContent",{"styles":this.css.pageContent}).inject(this.viewContent);
  299. },
  300. dragItemData:function(){
  301. var dragSort = new Sortables("tabBody",
  302. {
  303. clone:true,
  304. opacity:0.3,
  305. //handle : ".dragTr",
  306. onStart : function (element, clone) {
  307. clone.setStyles({
  308. "position":"absolute",
  309. "margin-top":(160-this.viewContentList.getScrollTop())+"px",
  310. "border":"1px dotted #000","width":(this.viewContentList.getWidth()-10)+"px",
  311. "height":element.getHeight()+"px",
  312. "overflow":"hidden",
  313. "max-height":element.getHeight()+"px"
  314. })
  315. }.bind(this),
  316. onSort : function (element, clone) {
  317. //element.setStyle("background-color","#4990E2");
  318. //clone.setStyle('background-color', '#4990E2');
  319. }.bind(this),
  320. onComplete : function (element) {
  321. var id = element.get("id");
  322. var idStr = dragSort.serialize();
  323. var submitData = {
  324. "ordersymbol":this.filter.ordersymbol,
  325. "ids":idStr
  326. };
  327. //this.actions.changeKeyWorkPosition(submitData,function(json){
  328. // this.createViewContent();
  329. // //if(json.type=="success"){
  330. //
  331. // //}else{
  332. //
  333. // //}
  334. //}.bind(this));
  335. }.bind(this)
  336. }
  337. )
  338. },
  339. resizeContent : function(){
  340. var size = this.node.getSize();
  341. if(this.yearContentList.getElements("div").length>0){
  342. var searchContentSize = this.searchContent.getSize();
  343. //var viewContentSize = this.viewContent.getSize();
  344. this.searchBar.setStyles({"width":(searchContentSize.x - this.searchDeptBar.getWidth()-100)+"px"});
  345. this.viewContent.setStyles({
  346. "height":(size.y-this.yearContent.getHeight()-this.searchContent.getHeight())+"px"
  347. });
  348. this.viewContentList.setStyles({
  349. "height":(this.viewContent.getHeight()-this.pageContent.getHeight()-20)+"px",
  350. "width":(this.viewContent.getWidth-60)+"px"
  351. });
  352. }
  353. }
  354. });
  355. MWF.xApplication.Strategy.MeasureList.View = new Class({
  356. Extends: MWF.xApplication.Strategy.Template.view,
  357. _createDocument: function(data){
  358. return new MWF.xApplication.Strategy.MeasureList.Document(this.viewBodyNode, data, this.explorer, this);
  359. },
  360. _getCurrentPageData: function(callback, count, pageNum){
  361. this.clearBody();
  362. if (!count)count = 10;
  363. //var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  364. //if(id=="(0)")this.app.createShade();
  365. if(!pageNum)pageNum = 1;
  366. var filter = this.options.filterData || {};
  367. //filter.maxCharacterNumber = "-1";
  368. this.actions.getMeasureListPage(pageNum,count,filter,function(json){
  369. if (callback)callback(json);
  370. //执行拖动方案
  371. if(!(this.app.measureList.filter.deptlist || this.app.measureList.filter.measuresinfotitle)){
  372. this.app.measureList.dragItemData();
  373. }
  374. this.app.destroyShade();
  375. }.bind(this));
  376. },
  377. _removeDocument: function(documentData){
  378. },
  379. _create: function(){
  380. },
  381. _openDocument: function( documentData ){
  382. MWF.xDesktop.requireApp("Strategy", "MeasureForm", function(){
  383. this.MeasureForm = new MWF.xApplication.Strategy.MeasureForm(this, this.actions,{
  384. "id":documentData.id,
  385. "maxAction":true
  386. },{
  387. "isEdited":false
  388. } );
  389. this.MeasureForm.load();
  390. }.bind(this));
  391. },
  392. _queryCreateViewNode: function(){
  393. },
  394. _postCreateViewNode: function( ){
  395. },
  396. _queryCreateViewHead:function(){
  397. },
  398. _postCreateViewHead: function( headNode ){
  399. }
  400. });
  401. MWF.xApplication.Strategy.MeasureList.Document = new Class({
  402. Extends: MWF.xApplication.Strategy.Template.Document,
  403. openActionReturn:function(d) {
  404. var ret = false;
  405. if(d.actions && d.actions.length==1){
  406. ret = true;
  407. }
  408. return ret;
  409. },
  410. editActionReturn:function(d) {
  411. var ret = false;
  412. if (d.actions && d.actions.indexOf("EDIT")>-1)ret = true;
  413. return ret;
  414. },
  415. deleteActionReturn:function(d) {
  416. var ret = false;
  417. if (d.actions && d.actions.indexOf("DELETE")>-1)ret = true;
  418. return ret;
  419. },
  420. action_open:function(){
  421. MWF.xDesktop.requireApp("Strategy", "MeasureForm", function(){
  422. this.MeasureForm = new MWF.xApplication.Strategy.MeasureForm(this, this.actions,{"id":this.data.id},{
  423. "isEdited":false
  424. } );
  425. this.MeasureForm.load();
  426. }.bind(this));
  427. },
  428. action_edit:function(){
  429. MWF.xDesktop.requireApp("Strategy", "MeasureForm", function(){
  430. this.Measureform = new MWF.xApplication.Strategy.MeasureForm(this, this.app.actions,{"id":this.data.id},{
  431. "isNew":false,
  432. "isEdited": true,
  433. "onPostSave" : function(){
  434. var _parent = this.app.measureList;
  435. var searchObj = {};
  436. var searchIn = _parent.searchIn.get("value");
  437. if(searchIn!=""){
  438. searchObj.measuresinfotitle = searchIn
  439. }
  440. var searchDept = _parent.searchDeptList.get("unit");
  441. if(searchDept){
  442. searchObj.deptlist = [searchDept]
  443. }
  444. _parent.createViewContent(searchObj,_parent.currentCountPerPage,_parent.view.currentPage);
  445. }.bind(this)
  446. });
  447. this.Measureform.load();
  448. }.bind(this));
  449. },
  450. action_delete:function(e){
  451. var _self = this;
  452. _self.view.app.confirm("warn",e,_self.view.app.lp.measure.submitWarn.title,_self.view.app.lp.measure.submitWarn.content.deleted,300,120,function(){
  453. _self.actions.deleteMeasure(_self.data.id, function(json){
  454. if(json.type && json.type=="success"){
  455. this.app.notice(_self.view.app.lp.prompt.measure.deleteOK, "success");
  456. _self.app.measureList.openList(this.app.measureList.currentYear)
  457. }
  458. }.bind(_self));
  459. this.close();
  460. },function(){
  461. this.close();
  462. })
  463. },
  464. _postCreateDocumentNode: function( itemNode, itemData ){
  465. itemNode.set("id",itemData.id);
  466. if(!this.openActionReturn(itemData)){
  467. itemNode.getElements("[item='action_open']").destroy();
  468. }
  469. if(!this.editActionReturn(itemData)){
  470. itemNode.getElements("[item='action_edit']").destroy();
  471. }
  472. if(!this.deleteActionReturn(itemData)){
  473. itemNode.getElements("[item='action_delete']").destroy();
  474. }
  475. }
  476. });