PermissionSetting.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. MWF.xApplication.cms.ColumnManager = MWF.xApplication.cms.ColumnManager || {};
  2. MWF.xApplication.cms.ColumnManager.PermissionSetting = new Class({
  3. Implements: [Options],
  4. options : {
  5. objectId : "", //对象或分类的ID
  6. objectType : "APPINFO", //CATEGORY
  7. permission : "VIEW" //PUBLISH
  8. },
  9. initialize: function(app, lp, node, options){
  10. this.app = app;
  11. this.node = $(node);
  12. this.lp = lp;
  13. this.setOptions( options );
  14. this.data = [];
  15. this.personList = [];
  16. this.unitList = [];
  17. //this.lp = this.app.lp.application.availableSetting;
  18. },
  19. load: function(){
  20. this.listData( function( json ){
  21. json.data = json.data || [];
  22. this.data = json.data;
  23. json.data.each(function( d ){
  24. if(d.usedObjectType == "USER" ){
  25. this.personList.push( d.usedObjectName )
  26. }else if(d.usedObjectType == "UNIT"){
  27. this.unitList.push( d.usedObjectName )
  28. }
  29. }.bind(this));
  30. this.createNode();
  31. }.bind(this));
  32. },
  33. createNode: function(){
  34. //if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  35. this.titleNode = new Element("div.availableTitleNode", {
  36. "styles": this.app.css.availableTitleNode,
  37. "text": this.lp.title
  38. }).inject(this.node);
  39. this.contentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  40. this.itemsContentNode = new Element("div.availableItemsContentNode", {"styles": this.app.css.availableItemsContentNode}).inject(this.contentNode);
  41. this.actionAreaNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  42. var changeIdentityList = new Element("div.selectButtonStyle", {
  43. "styles": this.app.css.selectButtonStyle,
  44. "text": this.lp.setPerson
  45. }).inject(this.actionAreaNode);
  46. changeIdentityList.addEvent("click", function(){
  47. this.changeIdentitys();
  48. }.bind(this));
  49. var changeUnitList = new Element("div.selectButtonStyle", {
  50. "styles": this.app.css.selectButtonStyle,
  51. "text": this.lp.setUnit
  52. }).inject(this.actionAreaNode);
  53. changeUnitList.addEvent("click", function(){
  54. this.changeUnit();
  55. }.bind(this));
  56. this.setItems();
  57. },
  58. setItems: function(){
  59. if (this.personList){
  60. this.personList.each(function(name){
  61. if (name) new MWF.widget.O2Person({"name": name}, this.itemsContentNode, {"style": "application"});
  62. }.bind(this));
  63. }
  64. if (this.unitList){
  65. this.unitList.each(function(name){
  66. if (name) new MWF.widget.O2Unit({"name": name}, this.itemsContentNode, {"style": "application"});
  67. }.bind(this));
  68. }
  69. },
  70. changeIdentitys: function(){
  71. var options = {
  72. "type": "person",
  73. "title": this.lp.setPerson,
  74. "values": this.personList || [],
  75. "onComplete": function(items){
  76. var personList = [];
  77. items.each(function(item){
  78. personList.push(item.data.distinguishedName);
  79. }.bind(this));
  80. personList.each(function(item){
  81. if( !this.personList.contains( item ) ){
  82. var object = {
  83. "objectType": this.options.objectType,
  84. "objectId": this.options.objectId,
  85. "usedObjectType": "USER",
  86. "usedObjectCode": item,
  87. "usedObjectName": item,
  88. "permission" : this.options.permission
  89. };
  90. this.saveData(object, function(json){
  91. object.id = json.data.id;
  92. this.data.push( object );
  93. }.bind(this), null, false);
  94. }
  95. }.bind(this));
  96. this.personList.each(function(item){
  97. if( !personList.contains( item ) ){
  98. var ad = null;
  99. var id = "";
  100. this.data.each(function(data){
  101. if( data.usedObjectName == item ){
  102. ad = data;
  103. id = data.id;
  104. }
  105. }.bind(this));
  106. this.removeData(id, function(json){
  107. this.data.erase( ad )
  108. }.bind(this));
  109. }
  110. }.bind(this));
  111. this.personList = personList;
  112. this.itemsContentNode.empty();
  113. this.setItems();
  114. this.app.notice( this.lp.setIdentitySuccess , "success");
  115. }.bind(this)
  116. };
  117. var selector = new MWF.O2Selector(this.app.content, options);
  118. },
  119. changeUnit: function(){
  120. var options = {
  121. "type": "unit",
  122. "title": this.lp.setUnit,
  123. "values": this.unitList || [],
  124. "onComplete": function(items){
  125. var unitList = [];
  126. items.each(function(item){
  127. unitList.push(item.data.distinguishedName);
  128. }.bind(this));
  129. unitList.each(function(item){
  130. if( !this.unitList.contains( item ) ){
  131. var object = {
  132. "objectType": this.options.objectType,
  133. "objectId": this.options.objectId,
  134. "usedObjectType": "UNIT",
  135. "usedObjectCode": item,
  136. "usedObjectName": item,
  137. "permission" : this.options.permission
  138. };
  139. this.saveData(object, function(json){
  140. object.id = json.data.id;
  141. this.data.push( object );
  142. }.bind(this));
  143. }
  144. }.bind(this));
  145. this.unitList.each(function(item){
  146. if( !unitList.contains( item ) ){
  147. var ad = null;
  148. var id = "";
  149. this.data.each(function(data){
  150. if( data.usedObjectName == item ){
  151. ad = data;
  152. id = data.id;
  153. }
  154. }.bind(this));
  155. this.removeData(id, function(json){
  156. this.data.erase( ad )
  157. }.bind(this));
  158. }
  159. }.bind(this));
  160. this.unitList = unitList;
  161. this.itemsContentNode.empty();
  162. this.setItems();
  163. this.app.notice( this.lp.setUnitSuccess , "success");
  164. }.bind(this)
  165. };
  166. var selector = new MWF.O2Selector(this.app.content, options);
  167. },
  168. listData: function( callback ){
  169. this.app.restActions.listColumnPermission(this.options.objectId, function(json){
  170. if( callback )callback( json );
  171. }.bind(this), null ,false)
  172. },
  173. removeData: function( id, callback ){
  174. this.app.restActions.removePermission(id, function (json) {
  175. if( callback )callback( json );
  176. }.bind(this), null, false);
  177. },
  178. saveData: function( data, callback ){
  179. this.app.restActions.savePermission(data, function (json) {
  180. if( callback )callback( json );
  181. }.bind(this), null, false);
  182. }
  183. });