Newer.js 37 KB

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