PermissionExplorer.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  3. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  4. MWF.xApplication.Attendance.PermissionExplorer = new Class({
  5. Extends: MWF.xApplication.Attendance.Explorer,
  6. Implements: [Options, Events],
  7. initialize: function(node, app, actions, options){
  8. this.setOptions(options);
  9. this.app = app;
  10. this.path = "/x_component_Attendance/$PermissionExplorer/";
  11. this.cssPath = "/x_component_Attendance/$PermissionExplorer/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.actions = actions;
  14. this.node = $(node);
  15. this.initData();
  16. if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  17. },
  18. loadView : function(){
  19. this.view = new MWF.xApplication.Attendance.PermissionExplorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  20. this.view.load();
  21. this.setContentSize();
  22. },
  23. createDocument: function(){
  24. if(this.view)this.view._createDocument();
  25. }
  26. });
  27. MWF.xApplication.Attendance.PermissionExplorer.View = new Class({
  28. Extends: MWF.xApplication.Attendance.Explorer.View,
  29. _createItem: function(data){
  30. return new MWF.xApplication.Attendance.PermissionExplorer.Document(this.table, data, this.explorer, this);
  31. },
  32. _getCurrentPageData: function(callback, count){
  33. this.actions.listPermission(function(json){
  34. if (callback) callback(json);
  35. });
  36. },
  37. _removeDocument: function(document, all){
  38. this.actions.deletePermission(document.id, function(json){
  39. this.explorer.view.reload();
  40. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  41. }.bind(this));
  42. },
  43. _createDocument: function(){
  44. var permission = new MWF.xApplication.Attendance.PermissionExplorer.Permission(this.explorer);
  45. permission.create();
  46. },
  47. _openDocument: function( documentData ){
  48. var permission = new MWF.xApplication.Attendance.PermissionExplorer.Permission(this.explorer, documentData );
  49. permission.edit();
  50. }
  51. })
  52. MWF.xApplication.Attendance.PermissionExplorer.Document = new Class({
  53. Extends: MWF.xApplication.Attendance.Explorer.Document
  54. })
  55. MWF.xApplication.Attendance.PermissionExplorer.Permission = new Class({
  56. Extends: MWF.widget.Common,
  57. options: {
  58. "width": "500",
  59. "height": "400"
  60. },
  61. initialize: function( explorer, data ){
  62. this.explorer = explorer;
  63. this.app = explorer.app;
  64. this.data = data || {};
  65. this.css = this.explorer.css;
  66. this.load();
  67. },
  68. load: function(){
  69. if( this.data.organizationName )this.data.department = this.data.organizationName;
  70. if( this.data.adminName )this.data.personName = this.data.adminName;
  71. if( this.data.adminLevel )this.data.role = this.data.adminLevel;
  72. },
  73. open: function(e){
  74. this.isNew = false;
  75. this.isEdited = false;
  76. },
  77. create: function(){
  78. this.isNew = true;
  79. this._open();
  80. },
  81. edit: function(){
  82. this.isEdited = true;
  83. this._open();
  84. },
  85. _open : function(){
  86. this.createMarkNode = new Element("div", {
  87. "styles": this.css.createMarkNode,
  88. "events": {
  89. "mouseover": function(e){e.stopPropagation();},
  90. "mouseout": function(e){e.stopPropagation();}
  91. }
  92. }).inject(this.app.content, "after");
  93. this.createAreaNode = new Element("div", {
  94. "styles": this.css.createAreaNode
  95. });
  96. this.createNode();
  97. this.createAreaNode.inject(this.createMarkNode, "after");
  98. this.createAreaNode.fade("in");
  99. this.personName.focus();
  100. this.setCreateNodeSize();
  101. this.setCreateNodeSizeFun = this.setCreateNodeSize.bind(this);
  102. this.addEvent("resize", this.setCreateNodeSizeFun);
  103. },
  104. createNode: function(){
  105. var _self = this;
  106. this.createNode = new Element("div", {
  107. "styles": this.css.createNode
  108. }).inject(this.createAreaNode);
  109. this.createIconNode = new Element("div", {
  110. "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  111. }).inject(this.createNode);
  112. this.createFormNode = new Element("div", {
  113. "styles": this.css.createFormNode
  114. }).inject(this.createNode);
  115. var lp = this.app.lp.permission;
  116. var inputStyle = "width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;";
  117. var inputPersonStyle = "width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;"+
  118. "background : url(/x_component_Attendance/$PermissionExplorer/default/icon/selectperson.png) 98% center no-repeat";
  119. //+(!this.isNew && !this.isEdited ? "" :
  120. // ("<input type='text' id='role' " + "style='" + inputStyle +"'" + " value='" + ( this.data && this.data.role ? this.data.role : "") + "'/>")) +
  121. var html = "<table width='100%' height='200' border='0' cellPadding='0' cellSpacing='0'>" +
  122. "<tr>"+
  123. "<td colspan='2' style='height: 50px; line-height: 50px; text-align: center; min-width: 80px; font-size:18px;font-weight: bold;'>" + lp.setAttendancer + "</td>" +
  124. "</tr>" +
  125. "<tr>"+
  126. "<td style='height: 30px; line-height: 30px; text-align: left; min-width: 80px; width:25%'>" + lp.role + ":</td>" +
  127. "<td style='; text-align: left;' id='roleArea'></td>"+
  128. "</tr>" +
  129. "<tr id='departmentArea'>" +
  130. "<td style='height: 30px; line-height: 30px; text-align: left' >"+lp.department+":</td>" +
  131. "<td style='; text-align: right;'>" +
  132. (!this.isNew && !this.isEdited ? "" :
  133. ("<input type='text' id='department' " + "style='" + inputPersonStyle +"'" + " value='" + ( this.data && this.data.department ? this.data.department : "") + "'/>")) +
  134. "</td>" +
  135. "</tr>" +
  136. "<tr>"+
  137. "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.personName+":</td>" +
  138. "<td style='text-align: right;'>"+
  139. (!this.isNew && !this.isEdited ? "" :
  140. ("<input type='text' id='personName' " + "style='" + inputPersonStyle +"'" + " value='" + ( this.data && this.data.personName ? this.data.personName : "") + "'/>")) +
  141. "</td>" +
  142. "</tr>" +
  143. "</table>";
  144. this.createFormNode.set("html", html);
  145. this.personName = this.createFormNode.getElement("#personName");
  146. this.department = this.createFormNode.getElement("#department");
  147. this.roleArea = this.createFormNode.getElement("#roleArea");
  148. this.role = new MDomItem( this.roleArea, {
  149. "name" : "role",
  150. "type" : "select",
  151. "value" : this.data.role || "DEPT",
  152. "selectText" : ["公司管理员","部门管理员"],
  153. "selectValue" : ["COMPANY","DEPT"],
  154. "style" : {"text-align":"left"}
  155. }, true, this.app );
  156. this.role.load();
  157. this.personName.addEvent("click",function(){
  158. this.selecePerson()
  159. }.bind(this))
  160. this.department.addEvent("click",function(){
  161. this.selectDepartment( this.role.get("value") )
  162. }.bind(this))
  163. this.cancelActionNode = new Element("div", {
  164. "styles": this.css.createCancelActionNode,
  165. "text": this.app.lp.cancel
  166. }).inject(this.createFormNode);
  167. this.createOkActionNode = new Element("div", {
  168. "styles": this.css.createOkActionNode,
  169. "text": this.app.lp.ok
  170. }).inject(this.createFormNode);
  171. this.cancelActionNode.addEvent("click", function(e){
  172. this.cancelCreate(e);
  173. }.bind(this));
  174. this.createOkActionNode.addEvent("click", function(e){
  175. this.okCreate(e);
  176. }.bind(this));
  177. },
  178. setCreateNodeSize: function (width, height, top, left) {
  179. if (!width)width = this.options && this.options.width ? this.options.width : "50%"
  180. if (!height)height = this.options && this.options.height ? this.options.height : "50%"
  181. if (!top) top = this.options && this.options.top ? this.options.top : 0;
  182. if (!left) left = this.options && this.options.left ? this.options.left : 0;
  183. var allSize = this.app.content.getSize();
  184. var limitWidth = allSize.x; //window.screen.width
  185. var limitHeight = allSize.y; //window.screen.height
  186. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  187. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  188. 300 > width && (width = 300);
  189. 220 > height && (height = 220);
  190. top = top || parseInt((limitHeight - height) / 2, 10);
  191. left = left || parseInt((limitWidth - width) / 2, 10);
  192. this.createAreaNode.setStyles({
  193. "width": "" + width + "px",
  194. "height": "" + height + "px",
  195. "top": "" + top + "px",
  196. "left": "" + left + "px"
  197. });
  198. this.createNode.setStyles({
  199. "width": "" + width + "px",
  200. "height": "" + height + "px"
  201. });
  202. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x: 0, y: 0};
  203. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  204. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  205. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  206. //var formMargin = formHeight -iconSize.y;
  207. this.createFormNode.setStyles({
  208. "height": "" + contentHeight + "px"
  209. });
  210. },
  211. //setCreateNodeSize: function(){
  212. // var size = this.app.node.getSize();
  213. // var allSize = this.app.content.getSize();
  214. //
  215. // this.createAreaNode.setStyles({
  216. // "width": ""+size.x+"px",
  217. // "height": ""+size.y+"px"
  218. // });
  219. // var hY = size.y*0.6;
  220. // var mY = size.y*0.2/2;
  221. // this.createNode.setStyles({
  222. // "height": ""+hY+"px",
  223. // "margin-top": ""+mY+"px"
  224. // });
  225. //
  226. // var iconSize = this.createIconNode.getSize();
  227. // var formHeight = hY*0.7;
  228. // if (formHeight>250) formHeight = 250;
  229. // var formMargin = hY*0.3/2-iconSize.y;
  230. // this.createFormNode.setStyles({
  231. // "height": ""+formHeight+"px",
  232. // "margin-top": ""+formMargin+"px"
  233. // });
  234. //},
  235. cancelCreate: function(e){
  236. var _self = this;
  237. if ( this.isNew && this.personName.get("value") ){
  238. this.app.confirm("warn", e,
  239. this.app.lp.create_cancel_title,
  240. this.app.lp.create_cancel, "320px", "100px",
  241. function(){
  242. _self.createMarkNode.destroy();
  243. _self.createAreaNode.destroy();
  244. this.close();
  245. },function(){
  246. this.close();
  247. }
  248. );
  249. }else{
  250. this.createMarkNode.destroy();
  251. this.createAreaNode.destroy();
  252. delete _self;
  253. }
  254. },
  255. okCreate: function(e){
  256. var data = {
  257. "id" : this.data.id || null,
  258. "organizationName": this.department.get("value"),
  259. //"organizationOu" : this.department.get("value")=="" ? "" : this.data.organizationOu,
  260. "adminName": this.personName.get("value"),
  261. "adminLevel": this.role.getValue()
  262. };
  263. if (data.adminName ){
  264. this.app.restActions.savePermission(data, function(json){
  265. if( json.type == "ERROR" ){
  266. this.app.notice( json.message , "error");
  267. }else{
  268. this.createMarkNode.destroy();
  269. this.createAreaNode.destroy();
  270. if(this.explorer.view)this.explorer.view.reload();
  271. this.app.notice( this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess , "success");
  272. }
  273. // this.app.processConfig();
  274. }.bind(this));
  275. }else{
  276. this.adminName.setStyle("border-color", "red");
  277. this.adminName.focus();
  278. this.app.notice( this.app.lp.inputName, "error");
  279. }
  280. },
  281. selecePerson: function(){
  282. var options = {
  283. "type": "person",
  284. "title": "设置管理员",
  285. "count" : "1",
  286. "names": [this.data.personName] || [],
  287. "onComplete": function(items){
  288. this.data.personName = [];
  289. items.each(function(item){
  290. this.data.personName.push(item.data.name);
  291. }.bind(this));
  292. this.personName.set("value",this.data.personName);
  293. }.bind(this)
  294. };
  295. var selector = new MWF.OrgSelector(this.app.content, options);
  296. },
  297. selectDepartment: function( u ){
  298. var options = {
  299. "type": u=="COMPANY" ? "company" : "department",
  300. "title": u=="COMPANY" ? "选择公司":"选择部门",
  301. "count" : "1",
  302. "names": [this.data.department] || [],
  303. "onComplete": function(items){
  304. this.data.department = [];
  305. items.each(function(item){
  306. this.data.department.push(item.data.name);
  307. }.bind(this));
  308. this.department.set("value",this.data.department);
  309. }.bind(this)
  310. };
  311. var selector = new MWF.OrgSelector(this.app.content, options);
  312. }
  313. });