Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. var Veil = {};
  2.  
  3. var InplaceForm = Class.create(BuroAjax,{
  4. initialize: function()
  5. {
  6. this.params = $H({});
  7. },
  8. addParameters: function(params, pattern)
  9. {
  10. if (Object.isString(params) || Object.isArray(params))
  11. {
  12. throw new Error('Form.addParameters method accepts only objects or Hashes.');
  13. return;
  14. }
  15.  
  16. params = $H(params);
  17.  
  18. if (pattern)
  19. {
  20. params.each(function(pattern, pair) {
  21. this.set(pair.key, pair.value.interpolate(pattern));
  22. }.bind(params, pattern));
  23. }
  24.  
  25. this.params = this.params.merge(params);
  26. return this;
  27. },
  28. requestSuccess: function(json)
  29. {
  30. this.observeForm(json);
  31. },
  32. observeForm: function(response)
  33. {
  34. this.requestOnSuccess(response);
  35. this.formContainer.setStyle({
  36. position:'absolute',
  37. top: (document.viewport.getScrollOffsets().top+100) + 'px',
  38. left: (document.viewport.getWidth()-740)/2+'px'
  39. });
  40. this.formContainer.update(response.responseJSON.content);
  41. },
  42. requestError: function()
  43. {
  44. this.veil.destroy();
  45. delete this.veil;
  46. },
  47. formCancel: function(ev)
  48. {
  49. ev.stop();
  50. this.formContainer.update();
  51. this.veil.destroy();
  52. delete this.veil;
  53. },
  54. formError: function()
  55. {
  56.  
  57. }
  58. });
  59.  
  60. var PasswordChange = Class.create(InplaceForm, {
  61.  
  62. initialize: function($super, hash) {
  63. this.hash = hash;
  64. $super();
  65. this.formContainer = $('subform');
  66. this.veil = new Veil.Veil(this.formContainer);
  67. this.formContainer.show().update();
  68. this.showForm();
  69.  
  70. },
  71. showForm: function()
  72. {
  73. new Ajax.Request(
  74. '/denergia_login/d_login/setup_password/'+this.hash+'/1',
  75. {
  76. asynchronous:true,
  77. evalScripts:true,
  78. parameters: this.params,
  79. onSuccess: function (response, json) {
  80. this.observeForm(response);
  81. }.bind(this)
  82. }
  83. );
  84. }
  85. });
  86.  
  87. Veil.Veil = Class.create({
  88. initialize: function(ontop)
  89. {
  90. this.ontop = $(ontop);
  91. this.mayaVeil = new Element('div', {className: 'veil'}).setOpacity(0);
  92. document.body.appendChild(this.mayaVeil);
  93. this.mayaVeil.insert({after: ontop});
  94. this.mayaVeil.style.zIndex = 999;
  95.  
  96. new Effect.Opacity(this.mayaVeil, {from:0, to:0.61, duration: 0.1, afterFinish: Element.show.bind(ontop, ontop)});
  97. ontop.makePositioned().setStyle({zIndex: 1000}).hide();
  98.  
  99. this.resizeBinded = this.resize.bind(this);
  100. Event.observe(window, 'resize', this.resizeBinded);
  101. Event.observe(window, 'scroll', this.resizeBinded);
  102. Event.observe(this.mayaVeil, 'click', this.destroy.bind(this));
  103. this.resize();
  104. },
  105. resize: function()
  106. {
  107. this.mayaVeil.setStyle({
  108. 'top': document.viewport.getScrollOffsets().top+'px',
  109. 'left': document.viewport.getScrollOffsets().left+'px',
  110. 'height': document.viewport.getHeight()+'px',
  111. 'width': document.viewport.getWidth()+'px'
  112. });
  113. },
  114. destroy: function()
  115. {
  116. Event.stopObserving(window, 'resize', this.resizeBinded);
  117. Event.stopObserving(window, 'scroll', this.resizeBinded);
  118. this.mayaVeil.remove();
  119. this.ontop.undoPositioned();
  120. }
  121. });
  122.  
  123.  
  124. var dusers = {
  125. block: function(id, uuid)
  126. {
  127. new Ajax.Request(
  128. baseUrl+"block_user/"+id,
  129. {
  130. asynchronous:true,
  131. evalScripts:true,
  132. parameters: this.params,
  133. onSuccess: function (response, json) {
  134. redirectLocation = response.getHeader('X-Location');
  135. if (redirectLocation)
  136. {
  137. window.location.href = redirectLocation;
  138. return;
  139. }
  140. $('block_'+uuid).hide();
  141. $('unblock_'+uuid).show();
  142. }
  143. }
  144. );
  145. },
  146. unblock: function(id, uuid)
  147. {
  148. new Ajax.Request(
  149. baseUrl+"unblock_user/"+id,
  150. {
  151. asynchronous:true,
  152. evalScripts:true,
  153. parameters: this.params,
  154. onSuccess: function (response, json) {
  155. redirectLocation = response.getHeader('X-Location');
  156. if (redirectLocation)
  157. {
  158. window.location.href = redirectLocation;
  159. return;
  160. }
  161. $('block_'+uuid).show();
  162. $('unblock_'+uuid).hide();
  163. }.bind(this)
  164. }
  165. );
  166. },
  167.  
  168. delete: function(id, uuid)
  169. {
  170. new Ajax.Request(
  171. baseUrl+"delete_user/"+id,
  172. {
  173. asynchronous:true,
  174. evalScripts:true,
  175. parameters: this.params,
  176. onSuccess: function (response, json) {
  177. redirectLocation = response.getHeader('X-Location');
  178. if (redirectLocation)
  179. {
  180. window.location.href = redirectLocation;
  181. return;
  182. }
  183. $('d_user_'+uuid).dropOut();
  184. }.bind(this)
  185. }
  186. );
  187. },
  188.  
  189. ask_change_password: function(id, uuid)
  190. {
  191. new Ajax.Request(
  192. baseUrl+"ask_change_password/"+id,
  193. {
  194. asynchronous:true,
  195. evalScripts:true,
  196. parameters: this.params,
  197. onSuccess: function (response, json) {
  198. redirectLocation = response.getHeader('X-Location');
  199. if (redirectLocation)
  200. {
  201. window.location.href = redirectLocation;
  202. return;
  203. }
  204. alert('Um email foi enviado ao usuário');
  205. }.bind(this)
  206. }
  207. );
  208. },
  209. };
  210.  
  211.  
  212. var Password = Class.create(InplaceForm, {
  213. initialize: function($super)
  214. {
  215. $super();
  216. this.formContainer = $('subform');
  217. this.veil = new Veil.Veil(this.formContainer);
  218. this.formContainer.show().update();
  219. this.showForm();
  220. },
  221. showForm: function()
  222. {
  223. new Ajax.Request(
  224. '/denergia_login/d_login/forgot_password',
  225. {
  226. asynchronous:true,
  227. evalScripts:true,
  228. parameters: this.params,
  229. onSuccess: function (response, json) {
  230. this.observeForm(response);
  231. }.bind(this)
  232. }
  233. );
  234. },
  235. });
  236.  
  237.  
  238.  
  239. var User = Class.create(InplaceForm, {
  240. initialize: function($super, id)
  241. {
  242. $super();
  243. this.formContainer = $('subform');
  244. this.veil = new Veil.Veil(this.formContainer);
  245. this.formContainer.show().update();
  246. this.showForm(id);
  247. },
  248. showForm: function(id)
  249. {
  250. new Ajax.Request(
  251. baseUrl+"user/"+id,
  252. {
  253. asynchronous:true,
  254. evalScripts:true,
  255. parameters: this.params,
  256. onSuccess: function (response, json) {
  257. redirectLocation = response.getHeader('X-Location');
  258. if (redirectLocation)
  259. {
  260. window.location.href = redirectLocation;
  261. return;
  262.  
  263. }
  264. this.observeForm(response);
  265. }.bind(this)
  266. }
  267. );
  268. },
  269. });
  270.  
  271. var Group = Class.create(InplaceForm, {
  272. initialize: function($super, id)
  273. {
  274. $super();
  275. this.formContainer = $('subform');
  276. this.veil = new Veil.Veil(this.formContainer);
  277. this.formContainer.show().update();
  278. this.showForm(id);
  279. },
  280. showForm: function(id)
  281. {
  282. new Ajax.Request(
  283. baseUrl+"group/"+id,
  284. {
  285. asynchronous:true,
  286. evalScripts:true,
  287. parameters: this.params,
  288. onSuccess: function (response, json) {
  289. redirectLocation = response.getHeader('X-Location');
  290. if (redirectLocation)
  291. {
  292. window.location.href = redirectLocation;
  293. return;
  294. }
  295. this.observeForm(response);
  296. }.bind(this)
  297. }
  298. );
  299. },
  300. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement