Newer.js 45 KB

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