ColumnViewerSetting.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. MWF.xApplication.cms.ColumnManager = MWF.xApplication.cms.ColumnManager || {};
  2. MWF.require("MWF.widget.O2Identity", null, false);
  3. MWF.xApplication.cms.ColumnManager.ColumnViewerSetting = new Class({
  4. Implements: [Options],
  5. options : {
  6. objectId : "" //对象或分类的ID
  7. //objectType : "APPINFO", //CATEGORY
  8. //permission : "VIEW" //PUBLISH
  9. },
  10. initialize: function(app, lp, node, options){
  11. this.app = app;
  12. this.node = $(node);
  13. this.lp = lp;
  14. this.setOptions( options );
  15. //this.lp = this.app.lp.application.availableSetting;
  16. },
  17. load: function(){
  18. this.createNode();
  19. this.listData( function(){
  20. this.loadOrg();
  21. }.bind(this));
  22. },
  23. createNode: function(){
  24. this.titleNode = new Element("div.availableTitleNode", {
  25. "styles": this.app.css.availableTitleNode,
  26. "text": this.lp.title
  27. }).inject(this.node);
  28. this.contentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  29. this.itemsContentNode = new Element("div.availableItemsContentNode", {"styles": this.app.css.availableItemsContentNode}).inject(this.contentNode);
  30. this.actionAreaNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  31. var changeAction = new Element("div.selectButtonStyle", {
  32. "styles": this.app.css.selectButtonStyle,
  33. "text": this.lp.set
  34. }).inject(this.actionAreaNode);
  35. changeAction.addEvent("click", function(){
  36. this.change();
  37. }.bind(this));
  38. },
  39. loadOrg : function(){
  40. this.itemsContentNode.empty();
  41. this.loadOrgWidget( this.data.personList );
  42. this.loadOrgWidget( this.data.unitList );
  43. this.loadOrgWidget( this.data.groupList );
  44. },
  45. loadOrgWidget: function(value ){
  46. this.OrgWidgetList = this.OrgWidgetList || [];
  47. var options = { "style": "xform", "canRemove": false };
  48. var node = this.itemsContentNode;
  49. (value || []).each(function( distinguishedName ){
  50. var flag = distinguishedName.substr(distinguishedName.length-1, 1);
  51. var data = { "name" : distinguishedName };
  52. switch (flag.toLowerCase()){
  53. case "i":
  54. var widget = new MWF.widget.O2Identity( data, node, options );
  55. break;
  56. case "p":
  57. var widget = new MWF.widget.O2Person(data, node, options);
  58. break;
  59. case "u":
  60. var widget = new MWF.widget.O2Unit(data, node, options);
  61. break;
  62. case "g":
  63. var widget = new MWF.widget.O2Group(data, node, options);
  64. break;
  65. default:
  66. var widget = new MWF.widget.O2Other( data, node, options);
  67. }
  68. this.OrgWidgetList.push( widget );
  69. }.bind(this));
  70. },
  71. change: function(){
  72. MWF.xDesktop.requireApp("Selector", "package", null, false);
  73. var opt = {
  74. "type" : "",
  75. "types" : ["person","unit","group"],
  76. "title": this.lp.set,
  77. "count" : 0,
  78. "values": ( this.data.personList || [] ).combine( this.data.unitList || []).combine( this.data.groupList || [] ),
  79. "expand": false,
  80. "onComplete": function( array ){
  81. var data = {
  82. personList : [],
  83. unitList : [],
  84. groupList : []
  85. };
  86. array.each( function( a ){
  87. var dn = a.data.distinguishedName;
  88. var flag = dn.substr(dn.length-1, 1);
  89. switch (flag.toLowerCase()){
  90. case "p":
  91. data.personList.push( dn );
  92. break;
  93. case "u":
  94. data.unitList.push( dn );
  95. break;
  96. case "g":
  97. data.groupList.push( dn );
  98. break;
  99. }
  100. });
  101. this.saveData( data, function(){
  102. this.listData( function(){
  103. this.loadOrg();
  104. }.bind(this));
  105. }.bind(this))
  106. }.bind(this)
  107. };
  108. var selector = new MWF.O2Selector(this.app.content, opt );
  109. },
  110. listData: function( callback ){
  111. this.app.restActions.listAppInfoViewers(this.options.objectId, function(json){
  112. this.data = json.data;
  113. if( callback )callback( json );
  114. }.bind(this), null ,false)
  115. },
  116. saveData: function( data, callback ){
  117. this.app.restActions.saveAppInfoViewer(this.options.objectId, data, function (json) {
  118. this.app.restActions.getColumn( this.options.objectId, function( js ){
  119. this.dataParent.data = js.data;
  120. this.app.options.column = js.data;
  121. this.app.options.application = js.data;
  122. if( callback )callback( json );
  123. }.bind(this));
  124. }.bind(this), null, false);
  125. }
  126. });