Newer.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. MWF.xDesktop.requireApp("Template", "MPopupForm", 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: MPopupForm,
  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 = MWF.Actions.get("x_cms_assemble_control"); //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.distinguishedName]
  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;min-width: 100px;'>"+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.distinguishedName]
  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( 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. MWF.Actions.get("x_organization_assemble_personal").getPerson(function(json){
  248. var identities1 = (json.data && json.data.woIdentityList) ? json.data.woIdentityList : [];
  249. var identities = [];
  250. identities1.each( function(i){
  251. if( i.distinguishedName )identities.push(i);
  252. }.bind(this));
  253. var selected = (identities.length==1) ? true : false;
  254. identities.each(function(id){
  255. var departSel = new MWF.xApplication.cms.Index.Newer.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  256. if (selected) departSel.selected();
  257. }.bind(this));
  258. }.bind(this), null )
  259. },
  260. cancelStart: function(e){
  261. var _self = this;
  262. if (this.subjectInput.get("value")){
  263. this.app.confirm("warn", e, this.lp.start_cancel_title, this.lp.start_cancel, "320", "120", function(){
  264. _self.close();
  265. this.close();
  266. },function(){
  267. this.close();
  268. });
  269. }else{
  270. this.close();
  271. }
  272. },
  273. okStart: function(){
  274. if( !this.categoryData ){
  275. this.app.notice(this.lp.selectCategory, "error");
  276. }else{
  277. if( this.categoryData.workflowAppId && this.categoryData.workflowFlag ){
  278. this._createProcessDocument();
  279. }else{
  280. this._createDocument();
  281. }
  282. }
  283. },
  284. _createDocument: function(e){
  285. var title = this.subjectInput.get("value");
  286. var data = {
  287. "id" : this.documentAction.getUUID(),
  288. "isNewDocument" : true,
  289. "title": title,
  290. "creatorIdentity": this.identityArea.get("value"),
  291. "appId" :this.categoryData.appId,
  292. "categoryId" : this.categoryData.id,
  293. "form" : this.categoryData.formId,
  294. "formName" :this.categoryData.formName,
  295. "docStatus" : "draft",
  296. "categoryName" : this.categoryData.name || this.categoryData.categoryName,
  297. "categoryAlias" : this.categoryData.alias || this.categoryData.categoryAlias,
  298. "attachmentList" : []
  299. };
  300. if (!data.title){
  301. this.subjectInput.setStyle("border-color", "red");
  302. this.subjectInput.focus();
  303. this.app.notice(this.lp.inputSubject, "error");
  304. }else if (!data.creatorIdentity){
  305. this.departmentSelArea.setStyle("border-color", "red");
  306. this.app.notice(this.lp.selectStartId, "error");
  307. }else{
  308. this.mask = new MWF.widget.Mask({"style": "desktop"});
  309. this.mask.loadNode(this.formAreaNode);
  310. this.documentAction.addDocument( data, function(json){
  311. this.mask.hide();
  312. //this.markNode.destroy();
  313. this.close();
  314. this._openDocument( json.data.id );
  315. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  316. //this.app.refreshAll();
  317. this.app.notice(this.lp.Started, "success");
  318. // this.app.processConfig();
  319. }.bind(this), null);
  320. }
  321. },
  322. _openDocument: function(id,el){
  323. var _self = this;
  324. var appId = "cms.Document"+id;
  325. if (_self.app.desktop.apps[appId]){
  326. _self.app.desktop.apps[appId].setCurrent();
  327. }else {
  328. var options = {
  329. "readonly" :false,
  330. "documentId": id,
  331. "appId": appId,
  332. "postPublish" : function(){
  333. if(_self.view && _self.view.reload )_self.view.reload();
  334. this.fireEvent( "postPublish" );
  335. }.bind(this)
  336. };
  337. this.app.desktop.openApplication(el, "cms.Document", options);
  338. }
  339. },
  340. _createProcessDocument:function(e){
  341. var title = this.subjectInput.get("value");
  342. var processId = this.categoryData.workflowFlag;
  343. var data = {
  344. "title":this.subjectInput.get("value"),
  345. "identity": this.identityArea.get("value")
  346. };
  347. if (!data.title){
  348. this.subjectInput.setStyle("border-color", "red");
  349. this.subjectInput.focus();
  350. this.app.notice(this.lp.inputSubject, "error");
  351. }else if (!data.identity){
  352. this.departmentSelArea.setStyle("border-color", "red");
  353. this.app.notice(this.lp.selectStartId, "error");
  354. }else{
  355. var workData = {
  356. cmsDocument : {
  357. "isNewDocument" : true,
  358. "title": title,
  359. "creatorIdentity": data.identity,
  360. "appId" :this.categoryData.appId,
  361. "categoryId" : this.categoryData.id,
  362. //"form" : this.categoryData.formId,
  363. //"formName" :this.categoryData.formName,
  364. "docStatus" : "draft",
  365. "categoryName" : this.categoryData.name,
  366. "categoryAlias" : this.categoryData.alias,
  367. "createTime": new Date().format("db"),
  368. "attachmentList" : []
  369. }
  370. };
  371. this.mask = new MWF.widget.Mask({"style": "desktop"});
  372. this.mask.loadNode(this.formAreaNode);
  373. MWF.Actions.get("x_processplatform_assemble_surface").startWork( function( json ){
  374. this.mask.hide();
  375. //this.markNode.destroy();
  376. this.close();
  377. this.afterStartProcess( json.data, data.title, this.categoryData.workflowName, workData );
  378. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  379. //this.app.refreshAll();
  380. this.app.notice(this.lp.Started, "success");
  381. }.bind(this), null, processId, data)
  382. }
  383. },
  384. afterStartProcess: function(data, title, processName, workData){
  385. var workInfors = [];
  386. var currentTask = [];
  387. data.each(function(work){
  388. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  389. workInfors.push(this.getStartWorkInforObj(work));
  390. }.bind(this));
  391. var workId = currentTask[0];
  392. MWF.Actions.get("x_processplatform_assemble_surface").saveData(function(){
  393. if (currentTask.length==1){
  394. var options = {"workId": workId};
  395. this.app.desktop.openApplication(null, "process.Work", options);
  396. this.createStartWorkResault(workInfors, title, processName, false);
  397. }else{
  398. this.createStartWorkResault(workInfors, title, processName, true);
  399. }
  400. }.bind(this), null, workId, workData)
  401. },
  402. getStartWorkInforObj: function(work){
  403. var users = [];
  404. var currentTask = "";
  405. work.taskList.each(function(task, idx){
  406. users.push(task.identity.split("@")[0]+"("+task.unit.split("@")[0] + ")");
  407. if (work.currentTaskIndex==idx) currentTask = task.id;
  408. }.bind(this));
  409. return {"activity": work.fromActivityName, "users": users, "currentTask": currentTask};
  410. },
  411. createStartWorkResault: function(workInfors, title, processName, isopen){
  412. var content = "";
  413. workInfors.each(function(infor){
  414. 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>";
  415. if (infor.currentTask && isopen){
  416. content += "&nbsp;&nbsp;&nbsp;&nbsp;<span value='"+infor.currentTask+"'>"+this.lp.deal+"</span></div>";
  417. }else{
  418. content += "</div>";
  419. }
  420. }.bind(this));
  421. var msg = {
  422. "subject": this.lp.processStarted,
  423. "content": "<div>"+this.lp.processStartedMessage+"“["+processName+"]"+title+"”</div>"+content
  424. };
  425. var tooltip = layout.desktop.message.addTooltip(msg);
  426. var item = layout.desktop.message.addMessage(msg);
  427. this.setStartWorkResaultAction(tooltip);
  428. this.setStartWorkResaultAction(item);
  429. },
  430. setStartWorkResaultAction: function(item){
  431. var node = item.node.getElements("span");
  432. node.setStyles(this.css.dealStartedWorkAction);
  433. var _self = this;
  434. node.addEvent("click", function(e){
  435. var options = {"taskId": this.get("value")};
  436. _self.app.desktop.openApplication(e, "process.Work", options);
  437. });
  438. }
  439. });
  440. MWF.xApplication.cms.Index.Newer.DepartmentSel = new Class({
  441. initialize: function(data, starter, container, idArea){
  442. this.data = data;
  443. this.starter = starter;
  444. this.container = container;
  445. this.idArea = idArea;
  446. this.css = this.starter.css;
  447. this.isSelected = false;
  448. this.load();
  449. },
  450. load: function(){
  451. this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  452. //this.starter.documentAction.listDepartmentWithIdentity(function(department){
  453. // var unitList = department.data && department.data.unitList ? department.data.unitList : [""];
  454. // this.node.set("text", unitList[0]);
  455. //}.bind(this), null, { "identityList" : [ this.data.distinguishedName ] } );
  456. var unit = this.data.woUnit ? this.data.woUnit.name : this.lp.unnamedUnit;
  457. this.node.set("text",this.data.woUnit.name);
  458. this.node.addEvents({
  459. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  460. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  461. "click": function(){
  462. this.selected();
  463. }.bind(this)
  464. });
  465. },
  466. selected: function(){
  467. if (!this.isSelected){
  468. if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  469. this.node.setStyles(this.css.departSelNode_selected);
  470. this.isSelected = true;
  471. this.starter.currentDepartment = this;
  472. this.idArea.set({
  473. "text": this.data.name,
  474. "value": this.data.distinguishedName
  475. });
  476. }
  477. },
  478. unSelected: function(){
  479. if (this.isSelected){
  480. if (this.starter.currentDepartment) this.starter.currentDepartment = null;
  481. this.node.setStyles(this.css.departSelNode);
  482. this.isSelected = false;
  483. }
  484. }
  485. });
  486. MWF.xApplication.cms.Index.Newer.CategorySel = new Class({
  487. Extends: MWF.widget.Common,
  488. Implements: [Options, Events],
  489. options: {
  490. "style": "default",
  491. "restrictToColumn" : false
  492. },
  493. initialize: function(app, node, newer, columnData, categoryData, options){
  494. this.setOptions(options);
  495. this.node = node;
  496. this.newer = newer;
  497. this.lp = newer.lp;
  498. this.css = newer.css;
  499. this.action = newer.documentAction;
  500. this.columnData = columnData;
  501. this.categoryData = categoryData;
  502. },
  503. load: function(){
  504. if (!this.areaNode){
  505. this.createArea();
  506. }
  507. this.areaNode.fade("1");
  508. },
  509. closeArea: function(){
  510. if (this.areaNode) this.areaNode.fade("out");
  511. },
  512. createArea: function(){
  513. this.areaNode = new Element("div.categorySelAreaNode", {"styles": this.css.categorySelAreaNode}).inject(this.node );
  514. this.areaNode.addEvent("click", function(e){
  515. //this.closeArea();
  516. }.bind(this));
  517. this.columnContainer = new Element("div", {"styles": this.css.selColumnAreaNode}).inject( this.areaNode );
  518. this.columnScrollNode = new Element("div.columnScrollNode", {"styles": this.css.selColumnScrollNode}).inject(this.columnContainer);
  519. this.setScrollBar( this.columnScrollNode );
  520. this.columnContentNode = new Element("div.selColumnContentNode", {"styles": this.css.selColumnContentNode}).inject(this.columnScrollNode);
  521. this.categoryContainer = new Element("div", {"styles": this.css.selCategoryAreaNode}).inject( this.areaNode );
  522. this.categoryScrollNode = new Element("div", {"styles": this.css.selCategoryScrollNode}).inject(this.categoryContainer);
  523. this.setScrollBar( this.categoryScrollNode );
  524. this.categoryContentNode = new Element("div", {"styles": this.css.selCategoryContentNode}).inject(this.categoryScrollNode);
  525. if( this.options.restrictToColumn && this.columnData ){
  526. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(this.columnData, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  527. "needGetCategorys": true,
  528. "isCurrent": true,
  529. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  530. "restrictToColumn" : this.options.restrictToColumn
  531. });
  532. }else{
  533. this.listColumns();
  534. }
  535. },
  536. listColumns: function(){
  537. var c = { wrapOutCategoryList : [] };
  538. this.action.listColumnByPublish(function(json){
  539. json.data.each(function(column){
  540. if(!column.name)column.name = column.appName;
  541. if( column.wrapOutCategoryList && column.wrapOutCategoryList.length ){
  542. column.wrapOutCategoryList.each(function(category){
  543. c.wrapOutCategoryList.push(category);
  544. }.bind(this));
  545. }
  546. }.bind(this));
  547. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(c, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  548. "needGetCategorys": false,
  549. "isAll" : true,
  550. "isCurrent" : this.columnData ? false : true,
  551. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  552. "restrictToColumn" : this.options.restrictToColumn
  553. });
  554. json.data.each( function(column) {
  555. if(!column.name)column.name = column.appName;
  556. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(column, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  557. "needGetCategorys": false,
  558. "isCurrent": ( this.columnData && this.columnData.id == column.id) ? true : false,
  559. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  560. "restrictToColumn" : this.options.restrictToColumn
  561. });
  562. }.bind(this) )
  563. }.bind(this));
  564. }
  565. });
  566. MWF.xApplication.cms.Index.Newer.CategorySel.Column = new Class({
  567. Implements: [Options],
  568. options: {
  569. "needGetCategorys": false,
  570. "isAll" : false,
  571. "isCurrent" : false,
  572. "currentCategory" : "",
  573. "restrictToColumn" : false
  574. },
  575. initialize: function(data, app, newer, container, categoryContainer, options ){
  576. this.setOptions( options );
  577. this.data = data;
  578. this.app = app;
  579. this.newer = newer;
  580. this.lp = newer.lp;
  581. this.css = newer.css;
  582. this.action = newer.documentAction;
  583. this.container = container;
  584. this.categoryContainer = categoryContainer;
  585. this.load();
  586. },
  587. load: function(){
  588. this.node = new Element("div", {"styles": this.css.columnItemNode}).inject(this.container);
  589. var iconNode = this.iconNode = new Element("img",{
  590. "styles" : this.css.columnItemIconNode
  591. }).inject(this.node);
  592. if( this.options.isAll ){
  593. this.iconNode.set("src", "/x_component_cms_Index/$Main/default/icon/all_40.png")
  594. }else if (this.data.appIcon){
  595. this.iconNode.set("src", "data:image/png;base64,"+this.data.appIcon+"");
  596. }else{
  597. this.iconNode.set("src", "/x_component_cms_Index/$Main/default/icon/column.png")
  598. }
  599. this.textNode = new Element("div", {"styles": this.css.columnItemTextNode}).inject(this.node);
  600. if( this.options.isAll ){
  601. this.textNode.set("text", this.lp.all);
  602. }else{
  603. this.textNode.set("text", (this.data.name || this.data.appName) );
  604. }
  605. if( this.options.isAll ){
  606. //new Element("div", {"styles": this.css.columnSelectNode}).inject(this.node);
  607. }
  608. this.node.addEvents({
  609. "mouseover" : function(){ if( !this.options.isCurrent )this.node.setStyles( this.css.columnItemNode_over ) }.bind(this),
  610. "mouseout" : function(){ if( !this.options.isCurrent )this.node.setStyles( this.css.columnItemNode ) }.bind(this),
  611. "click" : function(){ this.setCurrent(); }.bind(this)
  612. });
  613. if( this.options.isCurrent )this.setCurrent();
  614. },
  615. setCurrent: function(){
  616. this.options.isCurrent = true;
  617. this.node.setStyles( this.css.columnItemNode_current );
  618. this.newer.setCurrentColumn( this );
  619. this.loadCategory();
  620. },
  621. loadCategory: function(){
  622. this.categoryContainer.empty();
  623. if( this.options.needGetCategorys ){
  624. this.action.listCategoryByPublisher(this.data.id,function(json){
  625. if (json.data.length){
  626. var isSetCurrentImmediately = ( json.data.length == 1 && ( this.options.restrictToColumn || this.options.isAll ) );
  627. json.data.each(function(category){
  628. new MWF.xApplication.cms.Index.Newer.CategorySel.Category(category, this, this.categoryContainer, {
  629. isCurrent : ( this.options.currentCategory == category.id ) || isSetCurrentImmediately
  630. });
  631. }.bind(this));
  632. }else{
  633. this.node.setStyle("display", "none");
  634. }
  635. }.bind(this), null, this.data.id);
  636. }else{
  637. if( this.data.wrapOutCategoryList && this.data.wrapOutCategoryList.length ){
  638. var isSetCurrentImmediately = ( this.data.wrapOutCategoryList.length == 1 && ( this.options.restrictToColumn || this.options.isAll ) );
  639. this.data.wrapOutCategoryList.each(function(category){
  640. new MWF.xApplication.cms.Index.Newer.CategorySel.Category(category, this, this.categoryContainer,{
  641. isCurrent : ( this.options.currentCategory == category.id ) || isSetCurrentImmediately
  642. });
  643. }.bind(this));
  644. }else{
  645. this.node.setStyle("display", "none");
  646. }
  647. }
  648. }
  649. });
  650. MWF.xApplication.cms.Index.Newer.CategorySel.Category = new Class({
  651. Implements: [Options],
  652. options: {
  653. "isCurrent" : false
  654. },
  655. initialize: function(data, column, container, options){
  656. this.setOptions( options );
  657. this.data = data;
  658. this.column = column;
  659. this.app = this.column.app;
  660. this.newer = this.column.newer;
  661. this.container = container;
  662. this.css = this.newer.css;
  663. this.load();
  664. },
  665. load: function(){
  666. if( !this.data.name )this.data.name = this.data.categoryName;
  667. this.node = new Element("div.categoryItem", {"styles": this.css.categoryItemNode}).inject(this.container);
  668. if( this.options.isCurrent )this.node.setStyles( this.css.categoryItemNode_over );
  669. this.textNode = new Element("div", {"styles": this.css.categoryItemTextNode}).inject(this.node);
  670. this.textNode.set({
  671. "text": this.data.categoryName
  672. });
  673. var _self = this;
  674. this.node.addEvents({
  675. "mouseover": function(e){if( !this.options.isCurrent )this.node.setStyles(this.css.categoryItemNode_over); }.bind(this),
  676. "mouseout": function(e){if( !this.options.isCurrent )this.node.setStyles(this.css.categoryItemNode);}.bind(this),
  677. "click": function(e){
  678. this.setCurrent();
  679. }.bind(this)
  680. });
  681. if( this.options.isCurrent )this.setCurrent();
  682. },
  683. setCurrent: function(){
  684. this.options.isCurrent = true;
  685. this.node.setStyles( this.css.categoryItemNode_current );
  686. this.newer.setCurrentCategory( this );
  687. }
  688. });