PermissionSetting.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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.departmentList = [];
  17. this.companyList = [];
  18. //this.lp = this.app.lp.application.availableSetting;
  19. },
  20. load: function(){
  21. this.listData( function( json ){
  22. json.data = json.data || [];
  23. this.data = json.data;
  24. json.data.each(function( d ){
  25. if(d.usedObjectType == "USER" ){
  26. this.personList.push( d.usedObjectName )
  27. }else if(d.usedObjectType == "DEPARTMENT"){
  28. this.departmentList.push( d.usedObjectName )
  29. }else{
  30. this.companyList.push( d.usedObjectName )
  31. }
  32. }.bind(this));
  33. this.createNode();
  34. }.bind(this));
  35. },
  36. createNode: function(){
  37. if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  38. this.titleNode = new Element("div", {
  39. "styles": this.app.css.availableTitleNode,
  40. "text": this.lp.title
  41. }).inject(this.node);
  42. this.contentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  43. this.itemsContentNode = new Element("div", {"styles": this.app.css.availableItemsContentNode}).inject(this.contentNode);
  44. this.actionAreaNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  45. var changeIdentityList = new Element("div", {
  46. "styles": this.app.css.selectButtonStyle,
  47. "text": this.lp.setPerson
  48. }).inject(this.actionAreaNode);
  49. changeIdentityList.addEvent("click", function(){
  50. this.changeIdentitys();
  51. }.bind(this));
  52. var changeDepartmentList = new Element("div", {
  53. "styles": this.app.css.selectButtonStyle,
  54. "text": this.lp.setDepartment
  55. }).inject(this.actionAreaNode);
  56. changeDepartmentList.addEvent("click", function(){
  57. this.changeDepartments();
  58. }.bind(this));
  59. var changeCompanyList = new Element("div", {
  60. "styles": this.app.css.selectButtonStyle,
  61. "text":this.lp.setCompany
  62. }).inject(this.actionAreaNode);
  63. changeCompanyList.addEvent("click", function(){
  64. this.changeCompanys();
  65. }.bind(this));
  66. this.setItems();
  67. },
  68. setItems: function(){
  69. var explorer = {
  70. "actions": this.personActions,
  71. "app": {
  72. "lp": this.app.lp
  73. }
  74. }
  75. if (this.personList){
  76. this.personList.each(function(name){
  77. if (name) new MWF.widget.Person({"name": name}, this.itemsContentNode, explorer, false, null, {"style": "application"});
  78. }.bind(this));
  79. }
  80. if (this.departmentList){
  81. this.departmentList.each(function(name){
  82. if (name) new MWF.widget.Department({"name": name}, this.itemsContentNode, explorer, false, null, {"style": "application"});
  83. }.bind(this));
  84. }
  85. if (this.companyList){
  86. this.companyList.each(function(name){
  87. if (name) new MWF.widget.Company({"name": name}, this.itemsContentNode, explorer, false, null, {"style": "application"});
  88. }.bind(this));
  89. }
  90. },
  91. changeIdentitys: function(){
  92. var explorer = {
  93. "actions": this.personActions,
  94. "app": {
  95. "lp": this.app.lp
  96. }
  97. };
  98. var options = {
  99. "type": "person",
  100. "title": this.lp.setPerson,
  101. "names": this.personList || [],
  102. "onComplete": function(items){
  103. var personList = [];
  104. items.each(function(item){
  105. personList.push(item.data.name);
  106. }.bind(this));
  107. personList.each(function(item){
  108. if( !this.personList.contains( item ) ){
  109. var object = {
  110. "objectType": this.options.objectType,
  111. "objectId": this.options.objectId,
  112. "usedObjectType": "USER",
  113. "usedObjectCode": item,
  114. "usedObjectName": item,
  115. "permission" : this.options.permission
  116. };
  117. this.saveData(object, function(json){
  118. object.id = json.data.id;
  119. this.data.push( object );
  120. }.bind(this), null, false);
  121. }
  122. }.bind(this));
  123. this.personList.each(function(item){
  124. if( !personList.contains( item ) ){
  125. var ad = null;
  126. var id = "";
  127. this.data.each(function(data){
  128. if( data.usedObjectName == item ){
  129. ad = data;
  130. id = data.id;
  131. }
  132. }.bind(this));
  133. this.removeData(id, function(json){
  134. this.data.erase( ad )
  135. }.bind(this));
  136. }
  137. }.bind(this))
  138. this.personList = personList;
  139. this.itemsContentNode.empty();
  140. this.setItems();
  141. this.app.notice( this.lp.setIdentitySuccess , "success");
  142. }.bind(this)
  143. };
  144. var selector = new MWF.OrgSelector(this.app.content, options);
  145. },
  146. changeDepartments: function(){
  147. var explorer = {
  148. "actions": this.personActions,
  149. "app": {
  150. "lp": this.app.lp
  151. }
  152. };
  153. var options = {
  154. "type": "department",
  155. "title": this.lp.setDepartment,
  156. "names": this.departmentList || [],
  157. "onComplete": function(items){
  158. var departmentList = [];
  159. items.each(function(item){
  160. departmentList.push(item.data.name);
  161. }.bind(this));
  162. departmentList.each(function(item){
  163. if( !this.departmentList.contains( item ) ){
  164. var object = {
  165. "objectType": this.options.objectType,
  166. "objectId": this.options.objectId,
  167. "usedObjectType": "DEPARTMENT",
  168. "usedObjectCode": item,
  169. "usedObjectName": item,
  170. "permission" : this.options.permission
  171. };
  172. this.saveData(object, function(json){
  173. object.id = json.data.id;
  174. this.data.push( object );
  175. }.bind(this));
  176. }
  177. }.bind(this));
  178. this.departmentList.each(function(item){
  179. if( !departmentList.contains( item ) ){
  180. var ad = null;
  181. var id = "";
  182. this.data.each(function(data){
  183. if( data.usedObjectName == item ){
  184. ad = data;
  185. id = data.id;
  186. }
  187. }.bind(this));
  188. this.removeData(id, function(json){
  189. this.data.erase( ad )
  190. }.bind(this));
  191. }
  192. }.bind(this));
  193. this.departmentList = departmentList;
  194. this.itemsContentNode.empty();
  195. this.setItems();
  196. this.app.notice( this.lp.setDepartmentSuccess , "success");
  197. }.bind(this)
  198. };
  199. var selector = new MWF.OrgSelector(this.app.content, options);
  200. },
  201. changeCompanys: function(){
  202. var explorer = {
  203. "actions": this.personActions,
  204. "app": {
  205. "lp": this.app.lp
  206. }
  207. };
  208. var options = {
  209. "type": "company",
  210. "title": this.lp.setCompany,
  211. "names": this.companyList || [],
  212. "onComplete": function(items) {
  213. var companyList = [];
  214. items.each(function (item) {
  215. companyList.push(item.data.name);
  216. }.bind(this));
  217. companyList.each(function (item) {
  218. if (!this.companyList.contains(item)) {
  219. var object = {
  220. "objectType": this.options.objectType,
  221. "objectId": this.options.objectId,
  222. "usedObjectType": "COMPANY",
  223. "usedObjectCode": item,
  224. "usedObjectName": item,
  225. "permission" : this.options.permission
  226. };
  227. this.saveData(object, function (json) {
  228. object.id = json.data.id;
  229. this.data.push( object );
  230. }.bind(this));
  231. }
  232. }.bind(this));
  233. this.companyList.each(function (item) {
  234. if (!companyList.contains(item)) {
  235. var ad = null;
  236. var id = "";
  237. this.data.each(function (data) {
  238. if (data.usedObjectName == item) {
  239. ad = data;
  240. id = data.id;
  241. }
  242. }.bind(this));
  243. this.removeData(id, function (json) {
  244. this.data.erase(ad)
  245. }.bind(this) );
  246. }
  247. }.bind(this));
  248. this.companyList = companyList;
  249. this.itemsContentNode.empty();
  250. this.setItems();
  251. this.app.notice( this.lp.setCompanySuccess , "success");
  252. }.bind(this)
  253. };
  254. var selector = new MWF.OrgSelector(this.app.content, options);
  255. },
  256. listData: function( callback ){
  257. this.app.restActions.listColumnPermission(this.options.objectId, function(json){
  258. if( callback )callback( json );
  259. }.bind(this), null ,false)
  260. },
  261. removeData: function( id, callback ){
  262. this.app.restActions.removePermission(id, function (json) {
  263. if( callback )callback( json );
  264. }.bind(this), null, false);
  265. },
  266. saveData: function( data, callback ){
  267. debugger;
  268. this.app.restActions.savePermission(data, function (json) {
  269. if( callback )callback( json );
  270. }.bind(this), null, false);
  271. }
  272. });