Guest User

Untitled

a guest
Jul 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.71 KB | None | 0 0
  1. <?php $this->headScript()->captureStart() ?>
  2. YAHOO.util.Event.onDOMReady(function () {
  3.  
  4. //Datatable add row
  5. Yagis.Datatable.prototype.addRow = function() {
  6. YAHOO.util.Connect.asyncRequest('POST', this.options.addDataUrl, {
  7. success: function (o) {
  8. try {
  9. var responseText = YAHOO.lang.JSON.parse(o.responseText);
  10.  
  11. //Handle invalid reply code response
  12. if(responseText.replyCode != 200) {
  13. return;
  14. }
  15.  
  16. if(responseText.id != null) {
  17. var options = {id: responseText.id};
  18. } else {
  19. var options = {};
  20. }
  21.  
  22. this.dt.addRow(options, 0);
  23. } catch (e) {
  24.  
  25. }
  26. } ,
  27. failure: function(o) {
  28.  
  29. } ,
  30. scope: this
  31. }
  32. );
  33. };
  34.  
  35. var rolesArr = [
  36. <?php $i=0;?>
  37. <?php foreach ($this->roles as $role):?>
  38. <?php $i++;?>
  39. <?php if($i == count($this->roles)):?>
  40. "<?=$role->key?>"
  41. <?php else:?>
  42. "<?=$role->key?>",
  43. <?php endif;?>
  44. <?php endforeach;?>
  45. ];
  46.  
  47. var groupsArr = [
  48. <?php $i=0;?>
  49. <?php foreach ($this->groups as $group):?>
  50. <?php $i++;?>
  51. <?php if($i == count($this->groups)):?>
  52. "<?=$group?>"
  53. <?php else:?>
  54. "<?=$group?>",
  55. <?php endif;?>
  56. <?php endforeach;?>
  57. ];
  58.  
  59. //Rules
  60. var rulesOptions = {
  61. fields : [
  62. "id" ,
  63. "role" ,
  64. "resource" ,
  65. "privilege" ,
  66. "group"
  67. ] ,
  68. columnDefs : [
  69. {key: "id", resizeable:true, sortable:true, width: 25, label: '<?=$this->translate('id')?>'} ,
  70. {
  71. key: "role" ,
  72. resizeable:true ,
  73. sortable:true ,
  74. editor: new YAHOO.widget.DropdownCellEditor({dropdownOptions: rolesArr}) ,
  75. width: 50 ,
  76. label: '<?=$this->translate('role')?>'
  77. } ,
  78. {key: "resource", resizeable:true, sortable:true, editor: "textbox", width: 200, label: '<?=$this->translate('resource')?>'} ,
  79. {key: "privilege", resizeable:true, sortable:true, editor: "textbox", width: 150, label: '<?=$this->translate('privilege')?>'} ,
  80. {
  81. key: "group" ,
  82. resizeable:true ,
  83. sortable:true ,
  84. editor: new YAHOO.widget.DropdownCellEditor({dropdownOptions: groupsArr, disableBtns:true}) ,
  85. width: 50,
  86. label: '<?=$this->translate('group')?>'
  87. }
  88. ],
  89. dataUrl : '<?=$this->url(array())?>/ruleget' ,
  90. addDataUrl : '<?=$this->url(array())?>/ruleadd' ,
  91. updateDataUrl : '<?=$this->url(array())?>/ruleupdate' ,
  92. deleteDataUrl : '<?=$this->url(array())?>/ruledelete' ,
  93. container : 'ruleContainer' ,
  94. rowsPerPage : <?=$this->recordsPerPage?> ,
  95. keyColumn : 'id'
  96. };
  97.  
  98. function Rules(options) {
  99. Rules.superclass.constructor.call(this, options);
  100. };
  101. YAHOO.lang.extend(Rules, Yagis.Datatable);
  102.  
  103. Rules.prototype.deleteButton = new YAHOO.widget.Button('rulesDeleteButton');
  104. Rules.prototype.addButton = new YAHOO.widget.Button('rulesAddButton');
  105.  
  106. var rules = new Rules(rulesOptions);
  107. rules.initialize();
  108.  
  109. //Roles
  110. var rolesOptions = {
  111. fields : [
  112. "key" ,
  113. "extends"
  114. ] ,
  115. columnDefs : [
  116. {key: "key", resizeable:true, sortable:true, width: 50, label: '<?=$this->translate('key')?>'} ,
  117. {
  118. key: "extends" ,
  119. resizeable:true ,
  120. sortable:true ,
  121. editor: "textbox" ,
  122. width: 150 ,
  123. editor: new YAHOO.widget.CheckboxCellEditor({checkboxOptions: rolesArr}),
  124. label: '<?=$this->translate('extends')?>'
  125. }
  126. ],
  127. dataUrl : '<?=$this->url(array())?>/roleget' ,
  128. addDataUrl : '<?=$this->url(array())?>/roleadd' ,
  129. updateDataUrl : '<?=$this->url(array())?>/roleupdate' ,
  130. deleteDataUrl : '<?=$this->url(array())?>/roledelete' ,
  131. container : 'roleContainer' ,
  132. rowsPerPage : <?=$this->recordsPerPage?> ,
  133. keyColumn : 'key'
  134. };
  135.  
  136. function Roles(options) {
  137. Roles.superclass.constructor.call(this, options);
  138. };
  139. YAHOO.lang.extend(Roles, Yagis.Datatable);
  140.  
  141. //Add
  142. Roles.prototype.addRow = function() {
  143.  
  144. var handleNo = function() {
  145. this.addDialog.hide();
  146. Yagis.Util.destroyPanel(this.addDialog);
  147. };
  148.  
  149. var handleYes = function() {
  150.  
  151. var text = YAHOO.util.Dom.get('roleName').value;
  152.  
  153. for(var i in rolesArr) {
  154. var role = rolesArr[i];
  155. if(role == text) {
  156. this.addDialog.hide();
  157. Yagis.Util.destroyPanel(this.addDialog);
  158. this.triggerError(ya.translate._('roleAlreadyExists'));
  159. return;
  160. }
  161. }
  162.  
  163. if(text.length == 0) {
  164. this.addDialog.hide();
  165. Yagis.Util.destroyPanel(this.addDialog);
  166. this.triggerError(ya.translate._('nameEmpty'));
  167. return;
  168. }
  169.  
  170. var url = this.options.addDataUrl + '/key/' + text;
  171.  
  172. YAHOO.util.Connect.asyncRequest('GET', url, {
  173. success: function (o) {
  174. try {
  175. var responseText = YAHOO.lang.JSON.parse(o.responseText);
  176.  
  177. //Handle invalid reply code response
  178. if(responseText.replyCode != 200) {
  179. this.triggerError(pObj.parseErrors(responseText.errors));
  180. this.addDialog.hide();
  181. Yagis.Util.destroyPanel(this.addDialog);
  182. return;
  183. }
  184.  
  185. window.location = '';
  186.  
  187. } catch (e) {
  188.  
  189. }
  190. } ,
  191. failure: function(o) {
  192.  
  193. } ,
  194. scope: this
  195. }
  196. );
  197.  
  198. }
  199.  
  200. this.addDialog = new YAHOO.widget.SimpleDialog("simpledialog1",
  201. { width: "300px",
  202. fixedcenter: true,
  203. visible: true,
  204. draggable: true,
  205. close: true,
  206. text: '<label>' + ya.translate._('name') + '</label><input type="text" name="role_name" id="roleName" style="width: 200px;"/>',
  207. constraintoviewport: true,
  208. buttons: [ { text: ya.translate._('add'), handler: Yagis.Util.bind(handleYes, this), isDefault:true },
  209. { text: ya.translate._('cancel') , handler: Yagis.Util.bind(handleNo, this) } ]
  210. }
  211. );
  212.  
  213. this.addDialog.setHeader(ya.translate._('addNewRole'));
  214. this.addDialog.render("addDialog");
  215.  
  216. };
  217.  
  218. Roles.prototype.deleteButton = new YAHOO.widget.Button('rolesDeleteButton');
  219. Roles.prototype.addButton = new YAHOO.widget.Button('rolesAddButton');
  220.  
  221. var roles = new Roles(rolesOptions);
  222. roles.initialize();
  223.  
  224. });
  225. <?php $this->headScript()->captureEnd()?>
  226.  
  227. <div id="aclContainer">
  228. <div style="float: left;">
  229. <strong><?=$this->translate('rules')?>:</strong>
  230. <div id="ruleContainer"></div>
  231. <button id="rulesAddButton"><?=$this->translate('add')?></button>
  232. <button id="rulesDeleteButton" disabled><?=$this->translate('deleteSelected')?></button>
  233. </div>
  234.  
  235. <div style="float: right; width: 300px;">
  236. <strong><?=$this->translate('roles')?>:</strong>
  237. <div id="roleContainer"></div>
  238. <button id="rolesAddButton"><?=$this->translate('add')?></button>
  239. <button id="rolesDeleteButton" disabled><?=$this->translate('deleteSelected')?></button>
  240. </div>
  241. </div>
  242. <div id="addDialog"></div>
  243. <div id="errorPanel">
  244. </div>
Add Comment
Please, Sign In to add comment