PriorityListPortal.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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.PriorityListPortal = 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.priority;
  15. this.path = "/x_component_Strategy/$PriorityList/";
  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.node.empty();
  41. this.createDepartmentNavi();
  42. //this.createYearContent(function(){
  43. // this.resizeContent();
  44. //}.bind(this));
  45. this.app.addEvent("resize", function(){
  46. this.resizeContent();
  47. }.bind(this));
  48. },
  49. reload:function(year){
  50. //this.currentYear = year;
  51. //this.createYearContent();
  52. },
  53. createDepartmentNavi:function(){
  54. this.departmentNavi = new Element("div.departmentNavi",{"styles":this.css.departmentNavi}).inject(this.node);
  55. this.actions.getPriorityDepartments(function(json){
  56. if(json.type == "success"){
  57. var _self = this;
  58. json.data.each(function(d){
  59. new Element("div.departmentItem",{
  60. "styles":_self.css.departmentItem,
  61. "distinguishedName": d.distinguishedName,
  62. "text": d.name
  63. }).inject(_self.departmentNavi).
  64. addEvents({
  65. "click":function(){
  66. _self.openDepartment(this.get("distinguishedName"));
  67. },
  68. "mouseover":function(){
  69. if(_self.currentDistinguishedName != this.get("distinguishedName")){
  70. this.setStyles({"background-color":"#D9EBFF","color":"#4990E2"});
  71. }
  72. },
  73. "mouseout":function(){
  74. if(_self.currentDistinguishedName != this.get("distinguishedName")){
  75. this.setStyles({"background-color":"","color":""});
  76. }
  77. }
  78. })
  79. }.bind(_self));
  80. this.departmentNavi.getElements(".departmentItem")[0].click();
  81. }
  82. }.bind(this));
  83. },
  84. openDepartment:function(dn){
  85. if(!dn) return;
  86. this.changeDepartmentSelect(dn);
  87. this.createYearContent(function(){
  88. this.resizeContent();
  89. }.bind(this));
  90. },
  91. changeDepartmentSelect:function(dn){
  92. if(!dn) return;
  93. this.currentDistinguishedName = dn;
  94. var allDepartments = this.departmentNavi.getElements(".departmentItem");
  95. allDepartments.each(function(d){
  96. d.setStyles({"background-color":"","color":""});
  97. if(dn == d.get("distinguishedName")){
  98. d.setStyles({"background-color":"#D9EBFF","color":"#4990E2"});
  99. }
  100. }.bind(this))
  101. },
  102. createYearContent:function(callback){
  103. if(this.rightContent) this.rightContent.destroy();
  104. this.rightContent = new Element("div.rightContent",{"styles":this.css.rightContent}).inject(this.node);
  105. this.rightContent.setStyles({
  106. "width":(this.node.getWidth()-this.departmentNavi.getWidth())+"px"
  107. });
  108. this.yearContent = new Element("div.yearContent",{"styles":this.css.yearContent}).inject(this.rightContent);
  109. this.yearContentList = new Element("div.yearContentList",{"styles":this.css.yearContentList}).inject(this.yearContent);
  110. var data = {
  111. "keyworkunit":this.currentDistinguishedName
  112. };
  113. this.actions.getYearsByDepartment(data,function(json){
  114. if(json.type == "success"){
  115. if(json.data && json.data.valueList){
  116. this.yearList = json.data.valueList;
  117. this.yearList.each(function(d,i){
  118. if(i<3){
  119. new Element("div.year",{
  120. "styles":this.css.year,
  121. "value":d,
  122. "name":d,
  123. "text":d
  124. }).inject(this.yearContentList).
  125. addEvents({
  126. "click":function(){
  127. this.changeYearSelected(d);
  128. this.openList(d);
  129. }.bind(this)
  130. });
  131. }
  132. }.bind(this));
  133. if(this.yearList.length>3){
  134. new Element("div.yearMore",{"styles":this.css.year,"id":"yearMore"}).inject(this.yearContentList).
  135. setStyles({"width":"30px"}).set({"text":"..."}).
  136. addEvents({
  137. "click":function(){
  138. this.expandYears();
  139. }.bind(this)
  140. })
  141. }
  142. if(this.currentYear){
  143. if(this.yearContentList.getElements("div[name='"+this.currentYear+"']").length>0){
  144. this.yearContentList.getElements("div[name='"+this.currentYear+"']")[0].click();
  145. }
  146. }else{
  147. if(this.yearContentList.getElements("div").length>0){
  148. this.yearContentList.getElements("div")[0].click();
  149. }
  150. }
  151. if(callback)callback();
  152. }
  153. }
  154. }.bind(this));
  155. //新增
  156. this.actions.getPriorityAddAuthorize(
  157. function(json) {
  158. if (json.type == "success" && json.data && json.data.value) {
  159. this.addContent = new Element("div.addContent",{"styles":this.css.addContent}).inject(this.yearContent).
  160. addEvents({
  161. "click":function(){
  162. MWF.xDesktop.requireApp("Strategy", "PriorityForm", function(){
  163. this.Priorityform = new MWF.xApplication.Strategy.PriorityForm(this, this.app.actions,{},{
  164. "year":this.currentYear||"",
  165. "department":this.currentDistinguishedName,
  166. "isNew": true,
  167. "onPostSave" : function(){
  168. //this.openList(this.currentYear)
  169. //this.reload(this.currentYear);
  170. this.openDepartment(this.currentDistinguishedName);
  171. }.bind(this)
  172. });
  173. this.Priorityform.load();
  174. }.bind(this));
  175. }.bind(this)
  176. });
  177. this.addContentImg = new Element("div.addContentImg",{"styles":this.css.addContentImg}).inject(this.addContent);
  178. this.addContentLabel = new Element("div.addContentLabel",{
  179. "styles":this.css.addContentLabel,
  180. "text":this.lp.add
  181. }).inject(this.addContent);
  182. }
  183. }.bind(this)
  184. );
  185. },
  186. expandYears:function(){
  187. this.yearContentList.getElementById("yearMore").destroy();
  188. this.yearList.each(function(d,i){
  189. if(i>2){
  190. new Element("div.year",{
  191. "styles":this.css.year,
  192. "value":d,
  193. "name":d,
  194. "text":d
  195. }).inject(this.yearContentList).
  196. addEvents({
  197. "click":function(){
  198. this.changeYearSelected(d);
  199. this.openList(d)
  200. }.bind(this)
  201. })
  202. }
  203. }.bind(this))
  204. },
  205. openList:function(v){
  206. this.currentYear = v;
  207. this.createSearch();
  208. this.createViewContent();
  209. },
  210. changeYearSelected:function(str){
  211. this.yearContentList.getElements("div").each(function(d){
  212. if(d.get("text") == str){
  213. d.setStyles({"background-color":"#4990E2","color":"#FFFFFF"});
  214. }else{
  215. d.setStyles({"background-color":"","color":"#666666"});
  216. }
  217. }.bind(this))
  218. },
  219. createSearch:function(){
  220. if(this.searchContent) this.searchContent.destroy();
  221. this.searchContent = new Element("div.searchContent",{"styles":this.css.searchContent}).inject(this.rightContent);
  222. this.searchBar = new Element("div.searchBar",{"styles":this.css.searchBar}).inject(this.searchContent);
  223. this.searchIn = new Element("input.searchIn",{
  224. "styles":this.css.searchIn,
  225. "placeholder":this.lp.defaultSearchIn
  226. }).inject(this.searchBar).
  227. addEvents({
  228. "keydown":function(e){
  229. if(this.searchIn.get("value")!="" && e.event.keyCode=="13"){
  230. this.searchReset.setStyles({"display":""});
  231. this.createViewContent({"keyworktitle":this.searchIn.get("value")});
  232. }
  233. }.bind(this)
  234. });
  235. this.searchImg = new Element("div.searchImg",{"styles":this.css.searchImg}).inject(this.searchBar);
  236. this.searchImg.addEvents({
  237. "click":function(){
  238. if(this.searchIn.get("value")!=""){
  239. this.searchReset.setStyles({"display":""});
  240. this.createViewContent({"keyworktitle":this.searchIn.get("value")});
  241. }
  242. }.bind(this)
  243. });
  244. this.searchReset = new Element("div.searchReset",{"styles":this.css.searchReset}).inject(this.searchBar).
  245. addEvents({
  246. "click":function(){
  247. this.searchIn.set("value","");
  248. this.searchReset.setStyles({"display":"none"});
  249. this.createViewContent();
  250. }.bind(this)
  251. });
  252. },
  253. //视图
  254. createViewContent:function(searchObj){
  255. if(this.viewContent)this.viewContent.destroy();
  256. this.viewContent = new Element("div.viewContent",{"styles":this.css.viewContent}).inject(this.rightContent);
  257. this.viewContentList = new Element("div.viewContentList",{"styles":this.css.viewContentList}).inject(this.viewContent);
  258. this.filter = {
  259. "keyworkyear":this.currentYear,
  260. "keyworkunit":this.currentDistinguishedName,
  261. "ordersymbol":"ASC"
  262. };
  263. for(var item in searchObj){
  264. if(searchObj[item]!=this.app.lp.template.defaultSelect){
  265. this.filter[item] = searchObj[item];
  266. }
  267. }
  268. var templateUrl = this.path + "Priority.json";
  269. this.view = new MWF.xApplication.Strategy.PriorityListPortal.View(this.viewContentList, this.app, {lp : this.lp.view, css : this.css, actions : this.actions }, { templateUrl : templateUrl,filterData:this.filter} );
  270. this.view.load();
  271. this.resizeContent();
  272. },
  273. //分页
  274. createPageContent:function(){
  275. if(this.pageContent)this.pageContent.destroy();
  276. this.pageContent = new Element("div.pageContent",{"styles":this.css.pageContent}).inject(this.viewContent);
  277. },
  278. dragItemData:function(){
  279. var dragSort = new Sortables("tabBody",
  280. {
  281. clone:true,
  282. opacity:0.3,
  283. //handle : ".dragTr",
  284. onStart : function (element, clone) {
  285. clone.setStyles({
  286. "position":"absolute",
  287. "margin-top":(160-this.viewContentList.getScrollTop())+"px",
  288. "border":"1px dotted #000","width":(this.viewContentList.getWidth()-10)+"px",
  289. "height":element.getHeight()+"px",
  290. "overflow":"hidden",
  291. "max-height":element.getHeight()+"px"
  292. })
  293. }.bind(this),
  294. onSort : function (element, clone) {
  295. //element.setStyle("background-color","#4990E2");
  296. //clone.setStyle('background-color', '#4990E2');
  297. }.bind(this),
  298. onComplete : function (element) {
  299. var id = element.get("id");
  300. var dataIds = dragSort.serialize();
  301. //alert(cardIdStr)
  302. }.bind(this)
  303. }
  304. )
  305. },
  306. resizeContent : function(){
  307. var size = this.node.getSize();
  308. var leftNode = this.departmentNavi;
  309. this.rightContent.setStyles({
  310. "width":(size.x-leftNode.getWidth())+"px",
  311. "height":(size.y)+"px"
  312. });
  313. var yearNode = this.yearContent;
  314. var searchNode = this.searchContent;
  315. var viewNode = this.viewContent;
  316. var viewList = this.viewContentList;
  317. if(searchNode && viewNode){
  318. viewNode.setStyles({
  319. "height":(size.y - yearNode.getHeight() - searchNode.getHeight())+"px"
  320. });
  321. }
  322. if(viewList){
  323. viewList.setStyles({
  324. "height":(viewNode.getHeight()-10)+"px"
  325. })
  326. }
  327. }
  328. });
  329. MWF.xApplication.Strategy.PriorityListPortal.View = new Class({
  330. Extends: MWF.xApplication.Strategy.Template.view,
  331. _createDocument: function(data){
  332. return new MWF.xApplication.Strategy.PriorityListPortal.Document(this.viewBodyNode, data, this.explorer, this);
  333. },
  334. loadScrollElementList : function( count ){
  335. if (!this.isItemsLoaded) {
  336. if (!this.isItemLoadding) {
  337. this.isItemLoadding = true;
  338. this._getCurrentPageData(function (json) {
  339. var length = this.dataCount = json.count; //|| json.data.length;
  340. if (length <= this.items.length) {
  341. this.isItemsLoaded = true;
  342. }
  343. if( json.data && typeOf( json.data )=="array" ){
  344. json.data.each(function (data ) {
  345. var key = data[ this.options.documentKeyWord || "id" ];
  346. if (!this.documents[key]) {
  347. var item = this._createDocument(data, this.items.length);
  348. this.items.push(item);
  349. this.documents[key] = item;
  350. }
  351. }.bind(this));
  352. }
  353. this.isItemLoadding = false;
  354. //最后一条记录画好后,执行拖动方案
  355. if(!(this.app.priorityList.filter.keyworktitle)){
  356. this.app.priorityList.dragItemData();
  357. }
  358. if (this.loadItemQueue > 0) {
  359. this.loadItemQueue--;
  360. this.loadElementList();
  361. }
  362. }.bind(this), count);
  363. } else {
  364. this.loadItemQueue++;
  365. }
  366. }
  367. },
  368. _getCurrentPageData: function(callback, count){
  369. //var category = this.options.category;
  370. if (!count)count = 100;
  371. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  372. if(id=="(0)")this.app.createShade();
  373. var filter = this.options.filterData || {};
  374. //filter.maxCharacterNumber = "-1";
  375. this.actions.getPriorityListNext(id,count,filter,function(json){
  376. if (callback)callback(json);
  377. this.app.destroyShade();
  378. }.bind(this));
  379. },
  380. _removeDocument: function(documentData){
  381. },
  382. _create: function(){
  383. },
  384. _openDocument: function( documentData ){
  385. MWF.xDesktop.requireApp("Strategy", "PriorityForm", function(){
  386. this.priorityForm = new MWF.xApplication.Strategy.PriorityForm(this, this.actions,{"id":documentData.id},{
  387. "isEdited":false
  388. } );
  389. this.priorityForm.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.PriorityListPortal.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", "PriorityForm", function(){
  422. this.PriorityForm = new MWF.xApplication.Strategy.PriorityForm(this, this.actions,{"id":this.data.id},{
  423. "isEdited":false
  424. } );
  425. this.PriorityForm.load();
  426. }.bind(this));
  427. },
  428. action_edit:function(){
  429. MWF.xDesktop.requireApp("Strategy", "PriorityForm", function(){
  430. this.Priorityform = new MWF.xApplication.Strategy.PriorityForm(this, this.app.actions,{"id":this.data.id},{
  431. "isNew":false,
  432. "isEdited": true,
  433. "onPostSave" : function(){
  434. this.app.priorityListPortal.openDepartment(this.app.priorityListPortal.currentDistinguishedName);
  435. }.bind(this)
  436. });
  437. this.Priorityform.load();
  438. }.bind(this));
  439. },
  440. action_delete:function(e){
  441. var _self = this;
  442. _self.view.app.confirm("warn",e,_self.view.app.lp.priority.submitWarn.title,_self.view.app.lp.priority.submitWarn.content.delete,300,120,function(){
  443. _self.actions.deletePriority(_self.data.id, function(json){
  444. if(json.type && json.type=="success"){
  445. this.app.notice(_self.view.app.lp.prompt.priority.deleteOK, "success");
  446. _self.app.priorityListPortal.openDepartment(_self.app.priorityListPortal.currentDistinguishedName);
  447. }
  448. }.bind(_self));
  449. this.close();
  450. },function(){
  451. this.close();
  452. })
  453. },
  454. _postCreateDocumentNode: function( itemNode, itemData ){
  455. itemNode.set("id",itemData.id);
  456. if(!this.openActionReturn(itemData)){
  457. itemNode.getElements("[item='action_open']").destroy();
  458. }
  459. if(!this.editActionReturn(itemData)){
  460. itemNode.getElements("[item='action_edit']").destroy();
  461. }
  462. if(!this.deleteActionReturn(itemData)){
  463. itemNode.getElements("[item='action_delete']").destroy();
  464. }
  465. }
  466. });