KeyWorkList.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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.KeyWorkList = 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.keyWork;
  15. this.path = "/x_component_Strategy/$KeyWorkList/";
  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. //delete this.listContentDiv;
  30. //try{
  31. $(this.listContentDiv).destroy();
  32. //}catch(e){}
  33. }
  34. if(this.allArrowArr.length>0){
  35. this.allArrowArr.each(function(d){
  36. $(d).setStyles({
  37. "background":"url(/x_component_Strategy/$Template/default/icons/arrow.png) no-repeat center"
  38. });
  39. }.bind(this));
  40. }
  41. }.bind(this)
  42. });
  43. this.createYearContent(function(){
  44. this.resizeContent();
  45. }.bind(this));
  46. this.app.addEvent("resize", function(){
  47. this.resizeContent();
  48. }.bind(this));
  49. },
  50. reload:function(year){
  51. this.currentYear = year;
  52. this.createYearContent();
  53. },
  54. createYearContent:function(callback){
  55. this.node.empty();
  56. this.yearContent = new Element("div.yearContent",{"styles":this.css.yearContent}).inject(this.node);
  57. this.yearContentList = new Element("div.yearContentList",{"styles":this.css.yearContentList}).inject(this.yearContent);
  58. this.actions.getKeyWorkListYear(function(json){
  59. if(json.type=="success"){
  60. if(json.data && json.data.valueList){
  61. this.yearList = json.data.valueList;
  62. this.yearList.each(function(d,i){
  63. if(i<3){
  64. new Element("div.year",{
  65. "styles":this.css.year,
  66. "value":d,
  67. "name":d,
  68. "text":d
  69. }).inject(this.yearContentList).
  70. addEvents({
  71. "click":function(){
  72. this.changeYearSelected(d);
  73. this.openList(d)
  74. }.bind(this)
  75. });
  76. }
  77. }.bind(this));
  78. if(this.yearList.length>3){
  79. new Element("div.yearMore",{"styles":this.css.year,"id":"yearMore"}).inject(this.yearContentList).
  80. setStyles({"width":"30px"}).set({"text":"..."}).
  81. addEvents({
  82. "click":function(){
  83. this.expandYears()
  84. }.bind(this)
  85. });
  86. }
  87. if(this.currentYear){
  88. if(this.yearContentList.getElements("div[name='"+this.currentYear+"']").length>0){
  89. this.yearContentList.getElements("div[name='"+this.currentYear+"']")[0].click();
  90. }
  91. }else{
  92. if(this.yearContentList.getElements("div").length>0){
  93. this.yearContentList.getElements("div")[0].click();
  94. }
  95. }
  96. if(callback)callback();
  97. }
  98. }
  99. }.bind(this));
  100. //*******************************************
  101. // 去掉新建等按钮 在应用中不操作
  102. //*******************************************
  103. //新增
  104. //this.actions.getKeyWorkAddAuthorize(
  105. // function(json){
  106. // if(json.type=="success" && json.data && json.data.value){
  107. // this.addContent = new Element("div.addContent",{"styles":this.css.addContent}).inject(this.yearContent).
  108. // addEvents({
  109. // "click":function(){
  110. // MWF.xDesktop.requireApp("Strategy", "KeyWorkForm", function(){
  111. // this.keyWorkform = new MWF.xApplication.Strategy.KeyWorkForm(this, this.app.actions,{},{
  112. // "year":this.currentYear||"",
  113. // "isNew": true,
  114. // "onPostSave" : function(){
  115. // //this.openList(this.currentYear)
  116. // this.reload(this.currentYear);
  117. // }.bind(this)
  118. // });
  119. //
  120. // this.keyWorkform.load();
  121. // }.bind(this));
  122. // }.bind(this)
  123. // });
  124. // this.addContentImg = new Element("div.addContentImg",{"styles":this.css.addContentImg}).inject(this.addContent);
  125. // this.addContentLabel = new Element("div.addContentLabel",{
  126. // "styles":this.css.addContentLabel,
  127. // "text":this.lp.add
  128. // }).inject(this.addContent);
  129. //
  130. // //导入
  131. // this.importContent = new Element("div.importContent",{"styles":this.css.importContent}).inject(this.yearContent).
  132. // addEvents({
  133. // "click":function(){
  134. // //导入
  135. // MWF.xDesktop.requireApp("Strategy", "ImportForm", function(){
  136. // this.importform = new MWF.xApplication.Strategy.ImportForm(this,
  137. // {
  138. // "id":"idddddddddddddddd"
  139. // },
  140. // {
  141. // "year":this.currentYear||"",
  142. // "isNew": true,
  143. // "onPostSave" : function(){
  144. // //this.openList(this.currentYear)
  145. // this.reload(this.currentYear);
  146. // }.bind(this)
  147. // }
  148. // );
  149. //
  150. // this.importform.load();
  151. // }.bind(this));
  152. //
  153. // }.bind(this)
  154. // });
  155. // this.importContentImg = new Element("div.importContentImg",{"styles":this.css.importContentImg}).inject(this.importContent);
  156. // this.importContentLabel = new Element("div.importContentLabel",{
  157. // "styles":this.css.importContentLabel,
  158. // "text":this.lp.imported
  159. // }).inject(this.importContent);
  160. //
  161. //
  162. // }
  163. // }.bind(this)
  164. //);
  165. },
  166. expandYears:function(){
  167. this.yearContentList.getElementById("yearMore").destroy();
  168. this.yearList.each(function(d,i){
  169. if(i>2){
  170. // new Element("div.year",{
  171. // "styles":this.css.year,
  172. // "value":d,
  173. // "name":d,
  174. // "text":d
  175. // }).inject(this.yearContentList).
  176. // addEvents({
  177. // "click":function(){
  178. // this.changeYearSelected(d);
  179. // this.openList(d)
  180. // }.bind(this)
  181. //})
  182. }
  183. }.bind(this));
  184. },
  185. openList:function(v){
  186. this.currentYear = v;
  187. this.createSearch();
  188. this.createViewContent();
  189. this.resizeContent();
  190. },
  191. changeYearSelected:function(str){
  192. this.yearContentList.getElements("div").each(function(d){
  193. if(d.get("text") == str){
  194. d.setStyles({"background-color":"#4990E2","color":"#FFFFFF"})
  195. }else{
  196. d.setStyles({"background-color":"","color":"#666666"})
  197. }
  198. }.bind(this))
  199. },
  200. createSearch:function(){
  201. if(this.searchContent) {this.searchContent.destroy();}
  202. this.searchContent = new Element("div.searchContent",{"styles":this.css.searchContent}).inject(this.node);
  203. this.searchBar = new Element("div.searchBar",{"styles":this.css.searchBar}).inject(this.searchContent);
  204. this.searchIn = new Element("input.searchIn",{
  205. "styles":this.css.searchIn,
  206. "placeholder":this.lp.defaultSearchIn
  207. }).inject(this.searchBar).
  208. addEvents({
  209. "keydown":function(e){
  210. if(this.searchIn.get("value")!="" && e.event.keyCode=="13"){
  211. this.searchReset.setStyles({"display":""});
  212. this.createViewContent({"strategydeploytitle":this.searchIn.get("value")});
  213. }
  214. }.bind(this)
  215. });
  216. this.searchImg = new Element("div.searchImg",{"styles":this.css.searchImg}).inject(this.searchBar);
  217. this.searchImg.addEvents({
  218. "click":function(){
  219. if(this.searchIn.get("value")!=""){
  220. this.searchReset.setStyles({"display":""});
  221. this.createViewContent({"strategydeploytitle":this.searchIn.get("value")})
  222. }
  223. }.bind(this)
  224. });
  225. this.searchReset = new Element("div.searchReset",{"styles":this.css.searchReset}).inject(this.searchBar).
  226. addEvents({
  227. "click":function(){
  228. this.searchIn.set("value","");
  229. this.searchReset.setStyles({"display":"none"});
  230. this.createViewContent();
  231. }.bind(this)
  232. });
  233. this.searchDeptBar = new Element("div.searchDeptBar",{"styles":this.css.searchDeptBar}).inject(this.searchContent);
  234. this.searchDeptLabel = new Element("div.searchDeptBar",{
  235. "styles":this.css.searchDeptLabel,
  236. "text":this.lp.deptList
  237. }).inject(this.searchDeptBar);
  238. //部门列表
  239. this.searchDeptList = new Element("div.searchDeptList",{"styles":this.css.searchDeptList}).inject(this.searchDeptBar);
  240. var size = {"width":230,"height":30};
  241. this.searchDeptSelector = new MWF.xApplication.Strategy.Template.Select(this.searchDeptList,this, this.actions, size);
  242. this.searchDeptSelector.load();
  243. this.actions.getKeyWorkDepartmentByYear(this.currentYear,function(json){
  244. if(json.type=="success" && json.data.valueList){
  245. this.searchDeptSelector.setDeptList(json.data.valueList,function(d){
  246. this.createViewContent({"deptlist":[d]})
  247. }.bind(this));
  248. }
  249. }.bind(this));
  250. },
  251. //视图
  252. createViewContent:function(searchObj){
  253. if(this.viewContent)this.viewContent.destroy();
  254. this.viewContent = new Element("div.viewContent",{"styles":this.css.viewContent}).inject(this.node);
  255. this.viewContentList = new Element("div.viewContentList",{"styles":this.css.viewContentList}).inject(this.viewContent);
  256. this.filter = {
  257. "strategydeployyear":this.currentYear,
  258. "ordersymbol":"ASC"
  259. };
  260. for(var item in searchObj){
  261. if(searchObj[item]!=this.app.lp.template.defaultSelect){
  262. this.filter[item] = searchObj[item];
  263. }
  264. }
  265. var templateUrl = this.path + "KeyWork.json";
  266. this.view = new MWF.xApplication.Strategy.KeyWorkList.View(this.viewContentList, this.app, {lp : this.lp.view, css : this.css, actions : this.actions }, { templateUrl : templateUrl,filterData:this.filter} );
  267. this.view.load();
  268. this.resizeContent();
  269. //this.viewContentList.getElementById("tabList").getElementsByTagName("tr").
  270. // addEvents({
  271. // "move":function(e){
  272. // alert(1)
  273. // }.bind(this)
  274. // })
  275. },
  276. dragItemData:function(){
  277. var dragSort = new Sortables("tabBody",
  278. {
  279. clone:true,
  280. opacity:0.3,
  281. //handle : ".dragTr",
  282. onStart : function (element, clone) {
  283. clone.setStyles({
  284. "position":"absolute",
  285. "margin-top":(160-this.viewContentList.getScrollTop())+"px",
  286. "border":"1px dotted #000","width":(this.viewContentList.getWidth()-10)+"px",
  287. "height":element.getHeight()+"px",
  288. "overflow":"hidden",
  289. "max-height":element.getHeight()+"px"
  290. })
  291. }.bind(this),
  292. onSort : function (element, clone) {
  293. //element.setStyle("background-color","#4990E2");
  294. //clone.setStyle('background-color', '#4990E2');
  295. }.bind(this),
  296. onComplete : function (element) {
  297. var id = element.get("id");
  298. var idStr = dragSort.serialize();
  299. var submitData = {
  300. "ordersymbol":this.filter.ordersymbol,
  301. "ids":idStr
  302. };
  303. this.actions.changeKeyWorkPosition(submitData,function(){
  304. this.createViewContent();
  305. //if(json.type=="success"){
  306. //}else{
  307. //}
  308. }.bind(this));
  309. }.bind(this)
  310. }
  311. )
  312. },
  313. resizeContent : function(){
  314. var size = this.node.getSize();
  315. if(this.yearContentList.getElements("div").length>0){
  316. var searchContentSize = this.searchContent.getSize();
  317. //var viewContentSize = this.viewContent.getSize();
  318. this.searchBar.setStyles({"width":(searchContentSize.x - this.searchDeptBar.getWidth()-100)+"px"});
  319. this.viewContent.setStyles({
  320. "height":(size.y-this.yearContent.getHeight()-this.searchContent.getHeight())+"px"
  321. });
  322. this.viewContentList.setStyles({
  323. "height":(this.viewContent.getHeight()-20)+"px",
  324. "width":(this.viewContent.getWidth-60)+"px"
  325. });
  326. }
  327. }
  328. //
  329. });
  330. MWF.xApplication.Strategy.KeyWorkList.View = new Class({
  331. Extends: MWF.xApplication.Strategy.Template.view,
  332. _createDocument: function(data){
  333. return new MWF.xApplication.Strategy.KeyWorkList.Document(this.viewBodyNode, data, this.explorer, this);
  334. },
  335. loadScrollElementList : function( count ){
  336. if (!this.isItemsLoaded) {
  337. if (!this.isItemLoadding) {
  338. this.isItemLoadding = true;
  339. this._getCurrentPageData(function (json) {
  340. var length = this.dataCount = json.count; //|| json.data.length;
  341. if (length <= this.items.length) {
  342. this.isItemsLoaded = true;
  343. }
  344. if( json.data && typeOf( json.data )=="array" ){
  345. json.data.each(function (data ) {
  346. var key = data[ this.options.documentKeyWord || "id" ];
  347. if (!this.documents[key]) {
  348. var item = this._createDocument(data, this.items.length);
  349. this.items.push(item);
  350. this.documents[key] = item;
  351. }
  352. }.bind(this));
  353. }
  354. this.isItemLoadding = false;
  355. //最后一条记录画好后,执行拖动方案
  356. if(!(this.app.keyWorkList.filter.deptlist || this.app.keyWorkList.filter.strategydeploytitle)){
  357. this.app.keyWorkList.dragItemData();
  358. }
  359. if (this.loadItemQueue > 0) {
  360. this.loadItemQueue--;
  361. this.loadElementList();
  362. }
  363. }.bind(this), count);
  364. } else {
  365. this.loadItemQueue++;
  366. }
  367. }
  368. },
  369. _getCurrentPageData: function(callback, count){
  370. //var category = this.options.category;
  371. if (!count)count = 100;
  372. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  373. if(id=="(0)")this.app.createShade();
  374. var filter = this.options.filterData || {};
  375. //filter.maxCharacterNumber = "-1";
  376. this.actions.getKeyWorkListNext(id,count,filter,function(json){
  377. if (callback)callback(json);
  378. this.app.destroyShade();
  379. }.bind(this));
  380. },
  381. _removeDocument: function(documentData){
  382. },
  383. _create: function(){
  384. },
  385. _openDocument: function( documentData ){
  386. MWF.xDesktop.requireApp("Strategy", "KeyWorkForm", function(){
  387. this.KeyWorkForm = new MWF.xApplication.Strategy.KeyWorkForm(this, this.actions,{"id":documentData.id},{
  388. "isEdited":false
  389. } );
  390. this.KeyWorkForm.load();
  391. }.bind(this));
  392. },
  393. _queryCreateViewNode: function(){
  394. },
  395. _postCreateViewNode: function( ){
  396. },
  397. _queryCreateViewHead:function(){
  398. },
  399. _postCreateViewHead: function( headNode ){
  400. }
  401. });
  402. MWF.xApplication.Strategy.KeyWorkList.Document = new Class({
  403. Extends: MWF.xApplication.Strategy.Template.Document,
  404. openActionReturn:function(d) {
  405. var ret = false;
  406. if(d.actions && d.actions.length==1){
  407. ret = true;
  408. }
  409. return ret;
  410. },
  411. editActionReturn:function(d) {
  412. var ret = false;
  413. if (d.actions && d.actions.indexOf("EDIT")>-1)ret = true;
  414. return ret;
  415. },
  416. deleteActionReturn:function(d) {
  417. var ret = false;
  418. if (d.actions && d.actions.indexOf("DELETE")>-1)ret = true;
  419. return ret;
  420. },
  421. action_open:function(){
  422. MWF.xDesktop.requireApp("Strategy", "KeyWorkForm", function(){
  423. this.keyWorkform = new MWF.xApplication.Strategy.KeyWorkForm(this, this.actions,{"id":this.data.id},{
  424. "isEdited":false
  425. } );
  426. this.keyWorkform.load();
  427. }.bind(this));
  428. },
  429. action_edit:function(){
  430. MWF.xDesktop.requireApp("Strategy", "KeyWorkForm", function(){
  431. this.keyWorkform = new MWF.xApplication.Strategy.KeyWorkForm(this, this.app.actions,{"id":this.data.id},{
  432. "isNew":false,
  433. "isEdited": true,
  434. "onPostSave" : function(){
  435. this.app.keyWorkList.openList(this.app.keyWorkList.currentYear)
  436. }.bind(this)
  437. });
  438. this.keyWorkform.load();
  439. }.bind(this));
  440. },
  441. action_delete:function(e){
  442. var _self = this;
  443. _self.view.app.confirm(
  444. "warn",
  445. e,
  446. _self.view.app.lp.keyWork.submitWarn.title,
  447. _self.view.app.lp.keyWork.submitWarn.content.deleted,
  448. 300,
  449. 120,
  450. function(){
  451. _self.actions.deleteKeyWork(_self.data.id, function(json){
  452. if(json.type && json.type=="success"){
  453. this.app.notice(_self.view.app.lp.prompt.keyWork.deleteOK, "success");
  454. _self.app.keyWorkList.openList(this.app.keyWorkList.currentYear);
  455. }
  456. }.bind(_self));
  457. this.close();
  458. },
  459. function(){
  460. this.close();
  461. }
  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. //if(!(this.app.keyWorkList.filter.deptList && this.app.keyWorkList.filter.strategydeploytitle)){//alert("dr")
  476. // this.app.keyWorkList.dragItemData();
  477. // }
  478. }
  479. });