Newer.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.Index = MWF.xApplication.cms.Index || {};
  4. MWF.xDesktop.requireApp("cms.Index", "Actions.RestActions", null, false);
  5. MWF.require("MWF.xAction.org.express.RestActions", null, false);
  6. MWF.require("MWF.widget.Mask", null, false);
  7. MWF.xApplication.cms.Index.Newer = new Class({
  8. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "popupStyle" : "o2platform",
  13. "width": "850",
  14. "height": "510",
  15. "hasTop": true,
  16. "hasIcon": false,
  17. "hasTopContent" : true,
  18. "hasBottom": false,
  19. //"title": MWF.xApplication.cms.Index.LP.createDocument,
  20. "draggable": true,
  21. "closeAction": true,
  22. "ignoreDrafted" : false,
  23. "selectColumnEnable" : true,
  24. "restrictToColumn" : false
  25. },
  26. initialize: function (columnData, categoryData, app, view, options) {
  27. this.path = "/x_component_cms_Index/$Newer/";
  28. this.cssPath = "/x_component_cms_Index/$Newer/"+this.options.style+"/css.wcss";
  29. this._loadCss();
  30. MWF.xDesktop.requireApp("cms.Index", "$Newer.lp."+MWF.language, null, false);
  31. this.lp = MWF.xApplication.cms.Index.Newer.lp;
  32. this.options.title = this.lp.createDocument;
  33. this.setOptions(options);
  34. this.columnData = columnData;
  35. this.categoryData = categoryData;
  36. this.app = app;
  37. this.view = view;
  38. this.container = this.app.content;
  39. this.documentAction = new MWF.xApplication.cms.Index.Actions.RestActions();
  40. this.orgAction = new MWF.xAction.org.express.RestActions();
  41. },
  42. load : function(){
  43. if( !this.categoryData ){
  44. this._load();
  45. this.fireEvent( "postLoad" );
  46. }else if( this.options.ignoreDrafted ){
  47. this._load();
  48. this.fireEvent( "postLoad" );
  49. }else if(this.categoryData.workflowAppId && this.categoryData.workflowFlag ){
  50. this._load();
  51. this.fireEvent( "postLoad" );
  52. }else{
  53. var fielter = {
  54. "categoryIdList": [this.categoryData.id ],
  55. "creatorList": [layout.desktop.session.user.name]
  56. };
  57. this.documentAction.listDraftNext("(0)", 1, fielter, function(json){
  58. if( json.data.length > 0 ){
  59. this._openDocument(json.data[0].id);
  60. this.fireEvent( "postLoad" );
  61. }else{
  62. this._load();
  63. this.fireEvent( "postLoad" );
  64. }
  65. }.bind(this));
  66. }
  67. },
  68. _load : function(){
  69. this.isNew = true;
  70. this.isEdited = true;
  71. this._open();
  72. if( this.options.selectColumnEnable ){
  73. this.openSel();
  74. }
  75. },
  76. openSel : function(){
  77. this.formTopTextNode.set("text", this.lp.selCategory);
  78. if( this.sel ){
  79. this.sel.load();
  80. }else{
  81. this.sel = new MWF.xApplication.cms.Index.Newer.CategorySel(this.app, this.formContentNode, this, this.columnData, this.categoryData, {
  82. restrictToColumn : this.options.restrictToColumn
  83. });
  84. this.sel.load();
  85. }
  86. },
  87. _loadCss: function(){
  88. var key = encodeURIComponent(this.cssPath);
  89. if (MWF.widget.css[key]){
  90. this.css = MWF.widget.css[key];
  91. }else{
  92. this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+COMMON.version : this.cssPath+"?v="+COMMON.version;
  93. var r = new Request.JSON({
  94. url: this.cssPath,
  95. secure: false,
  96. async: false,
  97. method: "get",
  98. noCache: false,
  99. onSuccess: function(responseJSON, responseText){
  100. this.css = responseJSON;
  101. MWF.widget.css[key] = responseJSON;
  102. }.bind(this),
  103. onError: function(text, error){
  104. alert(error + text);
  105. }
  106. });
  107. r.send();
  108. }
  109. },
  110. _createTableContent: function () {
  111. var categoryName = this.categoryData ? ( this.categoryData.name || this.categoryData.categoryName ) : this.lp.selectCategory;
  112. var html = ""
  113. if( this.options.selectColumnEnable ){
  114. this.selectArea = new Element("div",{styles:this.css.selectArea}).inject( this.formTableArea );
  115. this.selectContainer = new Element("div",{styles:this.css.selectContainer}).inject( this.selectArea );
  116. //html = "<table width='100%' height='90%' border='0' cellPadding='0' cellSpacing='0'>" +
  117. //"<tr>" +
  118. //"<td style='height: 40px; line-height: 40px; text-align: left; width: 40%' id='form_startColumn'></td>" +
  119. //"<td style='text-align: left;' id='form_startCategory'></td>" +
  120. //"</tr>" +
  121. //"</table>"
  122. html = "<div id='form_startColumn' style='float:left'></div><div id='form_startCategory' style='float:left'></div>"
  123. this.selectContainer.set("html", html);
  124. this.setSelectContent();
  125. }
  126. this.inputContainer = new Element("div",{styles:this.css.inputContainer}).inject( this.formTableArea );
  127. html = "<table width='100%' height='90%' border='0' cellPadding='0' cellSpacing='0'; >" +
  128. "<tr><td colSpan='2' style='height: 60px; line-height: 60px; text-align: center; font-size: 24px; ' id='form_startTitle'>" +
  129. this.lp.start+" - "+categoryName+"</td></tr>" +
  130. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'>"+this.lp.department+":</td>" +
  131. "<td style='; text-align: left;' id='form_startDepartment'></td></tr>" +
  132. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'>"+this.lp.identity+":</td>" +
  133. "<td style='; text-align: left;'><div id='form_startIdentity'></div></td></tr>" +
  134. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'>"+this.lp.date+":</td>" +
  135. "<td style='; text-align: left;'><div id='form_startDate'></div></td></tr>" +
  136. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'>"+this.lp.subject+":</td>" +
  137. "<td style='; text-align: left;'><input type='text' id='form_startSubject' " +
  138. "style='width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  139. "height: 26px;'/></td></tr>" +
  140. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'></td>" +
  141. "<td style='text-align: left;' id='form_startAction'></td></tr>" +
  142. "</table>";
  143. this.inputContainer.set("html", html);
  144. this.setStartFormContent();
  145. this.startActionContainer = this.inputContainer.getElementById("form_startAction");
  146. this.startTitleNode = this.inputContainer.getElementById("form_startTitle");
  147. this.startOkActionNode = new Element("div", {
  148. "styles": this.css.startOkActionNode,
  149. "text": this.lp.ok
  150. }).inject(this.startActionContainer);
  151. this.cancelActionNode = new Element("div", {
  152. "styles": this.css.cancelActionNode,
  153. "text": this.lp.cancel
  154. }).inject(this.startActionContainer);
  155. this.cancelActionNode.addEvent("click", function(e){
  156. this.cancelStart(e);
  157. }.bind(this));
  158. this.startOkActionNode.addEvent("click", function(e){
  159. this.okStart(e);
  160. }.bind(this));
  161. },
  162. setSelectContent: function(){
  163. this.columnContainer = this.selectContainer.getElementById("form_startColumn");
  164. this.columnContainer.setStyles( this.css.columnContainer );
  165. this.selectContainer.addEvents({
  166. mouseover : function(){
  167. this.columnSelectNode.setStyles( this.css.columnSelectNode_over );
  168. }.bind(this),
  169. mouseout : function(){
  170. this.columnSelectNode.setStyles( this.css.columnSelectNode );
  171. }.bind(this),
  172. click : function(){
  173. this.openSel();
  174. }.bind(this)
  175. });
  176. this.columnIconNode = new Element("img", {styles : this.css.columnIconNode }).inject( this.columnContainer );
  177. if( this.columnData ){
  178. if (this.columnData.appIcon){
  179. this.columnIconNode.set("src", "data:image/png;base64,"+this.columnData.appIcon+"");
  180. }else{
  181. this.columnIconNode.set("src", "/x_component_cms_Index/$Main/default/icon/column.png");
  182. }
  183. }else{
  184. this.columnIconNode.set("src","/x_component_cms_Index/$Main/default/icon/all_40.png");
  185. }
  186. this.columnTextNode = new Element("div", {
  187. styles : this.css.columnTextNode,
  188. text : this.lp.all
  189. } ).inject( this.columnContainer );
  190. this.columnSelectNode = new Element("div", {styles : this.css.columnSelectNode }).inject( this.columnContainer );
  191. this.categoryContainer = this.selectContainer.getElementById("form_startCategory");
  192. this.categoryContainer.setStyles( this.css.categoryContainer );
  193. this.categoryTextNode = new Element("div", {
  194. styles : this.css.categoryTextNode,
  195. text : this.lp.clickForSelect
  196. }).inject( this.categoryContainer );
  197. },
  198. setCurrentColumn: function( column ){
  199. if( this.currentColumn && this.currentColumn != column ){
  200. this.currentColumn.node.setStyles( this.css.columnItemNode );
  201. this.currentColumn.options.isCurrent = false;
  202. }
  203. this.currentColumn = column;
  204. },
  205. setCurrentCategory: function( category ){
  206. if( this.currentCategory && this.currentCategory != category ){
  207. this.currentCategory.node.setStyles( this.css.categoryItemNode );
  208. this.currentCategory.options.isCurrent = false;
  209. }
  210. this.currentCategory = category;
  211. var fielter = {
  212. "categoryIdList": [ category.data.id ],
  213. "creatorList": [layout.desktop.session.user.name]
  214. };
  215. this.documentAction.listDraftNext("(0)", 1, fielter, function(j){
  216. if( j.data && j.data.length > 0 ){
  217. this._openDocument(j.data[0].id);
  218. this.close();
  219. }else{
  220. this.documentAction.getColumn( {id : category.data.appId} , function( json ){
  221. this.columnData = json.data;
  222. if (this.columnData.appIcon){
  223. this.columnIconNode.set("src", "data:image/png;base64,"+this.columnData.appIcon+"");
  224. }else{
  225. this.columnIconNode.set("src", "/x_component_cms_Index/$Main/default/icon/column.png");
  226. }
  227. this.columnTextNode.set("text", this.columnData.appName);
  228. this.formTopTextNode.set("text", this.lp.createDocument);
  229. this.categoryData = category.data;
  230. this.categoryTextNode.set("text", this.categoryData.categoryName);
  231. this.startTitleNode.set("text",this.lp.start+" - "+this.categoryData.categoryName);
  232. this.sel.closeArea();
  233. }.bind(this));
  234. }
  235. }.bind(this));
  236. },
  237. setStartFormContent: function(){
  238. this.dateArea = this.formTableArea.getElementById("form_startDate");
  239. var d = new Date();
  240. this.dateArea.set("text", d.format("%Y-%m-%d %H:%M"));
  241. this.departmentSelArea = this.formTableArea.getElementById("form_startDepartment");
  242. this.identityArea = this.formTableArea.getElementById("form_startIdentity");
  243. this.subjectInput = this.formTableArea.getElementById("form_startSubject");
  244. this.loadDepartments();
  245. },
  246. loadDepartments: function(){
  247. if (this.app.desktop.session.user.name){
  248. this.orgAction.listIdentityByPerson(function(json){
  249. var selected = (json.data.length==1) ? true : false;
  250. json.data.each(function(id){
  251. var departSel = new MWF.xApplication.cms.Index.Newer.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  252. if (selected) departSel.selected();
  253. }.bind(this));
  254. }.bind(this), null, this.app.desktop.session.user.name)
  255. }
  256. },
  257. cancelStart: function(e){
  258. var _self = this;
  259. if (this.subjectInput.get("value")){
  260. this.app.confirm("warn", e, this.lp.start_cancel_title, this.lp.start_cancel, "320px", "100px", function(){
  261. _self.close();
  262. this.close();
  263. },function(){
  264. this.close();
  265. }, null, this.app.content);
  266. }else{
  267. this.close();
  268. }
  269. },
  270. okStart: function(){
  271. if( !this.categoryData ){
  272. this.app.notice(this.lp.selectCategory, "error");
  273. }else{
  274. if( this.categoryData.workflowAppId && this.categoryData.workflowFlag ){
  275. this._createProcessDocument();
  276. }else{
  277. this._createDocument();
  278. }
  279. }
  280. },
  281. _createDocument: function(e){
  282. var title = this.subjectInput.get("value");
  283. var data = {
  284. "id" : this.documentAction.getUUID(),
  285. "isNewDocument" : true,
  286. "title": title,
  287. "creatorIdentity": this.identityArea.get("value"),
  288. "appId" :this.categoryData.appId,
  289. "categoryId" : this.categoryData.id,
  290. "form" : this.categoryData.formId,
  291. "formName" :this.categoryData.formName,
  292. "docStatus" : "draft",
  293. "categoryName" : this.categoryData.name,
  294. "categoryAlias" : this.categoryData.alias,
  295. "attachmentList" : []
  296. };
  297. if (!data.title){
  298. this.subjectInput.setStyle("border-color", "red");
  299. this.subjectInput.focus();
  300. this.app.notice(this.lp.inputSubject, "error");
  301. }else if (!data.creatorIdentity){
  302. this.departmentSelArea.setStyle("border-color", "red");
  303. this.app.notice(this.lp.selectStartId, "error");
  304. }else{
  305. this.mask = new MWF.widget.Mask({"style": "desktop"});
  306. this.mask.loadNode(this.formAreaNode);
  307. this.documentAction.addDocument( data, function(json){
  308. this.mask.hide();
  309. //this.markNode.destroy();
  310. this.close();
  311. this._openDocument( json.data.id );
  312. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  313. //this.app.refreshAll();
  314. this.app.notice(this.lp.Started, "success");
  315. // this.app.processConfig();
  316. }.bind(this), null);
  317. }
  318. },
  319. _openDocument: function(id,el){
  320. var _self = this;
  321. var appId = "cms.Document"+id;
  322. if (_self.app.desktop.apps[appId]){
  323. _self.app.desktop.apps[appId].setCurrent();
  324. }else {
  325. var options = {
  326. "readonly" :false,
  327. "documentId": id,
  328. "appId": appId,
  329. "postPublish" : function(){
  330. //if(_self.creater.view )_self.creater.view.reload();
  331. this.fireEvent( "postPublish" );
  332. }.bind(this)
  333. };
  334. this.app.desktop.openApplication(el, "cms.Document", options);
  335. }
  336. },
  337. _createProcessDocument:function(e){
  338. var title = this.subjectInput.get("value");
  339. var processId = this.categoryData.workflowFlag;
  340. var data = {
  341. "title":this.subjectInput.get("value"),
  342. "identity": this.identityArea.get("value")
  343. };
  344. if (!data.title){
  345. this.subjectInput.setStyle("border-color", "red");
  346. this.subjectInput.focus();
  347. this.app.notice(this.lp.inputSubject, "error");
  348. }else if (!data.identity){
  349. this.departmentSelArea.setStyle("border-color", "red");
  350. this.app.notice(this.lp.selectStartId, "error");
  351. }else{
  352. var workData = {
  353. cmsDocument : {
  354. "isNewDocument" : true,
  355. "title": title,
  356. "creatorIdentity": data.identity,
  357. "appId" :this.categoryData.appId,
  358. "categoryId" : this.categoryData.id,
  359. //"form" : this.categoryData.formId,
  360. //"formName" :this.categoryData.formName,
  361. "docStatus" : "draft",
  362. "categoryName" : this.categoryData.name,
  363. "categoryAlias" : this.categoryData.alias,
  364. "createTime": new Date().format("db"),
  365. "attachmentList" : []
  366. }
  367. };
  368. this.mask = new MWF.widget.Mask({"style": "desktop"});
  369. this.mask.loadNode(this.formAreaNode);
  370. this.documentAction.startWork( function( json ){
  371. this.mask.hide();
  372. //this.markNode.destroy();
  373. this.close();
  374. this.afterStartProcess( json.data, data.title, this.categoryData.workflowName, workData );
  375. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  376. //this.app.refreshAll();
  377. this.app.notice(this.lp.Started, "success");
  378. }.bind(this), null, processId, data)
  379. }
  380. },
  381. afterStartProcess: function(data, title, processName, workData){
  382. var workInfors = [];
  383. var currentTask = [];
  384. data.each(function(work){
  385. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  386. workInfors.push(this.getStartWorkInforObj(work));
  387. }.bind(this));
  388. var workId = currentTask[0];
  389. this.documentAction.saveWorkData(function(){
  390. if (currentTask.length==1){
  391. var options = {"workId": workId};
  392. this.app.desktop.openApplication(null, "process.Work", options);
  393. this.createStartWorkResault(workInfors, title, processName, false);
  394. }else{
  395. this.createStartWorkResault(workInfors, title, processName, true);
  396. }
  397. }.bind(this), null, workId, workData)
  398. },
  399. getStartWorkInforObj: function(work){
  400. var users = [];
  401. var currentTask = "";
  402. work.taskList.each(function(task, idx){
  403. users.push(task.person+"("+task.department + ")");
  404. if (work.currentTaskIndex==idx) currentTask = task.id;
  405. }.bind(this));
  406. return {"activity": work.fromActivityName, "users": users, "currentTask": currentTask};
  407. },
  408. createStartWorkResault: function(workInfors, title, processName, isopen){
  409. var content = "";
  410. workInfors.each(function(infor){
  411. content += "<div><b>"+this.lp.nextActivity+"<font style='color: #ea621f'>"+infor.activity+"</font>, "+this.lp.nextUser+"<font style='color: #ea621f'>"+infor.users.join(", ")+"</font></b>"
  412. if (infor.currentTask && isopen){
  413. content += "&nbsp;&nbsp;&nbsp;&nbsp;<span value='"+infor.currentTask+"'>"+this.lp.deal+"</span></div>";
  414. }else{
  415. content += "</div>";
  416. }
  417. }.bind(this));
  418. var msg = {
  419. "subject": this.lp.processStarted,
  420. "content": "<div>"+this.lp.processStartedMessage+"“["+processName+"]"+title+"”</div>"+content
  421. };
  422. var tooltip = layout.desktop.message.addTooltip(msg);
  423. var item = layout.desktop.message.addMessage(msg);
  424. this.setStartWorkResaultAction(tooltip);
  425. this.setStartWorkResaultAction(item);
  426. },
  427. setStartWorkResaultAction: function(item){
  428. var node = item.node.getElements("span");
  429. node.setStyles(this.css.dealStartedWorkAction);
  430. var _self = this;
  431. node.addEvent("click", function(e){
  432. var options = {"taskId": this.get("value")};
  433. _self.app.desktop.openApplication(e, "process.Work", options);
  434. });
  435. }
  436. });
  437. MWF.xApplication.cms.Index.Newer.DepartmentSel = new Class({
  438. initialize: function(data, starter, container, idArea){
  439. this.data = data;
  440. this.starter = starter;
  441. this.container = container;
  442. this.idArea = idArea;
  443. this.css = this.starter.css;
  444. this.isSelected = false;
  445. this.load();
  446. },
  447. load: function(){
  448. this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  449. this.starter.orgAction.getDepartmentByIdentity(function(department){
  450. this.node.set("text", department.data.name);
  451. }.bind(this), null, this.data.name);
  452. this.node.addEvents({
  453. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  454. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  455. "click": function(){
  456. this.selected();
  457. }.bind(this),
  458. });
  459. },
  460. selected: function(){
  461. if (!this.isSelected){
  462. if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  463. this.node.setStyles(this.css.departSelNode_selected);
  464. this.isSelected = true;
  465. this.starter.currentDepartment = this;
  466. this.idArea.set({
  467. "text": this.data.display,
  468. "value": this.data.name
  469. });
  470. }
  471. },
  472. unSelected: function(){
  473. if (this.isSelected){
  474. if (this.starter.currentDepartment) this.starter.currentDepartment = null;
  475. this.node.setStyles(this.css.departSelNode);
  476. this.isSelected = false;
  477. }
  478. }
  479. });
  480. MWF.xApplication.cms.Index.Newer.CategorySel = new Class({
  481. Extends: MWF.widget.Common,
  482. Implements: [Options, Events],
  483. options: {
  484. "style": "default",
  485. "restrictToColumn" : false
  486. },
  487. initialize: function(app, node, newer, columnData, categoryData, options){
  488. this.setOptions(options);
  489. this.node = node;
  490. this.newer = newer;
  491. this.lp = newer.lp;
  492. this.css = newer.css;
  493. this.action = newer.documentAction;
  494. this.columnData = columnData;
  495. this.categoryData = categoryData;
  496. },
  497. load: function(){
  498. if (!this.areaNode){
  499. this.createArea();
  500. }
  501. this.areaNode.fade("1");
  502. },
  503. closeArea: function(){
  504. if (this.areaNode) this.areaNode.fade("out");
  505. },
  506. createArea: function(){
  507. this.areaNode = new Element("div.categorySelAreaNode", {"styles": this.css.categorySelAreaNode}).inject(this.node );
  508. this.areaNode.addEvent("click", function(e){
  509. //this.closeArea();
  510. }.bind(this));
  511. this.columnContainer = new Element("div", {"styles": this.css.selColumnAreaNode}).inject( this.areaNode );
  512. this.columnScrollNode = new Element("div.columnScrollNode", {"styles": this.css.selColumnScrollNode}).inject(this.columnContainer);
  513. this.setScrollBar( this.columnScrollNode )
  514. this.columnContentNode = new Element("div.selColumnContentNode", {"styles": this.css.selColumnContentNode}).inject(this.columnScrollNode);
  515. this.categoryContainer = new Element("div", {"styles": this.css.selCategoryAreaNode}).inject( this.areaNode );
  516. this.categoryScrollNode = new Element("div", {"styles": this.css.selCategoryScrollNode}).inject(this.categoryContainer);
  517. this.setScrollBar( this.categoryScrollNode )
  518. this.categoryContentNode = new Element("div", {"styles": this.css.selCategoryContentNode}).inject(this.categoryScrollNode);
  519. if( this.options.restrictToColumn && this.columnData ){
  520. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(this.columnData, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  521. "needGetCategorys": true,
  522. "isCurrent": true,
  523. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  524. "restrictToColumn" : this.options.restrictToColumn
  525. });
  526. }else{
  527. this.listColumns();
  528. }
  529. },
  530. listColumns: function(){
  531. var c = { wrapOutCategoryList : [] };
  532. this.action.listColumnByPublish(function(json){
  533. json.data.each(function(column){
  534. if(!column.name)column.name = column.appName;
  535. if( column.wrapOutCategoryList && column.wrapOutCategoryList.length ){
  536. column.wrapOutCategoryList.each(function(category){
  537. c.wrapOutCategoryList.push(category);
  538. }.bind(this));
  539. }
  540. }.bind(this));
  541. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(c, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  542. "needGetCategorys": false,
  543. "isAll" : true,
  544. "isCurrent" : this.columnData ? false : true,
  545. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  546. "restrictToColumn" : this.options.restrictToColumn
  547. });
  548. json.data.each( function(column) {
  549. if(!column.name)column.name = column.appName;
  550. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(column, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  551. "needGetCategorys": false,
  552. "isCurrent": ( this.columnData && this.columnData.id == column.id) ? true : false,
  553. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  554. "restrictToColumn" : this.options.restrictToColumn
  555. });
  556. }.bind(this) )
  557. }.bind(this));
  558. }
  559. });
  560. MWF.xApplication.cms.Index.Newer.CategorySel.Column = new Class({
  561. Implements: [Options],
  562. options: {
  563. "needGetCategorys": false,
  564. "isAll" : false,
  565. "isCurrent" : false,
  566. "currentCategory" : "",
  567. "restrictToColumn" : false
  568. },
  569. initialize: function(data, app, newer, container, categoryContainer, options ){
  570. this.setOptions( options );
  571. this.data = data;
  572. this.app = app;
  573. this.newer = newer;
  574. this.lp = newer.lp;
  575. this.css = newer.css;
  576. this.action = newer.documentAction;
  577. this.container = container;
  578. this.categoryContainer = categoryContainer;
  579. this.load();
  580. },
  581. load: function(){
  582. this.node = new Element("div", {"styles": this.css.columnItemNode}).inject(this.container);
  583. var iconNode = this.iconNode = new Element("img",{
  584. "styles" : this.css.columnItemIconNode
  585. }).inject(this.node);
  586. if( this.options.isAll ){
  587. this.iconNode.set("src", "/x_component_cms_Index/$Main/default/icon/all_40.png")
  588. }else if (this.data.appIcon){
  589. this.iconNode.set("src", "data:image/png;base64,"+this.data.appIcon+"");
  590. }else{
  591. this.iconNode.set("src", "/x_component_cms_Index/$Main/default/icon/column.png")
  592. }
  593. this.textNode = new Element("div", {"styles": this.css.columnItemTextNode}).inject(this.node);
  594. if( this.options.isAll ){
  595. this.textNode.set("text", this.lp.all);
  596. }else{
  597. this.textNode.set("text", (this.data.name || this.data.appName) );
  598. }
  599. if( this.options.isAll ){
  600. //new Element("div", {"styles": this.css.columnSelectNode}).inject(this.node);
  601. }
  602. this.node.addEvents({
  603. "mouseover" : function(){ if( !this.options.isCurrent )this.node.setStyles( this.css.columnItemNode_over ) }.bind(this),
  604. "mouseout" : function(){ if( !this.options.isCurrent )this.node.setStyles( this.css.columnItemNode ) }.bind(this),
  605. "click" : function(){ this.setCurrent(); }.bind(this)
  606. });
  607. if( this.options.isCurrent )this.setCurrent();
  608. },
  609. setCurrent: function(){
  610. this.options.isCurrent = true;
  611. this.node.setStyles( this.css.columnItemNode_current );
  612. this.newer.setCurrentColumn( this );
  613. this.loadCategory();
  614. },
  615. loadCategory: function(){
  616. this.categoryContainer.empty();
  617. if( this.options.needGetCategorys ){
  618. this.action.listCategoryByPublisher(this.data.id,function(json){
  619. if (json.data.length){
  620. var isSetCurrentImmediately = ( json.data.length == 1 && ( this.options.restrictToColumn || this.options.isAll ) );
  621. json.data.each(function(category){
  622. new MWF.xApplication.cms.Index.Newer.CategorySel.Category(category, this, this.categoryContainer, {
  623. isCurrent : ( this.options.currentCategory == category.id ) || isSetCurrentImmediately
  624. });
  625. }.bind(this));
  626. }else{
  627. this.node.setStyle("display", "none");
  628. }
  629. }.bind(this), null, this.data.id);
  630. }else{
  631. if( this.data.wrapOutCategoryList && this.data.wrapOutCategoryList.length ){
  632. var isSetCurrentImmediately = ( this.data.wrapOutCategoryList.length == 1 && ( this.options.restrictToColumn || this.options.isAll ) );
  633. this.data.wrapOutCategoryList.each(function(category){
  634. new MWF.xApplication.cms.Index.Newer.CategorySel.Category(category, this, this.categoryContainer,{
  635. isCurrent : ( this.options.currentCategory == category.id ) || isSetCurrentImmediately
  636. });
  637. }.bind(this));
  638. }else{
  639. this.node.setStyle("display", "none");
  640. }
  641. }
  642. }
  643. });
  644. MWF.xApplication.cms.Index.Newer.CategorySel.Category = new Class({
  645. Implements: [Options],
  646. options: {
  647. "isCurrent" : false
  648. },
  649. initialize: function(data, column, container, options){
  650. this.setOptions( options );
  651. this.data = data;
  652. this.column = column;
  653. this.app = this.column.app;
  654. this.newer = this.column.newer;
  655. this.container = container;
  656. this.css = this.newer.css;
  657. this.load();
  658. },
  659. load: function(){
  660. if( !this.data.name )this.data.name = this.data.categoryName;
  661. this.node = new Element("div.categoryItem", {"styles": this.css.categoryItemNode}).inject(this.container);
  662. if( this.options.isCurrent )this.node.setStyles( this.css.categoryItemNode_over );
  663. this.textNode = new Element("div", {"styles": this.css.categoryItemTextNode}).inject(this.node);
  664. this.textNode.set({
  665. "text": this.data.categoryName
  666. });
  667. var _self = this;
  668. this.node.addEvents({
  669. "mouseover": function(e){if( !this.options.isCurrent )this.node.setStyles(this.css.categoryItemNode_over); }.bind(this),
  670. "mouseout": function(e){if( !this.options.isCurrent )this.node.setStyles(this.css.categoryItemNode);}.bind(this),
  671. "click": function(e){
  672. this.setCurrent();
  673. }.bind(this)
  674. });
  675. if( this.options.isCurrent )this.setCurrent();
  676. },
  677. setCurrent: function(){
  678. this.options.isCurrent = true;
  679. this.node.setStyles( this.css.categoryItemNode_current );
  680. this.newer.setCurrentCategory( this );
  681. }
  682. });