Starter.js 21 KB

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