Starter.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. MWF.require("MWF.widget.Mask", null, false);
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.Index = MWF.xApplication.cms.Index || {};
  4. MWF.xApplication.cms.Index.Starter = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "ignoreDrafted" : false
  10. },
  11. initialize: function(columnData, categoryData, app, options){
  12. this.setOptions(options);
  13. this.path = "/x_component_cms_Index/$Starter/";
  14. this.cssPath = "/x_component_cms_Index/$Starter/"+this.options.style+"/css.wcss";
  15. this._loadCss();
  16. MWF.xDesktop.requireApp("cms.Index", "$Starter."+MWF.language, null, false);
  17. this.lp = MWF.xApplication.cms.Index.Starter.lp;
  18. this.columnData = columnData;
  19. this.categoryData = categoryData;
  20. this.app = app;
  21. },
  22. load: function( ){
  23. if( this.options.ignoreDrafted ){
  24. this._load();
  25. this.fireEvent( "postLoad" );
  26. }else if(this.categoryData.workflowAppId && this.categoryData.workflowFlag ){
  27. this._load();
  28. this.fireEvent( "postLoad" );
  29. }else{
  30. var fielter = {
  31. "categoryIdList": [this.categoryData.id ],
  32. "creatorList": [layout.desktop.session.user.name]
  33. };
  34. this.getDocumentAction( function(){
  35. this.documentAction.listDraftNext("(0)", 1, fielter, function(json){
  36. if( json.data.length > 0 ){
  37. this._openDocument(json.data[0].id);
  38. this.fireEvent( "postLoad" );
  39. }else{
  40. this._load();
  41. this.fireEvent( "postLoad" );
  42. }
  43. }.bind(this));
  44. }.bind(this));
  45. }
  46. },
  47. _load: function(){
  48. this.createMarkNode();
  49. this.createAreaNode();
  50. this.createStartNode();
  51. this.areaNode.inject(this.markNode, "after");
  52. this.areaNode.fade("in");
  53. $("form_startSubject").focus();
  54. this.setStartNodeSize();
  55. this.setStartNodeSizeFun = this.setStartNodeSize.bind(this);
  56. this.app.addEvent("resize", this.setStartNodeSizeFun);
  57. },
  58. _openDocument: function(id,el){
  59. var _self = this;
  60. var appId = "cms.Document"+id;
  61. if (_self.app.desktop.apps[appId]){
  62. _self.app.desktop.apps[appId].setCurrent();
  63. }else {
  64. var options = {
  65. "readonly" :false,
  66. "documentId": id,
  67. "appId": appId,
  68. "postPublish" : function(){
  69. //if(_self.creater.view )_self.creater.view.reload();
  70. this.fireEvent( "postPublish" );
  71. }.bind(this)
  72. };
  73. this.app.desktop.openApplication(el, "cms.Document", options);
  74. }
  75. },
  76. createMarkNode: function(){
  77. this.markNode = new Element("div#mark", {
  78. "styles": this.css.markNode,
  79. "events": {
  80. "mouseover": function(e){e.stopPropagation();},
  81. "mouseout": function(e){e.stopPropagation();}
  82. }
  83. }).inject(this.app.content);
  84. },
  85. createAreaNode: function(){
  86. this.areaNode = new Element("div#area", {
  87. "styles": this.css.areaNode
  88. });
  89. },
  90. createStartNode: function(){
  91. this.createNode = new Element("div", {
  92. "styles": this.css.createNode
  93. }).inject(this.areaNode);
  94. this.createNewNode = new Element("div", {
  95. "styles": this.css.createNewNode
  96. }).inject(this.createNode);
  97. this.formNode = new Element("div", {
  98. "styles": this.css.formNode
  99. }).inject(this.createNode);
  100. var categoryName = this.categoryData.name || this.categoryData.categoryName;
  101. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  102. "<tr><td colSpan=\"2\" style=\"height: 60px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  103. this.lp.start+" - "+categoryName+"</td></tr>" +
  104. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.department+":</td>" +
  105. "<td style=\"; text-align: left;\" id=\"form_startDepartment\"></td></tr>" +
  106. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.identity+":</td>" +
  107. "<td style=\"; text-align: left;\"><div id=\"form_startIdentity\"></div></td></tr>" +
  108. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.date+":</td>" +
  109. "<td style=\"; text-align: left;\"><div id=\"form_startDate\"></div></td></tr>" +
  110. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.subject+":</td>" +
  111. "<td style=\"; text-align: left;\"><input type=\"text\" id=\"form_startSubject\" " +
  112. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  113. "height: 26px;\"/></td></tr>" +
  114. "</table>";
  115. this.formNode.set("html", html);
  116. this.setStartFormContent();
  117. this.cancelActionNode = new Element("div", {
  118. "styles": this.css.cancelActionNode,
  119. "text": this.lp.cancel
  120. }).inject(this.formNode);
  121. this.startOkActionNode = new Element("div", {
  122. "styles": this.css.startOkActionNode,
  123. "text": this.lp.ok
  124. }).inject(this.formNode);
  125. this.cancelActionNode.addEvent("click", function(e){
  126. this.cancelStart(e);
  127. }.bind(this));
  128. this.startOkActionNode.addEvent("click", function(e){
  129. this.okStart(e);
  130. }.bind(this));
  131. },
  132. setStartFormContent: function(){
  133. this.dateArea = this.formNode.getElementById("form_startDate");
  134. var d = new Date();
  135. this.dateArea.set("text", d.format("%Y-%m-%d %H:%M"));
  136. this.departmentSelArea = this.formNode.getElementById("form_startDepartment");
  137. this.identityArea = this.formNode.getElementById("form_startIdentity");
  138. this.getOrgAction(function(){
  139. //if (!this.app.desktop.user.id){
  140. // this.orgAction.listPersonByKey(function(json){
  141. // if (json.data.length) this.app.desktop.user.id = json.data[0].id
  142. // this.loadDepartments();
  143. // }.bind(this), null, this.app.desktop.user.name);
  144. //}else{
  145. // this.loadDepartments();
  146. //}
  147. this.loadDepartments();
  148. }.bind(this));
  149. },
  150. loadDepartments: function(){
  151. if (this.app.desktop.session.user.name){
  152. this.orgAction.listIdentityByPerson(function(json){
  153. var selected = (json.data.length==1) ? true : false;
  154. json.data.each(function(id){
  155. var departSel = new MWF.xApplication.cms.Index.Starter.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  156. if (selected) departSel.selected();
  157. }.bind(this));
  158. }.bind(this), null, this.app.desktop.session.user.name)
  159. }
  160. },
  161. getOrgAction: function(callback){
  162. if (!this.orgAction){
  163. MWF.require("MWF.xAction.org.express.RestActions", function(){
  164. this.orgAction = new MWF.xAction.org.express.RestActions();
  165. if (callback) callback();
  166. }.bind(this));
  167. }else{
  168. if (callback) callback();
  169. }
  170. },
  171. setStartNodeSize: function(){
  172. var size = this.app.content.getSize();
  173. var allSize = this.app.content.getSize();
  174. this.markNode.setStyles({
  175. "width": ""+allSize.x+"px",
  176. "height": ""+allSize.y+"px"
  177. });
  178. this.areaNode.setStyles({
  179. "width": ""+size.x+"px",
  180. "height": ""+size.y+"px"
  181. });
  182. var hY = size.y*0.8;
  183. var mY = size.y*0.2/2;
  184. if( hY > 500 )hY = 500;
  185. this.createNode.setStyles({
  186. "height": ""+hY+"px",
  187. "margin-top": ""+mY+"px"
  188. });
  189. var iconSize = this.createNewNode.getSize();
  190. var formHeight = hY*0.7;
  191. if (formHeight>250) formHeight = 250;
  192. var formMargin = hY*0.3/2-iconSize.y;
  193. this.formNode.setStyles({
  194. "height": ""+formHeight+"px",
  195. "margin-top": ""+formMargin+"px"
  196. });
  197. },
  198. cancelStart: function(e){
  199. var _self = this;
  200. if ($("form_startSubject").get("value")){
  201. this.app.confirm("warn", e, this.lp.start_cancel_title, this.lp.start_cancel, "320px", "100px", function(){
  202. _self.markNode.destroy();
  203. _self.areaNode.destroy();
  204. this.close();
  205. },function(){
  206. this.close();
  207. }, null, this.app.content);
  208. }else{
  209. this.markNode.destroy();
  210. this.areaNode.destroy();
  211. }
  212. },
  213. okStart: function(){
  214. if( this.categoryData.workflowAppId && this.categoryData.workflowFlag ){
  215. this._createProcessDocument();
  216. }else{
  217. this._createDocument();
  218. }
  219. },
  220. _createDocument: function(e){
  221. var title = $("form_startSubject").get("value");
  222. this.getDocumentAction();
  223. var data = {
  224. "id" : this.documentAction.getUUID(),
  225. "isNewDocument" : true,
  226. "title": title,
  227. "creatorIdentity": this.identityArea.get("value"),
  228. "appId" :this.categoryData.appId,
  229. "categoryId" : this.categoryData.id,
  230. "form" : this.categoryData.formId,
  231. "formName" :this.categoryData.formName,
  232. "docStatus" : "draft",
  233. "categoryName" : this.categoryData.name,
  234. "categoryAlias" : this.categoryData.alias,
  235. "attachmentList" : []
  236. };
  237. if (!data.title){
  238. $("form_startSubject").setStyle("border-color", "red");
  239. $("form_startSubject").focus();
  240. this.app.notice(this.lp.inputSubject, "error");
  241. }else if (!data.creatorIdentity){
  242. this.departmentSelArea.setStyle("border-color", "red");
  243. this.app.notice(this.lp.selectStartId, "error");
  244. }else{
  245. this.mask = new MWF.widget.Mask({"style": "desktop"});
  246. this.mask.loadNode(this.areaNode);
  247. this.getDocumentAction(function(){
  248. this.documentAction.addDocument( data, function(json){
  249. this.mask.hide();
  250. this.markNode.destroy();
  251. this.areaNode.destroy();
  252. this._openDocument( json.data.id );
  253. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  254. //this.app.refreshAll();
  255. this.app.notice(this.lp.Started, "success");
  256. // this.app.processConfig();
  257. }.bind(this), null);
  258. }.bind(this));
  259. }
  260. },
  261. getDocumentAction: function(callback){
  262. if (!this.documentAction){
  263. MWF.xDesktop.requireApp("cms.Index", "Actions.RestActions", function(){
  264. this.documentAction = new MWF.xApplication.cms.Index.Actions.RestActions();
  265. if (callback) callback();
  266. }.bind(this));
  267. }else{
  268. if (callback) callback();
  269. }
  270. },
  271. _createProcessDocument:function(e){
  272. var title = $("form_startSubject").get("value");
  273. var processId = this.categoryData.workflowFlag;
  274. var data = {
  275. "title":$("form_startSubject").get("value"),
  276. "identity": this.identityArea.get("value")
  277. };
  278. if (!data.title){
  279. $("form_startSubject").setStyle("border-color", "red");
  280. $("form_startSubject").focus();
  281. this.app.notice(this.lp.inputSubject, "error");
  282. }else if (!data.identity){
  283. this.departmentSelArea.setStyle("border-color", "red");
  284. this.app.notice(this.lp.selectStartId, "error");
  285. }else{
  286. var workData = {
  287. cmsDocument : {
  288. "isNewDocument" : true,
  289. "title": title,
  290. "creatorIdentity": data.identity,
  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,
  297. "categoryAlias" : this.categoryData.alias,
  298. "createTime": new Date().format("db"),
  299. "attachmentList" : []
  300. }
  301. };
  302. this.mask = new MWF.widget.Mask({"style": "desktop"});
  303. this.mask.loadNode(this.areaNode);
  304. this.getDocumentAction(function(){
  305. this.documentAction.startWork( function( json ){
  306. this.mask.hide();
  307. this.markNode.destroy();
  308. this.areaNode.destroy();
  309. this.afterStartProcess( json.data, data.title, this.categoryData.workflowName, workData );
  310. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  311. //this.app.refreshAll();
  312. this.app.notice(this.lp.Started, "success");
  313. }.bind(this), null, processId, data)
  314. }.bind(this));
  315. }
  316. },
  317. afterStartProcess: function(data, title, processName, workData){
  318. var workInfors = [];
  319. var currentTask = [];
  320. data.each(function(work){
  321. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  322. workInfors.push(this.getStartWorkInforObj(work));
  323. }.bind(this));
  324. var workId = currentTask[0];
  325. this.documentAction.saveWorkData(function(){
  326. if (currentTask.length==1){
  327. var options = {"workId": workId};
  328. this.app.desktop.openApplication(null, "process.Work", options);
  329. this.createStartWorkResault(workInfors, title, processName, false);
  330. }else{
  331. this.createStartWorkResault(workInfors, title, processName, true);
  332. }
  333. }.bind(this), null, workId, workData)
  334. },
  335. getStartWorkInforObj: function(work){
  336. var users = [];
  337. var currentTask = "";
  338. work.taskList.each(function(task, idx){
  339. users.push(task.person+"("+task.department + ")");
  340. if (work.currentTaskIndex==idx) currentTask = task.id;
  341. }.bind(this));
  342. return {"activity": work.fromActivityName, "users": users, "currentTask": currentTask};
  343. },
  344. createStartWorkResault: function(workInfors, title, processName, isopen){
  345. var content = "";
  346. workInfors.each(function(infor){
  347. 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>"
  348. if (infor.currentTask && isopen){
  349. content += "&nbsp;&nbsp;&nbsp;&nbsp;<span value=\""+infor.currentTask+"\">"+this.lp.deal+"</span></div>";
  350. }else{
  351. content += "</div>";
  352. }
  353. }.bind(this));
  354. var msg = {
  355. "subject": this.lp.processStarted,
  356. "content": "<div>"+this.lp.processStartedMessage+"“["+processName+"]"+title+"”</div>"+content
  357. };
  358. var tooltip = layout.desktop.message.addTooltip(msg);
  359. var item = layout.desktop.message.addMessage(msg);
  360. this.setStartWorkResaultAction(tooltip);
  361. this.setStartWorkResaultAction(item);
  362. },
  363. setStartWorkResaultAction: function(item){
  364. var node = item.node.getElements("span");
  365. node.setStyles(this.css.dealStartedWorkAction);
  366. var _self = this;
  367. node.addEvent("click", function(e){
  368. var options = {"taskId": this.get("value")};
  369. _self.app.desktop.openApplication(e, "process.Work", options);
  370. });
  371. }
  372. });
  373. MWF.xApplication.cms.Index.Starter.DepartmentSel = new Class({
  374. initialize: function(data, starter, container, idArea){
  375. this.data = data;
  376. this.starter = starter;
  377. this.container = container;
  378. this.idArea = idArea;
  379. this.css = this.starter.css;
  380. this.isSelected = false;
  381. this.load();
  382. },
  383. load: function(){
  384. this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  385. this.starter.orgAction.getDepartmentByIdentity(function(department){
  386. this.node.set("text", department.data.name);
  387. }.bind(this), null, this.data.name);
  388. this.node.addEvents({
  389. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  390. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  391. "click": function(){
  392. this.selected();
  393. }.bind(this),
  394. });
  395. },
  396. selected: function(){
  397. if (!this.isSelected){
  398. if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  399. this.node.setStyles(this.css.departSelNode_selected);
  400. this.isSelected = true;
  401. this.starter.currentDepartment = this;
  402. this.idArea.set({
  403. "text": this.data.display,
  404. "value": this.data.name
  405. });
  406. }
  407. },
  408. unSelected: function(){
  409. if (this.isSelected){
  410. if (this.starter.currentDepartment) this.starter.currentDepartment = null;;
  411. this.node.setStyles(this.css.departSelNode);
  412. this.isSelected = false;
  413. }
  414. }
  415. });