PriorityList.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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.PriorityList = 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. //alert(JSON.stringify(app.lp.priority))
  14. this.app = app;
  15. this.lp = app.lp.priority;
  16. this.path = "../x_component_Strategy/$PriorityList/";
  17. this.loadCss();
  18. this.actions = actions;
  19. this.node = $(node);
  20. },
  21. loadCss: function () {
  22. this.cssPath = this.path + this.options.style + "/css.wcss";
  23. this._loadCss();
  24. },
  25. load: function () {
  26. if(this.options.style == "portal"){
  27. this.node.setStyles({
  28. "background-color":"#ffffff"
  29. });
  30. }
  31. this.allArrowArr = [];
  32. this.node.addEvents({
  33. "click": function () {
  34. if(this.listContentDiv){
  35. $(this.listContentDiv).destroy();
  36. }
  37. if(this.allArrowArr.length>0){
  38. this.allArrowArr.each(function(d){
  39. $(d).setStyles({
  40. "background":"url(../x_component_Strategy/$Template/default/icons/arrow.png) no-repeat center"
  41. });
  42. }.bind(this))
  43. }
  44. }.bind(this)
  45. });
  46. this.node.empty();
  47. this.createDepartmentNavi();
  48. //this.createYearContent(function(){
  49. // this.resizeContent();
  50. //}.bind(this));
  51. this.app.addEvent("resize", function(){
  52. this.resizeContent();
  53. }.bind(this));
  54. },
  55. reload:function(year){
  56. //this.currentYear = year;
  57. //this.createYearContent();
  58. },
  59. createDepartmentNavi:function(){
  60. this.departmentNavi = new Element("div.departmentNavi",{"styles":this.css.departmentNavi}).inject(this.node);
  61. this.actions.getPriorityDepartments(function(json){
  62. if(json.type == "success"){
  63. var _self = this;
  64. json.data.each(function(d){
  65. new Element("div.departmentItem",{
  66. "styles":_self.css.departmentItem,
  67. "distinguishedName": d.distinguishedName,
  68. "text": d.name
  69. }).inject(_self.departmentNavi).
  70. addEvents({
  71. "click":function(){
  72. _self.openDepartment(this.get("distinguishedName"))
  73. },
  74. "mouseover":function(){
  75. if(_self.currentDistinguishedName != this.get("distinguishedName")){
  76. this.setStyles({"background-color":"#D9EBFF","color":"#4990E2"})
  77. }
  78. },
  79. "mouseout":function(){
  80. if(_self.currentDistinguishedName != this.get("distinguishedName")){
  81. this.setStyles({"background-color":"","color":""})
  82. }
  83. }
  84. })
  85. }.bind(_self));
  86. this.departmentNavi.getElements(".departmentItem")[0].click();
  87. }
  88. }.bind(this));
  89. },
  90. openDepartment:function(dn){
  91. if(!dn) return;
  92. this.changeDepartmentSelect(dn);
  93. this.createYearContent(function(){
  94. this.resizeContent();
  95. }.bind(this));
  96. },
  97. changeDepartmentSelect:function(dn){
  98. if(!dn) return;
  99. this.currentDistinguishedName = dn;
  100. var allDepartments = this.departmentNavi.getElements(".departmentItem");
  101. allDepartments.each(function(d){
  102. d.setStyles({"background-color":"","color":""});
  103. if(dn == d.get("distinguishedName")){
  104. d.setStyles({"background-color":"#D9EBFF","color":"#4990E2"});
  105. }
  106. }.bind(this))
  107. },
  108. createYearContent:function(callback){
  109. if(this.rightContent) this.rightContent.destroy();
  110. this.rightContent = new Element("div.rightContent",{"styles":this.css.rightContent}).inject(this.node);
  111. this.rightContent.setStyles({
  112. "width":(this.node.getWidth()-this.departmentNavi.getWidth())+"px"
  113. });
  114. this.yearContent = new Element("div.yearContent",{"styles":this.css.yearContent}).inject(this.rightContent);
  115. this.yearContentList = new Element("div.yearContentList",{"styles":this.css.yearContentList}).inject(this.yearContent);
  116. var data = {
  117. "keyworkunit":this.currentDistinguishedName
  118. };
  119. this.actions.getYearsByDepartment(data,function(json){
  120. if(json.type == "success"){
  121. if(json.data && json.data.valueList){
  122. this.yearList = json.data.valueList;
  123. this.yearList.each(function(d,i){
  124. if(i<3){
  125. new Element("div.year",{
  126. "styles":this.css.year,
  127. "value":d,
  128. "name":d,
  129. "text":d
  130. }).inject(this.yearContentList).
  131. addEvents({
  132. "click":function(){
  133. this.changeYearSelected(d);
  134. this.openList(d)
  135. }.bind(this)
  136. })
  137. }
  138. }.bind(this));
  139. if(this.yearList.length>3){
  140. new Element("div.yearMore",{"styles":this.css.year,"id":"yearMore"}).inject(this.yearContentList).
  141. setStyles({"width":"30px"}).set({"text":"..."}).
  142. addEvents({
  143. "click":function(){
  144. this.expandYears()
  145. }.bind(this)
  146. })
  147. }
  148. if(this.currentYear){
  149. if(this.yearContentList.getElements("div[name='"+this.currentYear+"']").length>0){
  150. this.yearContentList.getElements("div[name='"+this.currentYear+"']")[0].click();
  151. }
  152. }else{
  153. if(this.yearContentList.getElements("div").length>0){
  154. this.yearContentList.getElements("div")[0].click();
  155. }
  156. }
  157. if(callback)callback()
  158. }
  159. }
  160. }.bind(this));
  161. //新增
  162. this.actions.getPriorityAddAuthorize(
  163. function(json) {
  164. if (json.type == "success" && json.data && json.data.value) {
  165. this.addContent = new Element("div.addContent",{"styles":this.css.addContent}).inject(this.yearContent).
  166. addEvents({
  167. "click":function(){
  168. MWF.xDesktop.requireApp("Strategy", "PriorityForm", function(){
  169. //function (explorer, data, options, para) {
  170. this.Priorityform = new MWF.xApplication.Strategy.PriorityForm(this,{},{
  171. "isNew":true,
  172. "onPostSave" : function(){
  173. //this.openList(this.currentYear)
  174. //this.reload(this.currentYear);
  175. this.openDepartment(this.currentDistinguishedName);
  176. }.bind(this),
  177. "width":"90%",
  178. "height":"100%",
  179. "maxAction":true,
  180. "year":this.currentYear||"",
  181. "department":this.currentDistinguishedName,
  182. "container":this.app.portalContainer || this.app.content
  183. },{
  184. //"onPostSave" : function(){
  185. // //this.openList(this.currentYear)
  186. // //this.reload(this.currentYear);
  187. // this.openDepartment(this.currentDistinguishedName);
  188. //}.bind(this),
  189. "container":this.app.portalContainer || this.app.content
  190. });
  191. this.Priorityform.load();
  192. //this.Priorityform = new MWF.xApplication.Strategy.PriorityForm(this, this.app.actions,{},{
  193. // "year":this.currentYear||"",
  194. // "department":this.currentDistinguishedName,
  195. // "isNew": true,
  196. // "onPostSave" : function(){
  197. // //this.openList(this.currentYear)
  198. // //this.reload(this.currentYear);
  199. // this.openDepartment(this.currentDistinguishedName);
  200. // }.bind(this),
  201. // "container":this.app.portalContainer || this.app.content
  202. //});
  203. //this.Priorityform.container = this.app.portalContainer || this.app.content;
  204. //this.Priorityform.load();
  205. }.bind(this));
  206. }.bind(this)
  207. });
  208. this.addContentImg = new Element("div.addContentImg",{"styles":this.css.addContentImg}).inject(this.addContent);
  209. this.addContentLabel = new Element("div.addContentLabel",{
  210. "styles":this.css.addContentLabel,
  211. "text":this.lp.add
  212. }).inject(this.addContent);
  213. }
  214. }.bind(this)
  215. );
  216. },
  217. expandYears:function(){
  218. this.yearContentList.getElementById("yearMore").destroy();
  219. this.yearList.each(function(d,i){
  220. if(i>2){
  221. new Element("div.year",{
  222. "styles":this.css.year,
  223. "value":d,
  224. "name":d,
  225. "text":d
  226. }).inject(this.yearContentList).
  227. addEvents({
  228. "click":function(){
  229. this.changeYearSelected(d);
  230. this.openList(d)
  231. }.bind(this)
  232. })
  233. }
  234. }.bind(this))
  235. },
  236. openList:function(v){
  237. this.currentYear = v;
  238. this.createSearch();
  239. this.createViewContent();
  240. },
  241. changeYearSelected:function(str){
  242. this.yearContentList.getElements("div").each(function(d){
  243. if(d.get("text") == str){
  244. d.setStyles({"background-color":"#4990E2","color":"#FFFFFF"})
  245. }else{
  246. d.setStyles({"background-color":"","color":"#666666"})
  247. }
  248. }.bind(this))
  249. },
  250. createSearch:function(){
  251. if(this.searchContent) this.searchContent.destroy();
  252. this.searchContent = new Element("div.searchContent",{"styles":this.css.searchContent}).inject(this.rightContent);
  253. this.searchBar = new Element("div.searchBar",{"styles":this.css.searchBar}).inject(this.searchContent);
  254. this.searchIn = new Element("input.searchIn",{
  255. "styles":this.css.searchIn,
  256. "placeholder":this.lp.defaultSearchIn
  257. }).inject(this.searchBar).
  258. addEvents({
  259. "keydown":function(e){
  260. if(this.searchIn.get("value")!="" && e.event.keyCode=="13"){
  261. this.searchReset.setStyles({"display":""});
  262. this.createViewContent({"keyworktitle":this.searchIn.get("value")});
  263. }
  264. }.bind(this)
  265. });
  266. this.searchImg = new Element("div.searchImg",{"styles":this.css.searchImg}).inject(this.searchBar);
  267. this.searchImg.addEvents({
  268. "click":function(){
  269. if(this.searchIn.get("value")!=""){
  270. this.searchReset.setStyles({"display":""});
  271. this.createViewContent({"keyworktitle":this.searchIn.get("value")})
  272. }
  273. }.bind(this)
  274. });
  275. this.searchReset = new Element("div.searchReset",{"styles":this.css.searchReset}).inject(this.searchBar).
  276. addEvents({
  277. "click":function(){
  278. this.searchIn.set("value","");
  279. this.searchReset.setStyles({"display":"none"});
  280. this.createViewContent();
  281. }.bind(this)
  282. });
  283. },
  284. //视图
  285. createViewContent:function(searchObj){
  286. if(this.viewContent)this.viewContent.destroy();
  287. this.viewContent = new Element("div.viewContent",{"styles":this.css.viewContent}).inject(this.rightContent);
  288. this.viewContentList = new Element("div.viewContentList",{"styles":this.css.viewContentList}).inject(this.viewContent);
  289. this.filter = {
  290. "keyworkyear":this.currentYear,
  291. "keyworkunit":this.currentDistinguishedName,
  292. "ordersymbol":"ASC"
  293. };
  294. for(var item in searchObj){
  295. if(searchObj[item]!=this.app.lp.template.defaultSelect){
  296. this.filter[item] = searchObj[item];
  297. }
  298. }
  299. var templateUrl = this.path + "Priority.json";
  300. this.view = new MWF.xApplication.Strategy.PriorityList.View(this.viewContentList, this.app, {explorer:this,lp : this.lp.view, css : this.css, actions : this.actions }, { templateUrl : templateUrl,filterData:this.filter} );
  301. this.view.load();
  302. this.resizeContent();
  303. },
  304. //分页
  305. createPageContent:function(){
  306. if(this.pageContent)this.pageContent.destroy();
  307. this.pageContent = new Element("div.pageContent",{"styles":this.css.pageContent}).inject(this.viewContent);
  308. },
  309. dragItemData:function(){
  310. var dragSort = new Sortables("tabBody",
  311. {
  312. clone:true,
  313. opacity:0.3,
  314. //handle : ".dragTr",
  315. onStart : function (element, clone) {
  316. clone.setStyles({
  317. "position":"absolute",
  318. "margin-top":(160-this.viewContentList.getScrollTop())+"px",
  319. "border":"1px dotted #000","width":(this.viewContentList.getWidth()-10)+"px",
  320. "height":element.getHeight()+"px",
  321. "overflow":"hidden",
  322. "max-height":element.getHeight()+"px"
  323. })
  324. }.bind(this),
  325. onSort : function (element, clone) {
  326. //element.setStyle("background-color","#4990E2");
  327. //clone.setStyle('background-color', '#4990E2');
  328. }.bind(this),
  329. onComplete : function (element) {
  330. var id = element.get("id");
  331. var dataIds = dragSort.serialize();
  332. //alert(cardIdStr)
  333. }.bind(this)
  334. }
  335. )
  336. },
  337. resizeContent : function(){
  338. var size = this.node.getSize();
  339. var leftNode = this.departmentNavi;
  340. this.rightContent.setStyles({
  341. "width":(size.x-leftNode.getWidth())+"px",
  342. "height":(size.y)+"px"
  343. });
  344. var yearNode = $(this.yearContent);
  345. var searchNode = $(this.searchContent);
  346. var viewNode = $(this.viewContent);
  347. var viewList = $(this.viewContentList);
  348. if(searchNode && viewNode){
  349. $(viewNode).setStyles({
  350. "height":(size.y - yearNode.getHeight() - searchNode.getHeight())+"px"
  351. });
  352. }
  353. if(viewList){
  354. $(viewList).setStyles({
  355. "height":(viewNode.getHeight()-10)+"px"
  356. })
  357. }
  358. },
  359. createShade: function(o,txtInfo){
  360. var defaultObj = this.node;
  361. var obj = o || defaultObj;
  362. var txt = txtInfo || "loading...";
  363. if(this.shadeDiv){ $(this.shadeDiv).destroy()}
  364. if(this["shadeTxtDiv"]) this["shadeTxtDiv"].destroy();
  365. this.shadeDiv = new Element("div.shadeDiv").inject(obj);
  366. this.inforDiv = new Element("div.inforDiv",{
  367. styles:{
  368. "height":"16px",
  369. "width":"200px",
  370. "display":"line-block",
  371. "position":"relative",
  372. "background-color":"#000000","border-radius":"3px","padding":"5px 10px"}
  373. }).inject(this.shadeDiv);
  374. this.loadImg = new Element("img.loadImg",{
  375. styles:{"width":"16px","height":"16px","float":"left"},
  376. //src:this.path+"default/icon/loading.gif"
  377. src:"../x_component_Strategy/$Main/default/icon/loading.gif"
  378. }).inject(this.inforDiv);
  379. this.shadeTxtSpan = new Element("span.shadeTxtSpan").inject(this.inforDiv);
  380. this.shadeTxtSpan.set("text",txt);
  381. this.shadeDiv.setStyles({
  382. "width":"100%",
  383. "height":"100%",
  384. //"position":"absolute",
  385. "opacity":"0.6",
  386. "background-color":"#cccccc","z-index":"999"
  387. });
  388. this.shadeTxtSpan.setStyles({"color":"#ffffff","font-size":"12px","display":"inline-block","line-height":"16px","padding-left":"5px"});
  389. var x = obj.getSize().x;
  390. var y = obj.getSize().y;
  391. this.shadeDiv.setStyles({
  392. "left":(obj.getLeft()-defaultObj.getLeft())+"px",
  393. "top":(obj.getTop()-defaultObj.getTop())+"px",
  394. "width":x+"px",
  395. "height":y+"px"
  396. });
  397. if(obj.getStyle("position")=="position"){
  398. this.shadeDiv.setStyles({
  399. "left":"0px",
  400. "top":"0px"
  401. })
  402. }
  403. this.inforDiv.setStyles({
  404. "left":(x/2)+"px",
  405. "top":(y/2)+"px"
  406. });
  407. this.inforDiv.setStyles({"display":"none"})
  408. },
  409. destroyShade : function(){
  410. if(this.shadeDiv) $(this.shadeDiv).destroy();
  411. //if(this.shadeDiv) this.shadeDiv.destroy()
  412. },
  413. showErrorMessage:function(xhr,text,error){
  414. var errorText = error;
  415. var errorMessage;
  416. if (xhr) errorMessage = xhr.responseText;
  417. if(errorMessage!=""){
  418. var e = JSON.parse(errorMessage);
  419. if(e.message){
  420. this.notice( e.message,"error");
  421. }else{
  422. this.notice( errorText,"error");
  423. }
  424. }else{
  425. this.notice(errorText,"error");
  426. }
  427. }
  428. });
  429. MWF.xApplication.Strategy.PriorityList.View = new Class({
  430. Extends: MWF.xApplication.Strategy.Template.view,
  431. _createDocument: function(data){
  432. return new MWF.xApplication.Strategy.PriorityList.Document(this.viewBodyNode, data, this.explorer, this);
  433. },
  434. loadScrollElementList : function( count ){
  435. if (!this.isItemsLoaded) {
  436. if (!this.isItemLoadding) {
  437. this.isItemLoadding = true;
  438. this._getCurrentPageData(function (json) {
  439. var length = this.dataCount = json.count; //|| json.data.length;
  440. if (length <= this.items.length) {
  441. this.isItemsLoaded = true;
  442. }
  443. if( json.data && typeOf( json.data )=="array" ){
  444. json.data.each(function (data ) {
  445. var key = data[ this.options.documentKeyWord || "id" ];
  446. if (!this.documents[key]) {
  447. var item = this._createDocument(data, this.items.length);
  448. this.items.push(item);
  449. this.documents[key] = item;
  450. }
  451. }.bind(this));
  452. }
  453. this.isItemLoadding = false;
  454. //如果不是门户,最后一条记录画好后,执行拖动方案
  455. if(this.explorer.explorer.options.style!="portal"){
  456. if(!(this.explorer.explorer.filter.keyworktitle)){
  457. this.explorer.explorer.dragItemData();
  458. }
  459. }
  460. if (this.loadItemQueue > 0) {
  461. this.loadItemQueue--;
  462. this.loadElementList();
  463. }
  464. }.bind(this), count);
  465. } else {
  466. this.loadItemQueue++;
  467. }
  468. }
  469. },
  470. _getCurrentPageData: function(callback, count){
  471. //var category = this.options.category;
  472. if (!count)count = 100;
  473. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  474. if(id=="(0)") {debugger;
  475. this.explorer.explorer.createShade();
  476. }
  477. var filter = this.options.filterData || {};
  478. //filter.maxCharacterNumber = "-1";
  479. this.actions.getPriorityListNext(id,count,filter,function(json){
  480. if (callback)callback(json);
  481. this.explorer.explorer.destroyShade();
  482. }.bind(this));
  483. },
  484. _removeDocument: function(documentData){
  485. },
  486. _create: function(){
  487. },
  488. _openDocument: function( documentData ){
  489. MWF.xDesktop.requireApp("Strategy", "PriorityForm", function(){
  490. this.priorityForm = new MWF.xApplication.Strategy.PriorityForm(this, this.actions,
  491. {
  492. "id":documentData.id
  493. //"width":1000,
  494. //"height":500
  495. },{
  496. "isEdited":false,
  497. "container":this.app.portalContainer || this.app.content
  498. } );
  499. this.priorityForm.load();
  500. }.bind(this));
  501. },
  502. _queryCreateViewNode: function(){
  503. },
  504. _postCreateViewNode: function( ){
  505. },
  506. _queryCreateViewHead:function(){
  507. },
  508. _postCreateViewHead: function( headNode ){
  509. }
  510. });
  511. MWF.xApplication.Strategy.PriorityList.Document = new Class({
  512. Extends: MWF.xApplication.Strategy.Template.Document,
  513. openActionReturn:function(d) {
  514. var ret = false;
  515. if(d.actions && d.actions.length==1){
  516. ret = true;
  517. }
  518. return ret;
  519. },
  520. editActionReturn:function(d) {
  521. var ret = false;
  522. if (d.actions && d.actions.indexOf("EDIT")>-1)ret = true;
  523. return ret;
  524. },
  525. deleteActionReturn:function(d) {
  526. var ret = false;
  527. if (d.actions && d.actions.indexOf("DELETE")>-1)ret = true;
  528. return ret;
  529. },
  530. action_open:function(){
  531. MWF.xDesktop.requireApp("Strategy", "PriorityForm", function(){
  532. this.PriorityForm = new MWF.xApplication.Strategy.PriorityForm(this, this.actions,{"id":this.data.id},{
  533. "isEdited":false
  534. } );
  535. this.PriorityForm.load();
  536. }.bind(this));
  537. },
  538. action_edit:function(){
  539. MWF.xDesktop.requireApp("Strategy", "PriorityForm", function(){
  540. this.Priorityform = new MWF.xApplication.Strategy.PriorityForm(this, this.app.actions,{
  541. "id":this.data.id,
  542. "isNew":false,
  543. "isEdited": true,
  544. "width":1000,
  545. "height":500,
  546. "year":this.data.keyworkyear,
  547. "onPostSave" : function(){
  548. //this.app.priorityList.openDepartment(this.app.priorityList.currentDistinguishedName);
  549. this.explorer.explorer.openDepartment(this.explorer.explorer.currentDistinguishedName);
  550. }.bind(this)
  551. },{
  552. "container":this.app.portalContainer || this.app.content
  553. });
  554. this.Priorityform.load();
  555. }.bind(this));
  556. },
  557. action_delete:function(e){
  558. var _self = this;
  559. _self.view.app.confirm("warn",e,_self.explorer.explorer.app.lp.priority.submitWarn.title,_self.explorer.explorer.app.lp.priority.submitWarn.content.deleted,300,120,function(){
  560. _self.actions.deletePriority(_self.data.id, function(json){
  561. if(json.type && json.type=="success"){
  562. this.app.notice(_self.explorer.explorer.app.lp.prompt.priority.deleteOK, "success");
  563. _self.explorer.explorer.openDepartment(_self.explorer.explorer.currentDistinguishedName);
  564. }
  565. }.bind(_self));
  566. this.close()
  567. },function(){
  568. this.close();
  569. })
  570. },
  571. _postCreateDocumentNode: function( itemNode, itemData ){
  572. itemNode.set("id",itemData.id);
  573. if(!this.openActionReturn(itemData)){
  574. itemNode.getElements("[item='action_open']").destroy();
  575. }
  576. if(!this.editActionReturn(itemData)){
  577. itemNode.getElements("[item='action_edit']").destroy();
  578. }
  579. if(!this.deleteActionReturn(itemData)){
  580. itemNode.getElements("[item='action_delete']").destroy();
  581. }
  582. }
  583. });