Newer.js 39 KB

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