AssociatedDocument.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. MWF.xDesktop.requireApp("process.Xform", "AssociatedDocument", null, false);
  2. MWF.xApplication.cms.Xform.AssociatedDocument = MWF.CMSAssociatedDocument = new Class({
  3. Extends: MWF.APPAssociatedDocument,
  4. getBundle: function(){
  5. return this.form.businessData.document.id;
  6. },
  7. selectDocument: function(data){
  8. this.cancelAllAssociated( function () {
  9. if( data && data.length ){
  10. o2.Actions.load("x_cms_assemble_control").CorrelationAction.createWithDocument(this.form.businessData.document.id, {
  11. targetList: data
  12. }, function (json) {
  13. this.status = "showResult";
  14. if(this.dlg.titleText)this.dlg.titleText.set("text", MWF.xApplication.process.Xform.LP.associatedResult);
  15. if( layout.mobile ){
  16. var okAction = this.dlg.node.getElement(".MWF_dialod_Action_ok");
  17. if (okAction) okAction.hide();
  18. }else{
  19. var okNode = this.dlg.button.getFirst();
  20. if(okNode){
  21. okNode.hide();
  22. var cancelButton = okNode.getNext();
  23. if(cancelButton)cancelButton.set("value", o2.LP.widget.close);
  24. }
  25. }
  26. if( (json.data.failureList && json.data.failureList.length) || (json.data.successList && json.data.successList.length) ){
  27. this.showCreateResult(json.data.failureList, json.data.successList);
  28. }
  29. this.loadAssociatedDocument(function () {
  30. this.fireEvent("afterSelectResult", [this.documentList]);
  31. }.bind(this));
  32. }.bind(this));
  33. }else{
  34. this.status = "showResult";
  35. this.loadAssociatedDocument(function () {
  36. this.fireEvent("afterSelectResult", [this.documentList]);
  37. }.bind(this));
  38. if( this.dlg )this.dlg.close();
  39. }
  40. }.bind(this));
  41. },
  42. cancelAllAssociated: function( callback ){
  43. var _self = this;
  44. if( this.documentList.length ){
  45. var ids = [];
  46. if( this.json.reserve === false ){
  47. ids = this.documentList.map(function (doc) {
  48. return doc.id;
  49. });
  50. }else{
  51. var viewIds = (this.json.queryView || []).map(function (view) {
  52. return view.id;
  53. });
  54. var docs = this.documentList.filter(function (doc) {
  55. return viewIds.contains( doc.view );
  56. });
  57. ids = docs.map(function (doc) {
  58. return doc.id;
  59. });
  60. }
  61. o2.Actions.load("x_cms_assemble_control").CorrelationAction.deleteWithDocument(this.getBundle(), {
  62. idList: ids
  63. },function (json) {
  64. this.documentList = [];
  65. if(callback)callback();
  66. }.bind(this));
  67. }else{
  68. if(callback)callback();
  69. }
  70. },
  71. loadAssociatedDocument: function( callback ){
  72. this.documentListNode.empty();
  73. o2.Actions.load("x_cms_assemble_control").CorrelationAction.listWithDocumentWithSite(this.form.businessData.document.id, (this.json.site || this.json.id), function (json) {
  74. this.documentList = json.data;
  75. this.showDocumentList();
  76. if(callback)callback();
  77. }.bind(this));
  78. },
  79. cancelAssociated: function(e, d, itemNode){
  80. var lp = MWF.xApplication.cms.Xform.LP;
  81. var _self = this;
  82. this.form.confirm("warn", e, lp.cancelAssociatedTitle, lp.cancelAssociated.replace("{title}", o2.txt(d.targetTitle)), 370, 120, function () {
  83. _self.fireEvent("deleteDocument", [d]);
  84. o2.Actions.load("x_cms_assemble_control").CorrelationAction.deleteWithDocument(_self.form.businessData.document.id, {
  85. idList: [d.id]
  86. },function (json) {
  87. itemNode.destroy();
  88. _self.documentList.erase(d);
  89. this.close();
  90. //this.showDocumentList();
  91. }.bind(this));
  92. }, function () {
  93. this.close();
  94. });
  95. }
  96. });