Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Veil = {};
- var InplaceForm = Class.create(BuroAjax,{
- initialize: function()
- {
- this.params = $H({});
- },
- addParameters: function(params, pattern)
- {
- if (Object.isString(params) || Object.isArray(params))
- {
- throw new Error('Form.addParameters method accepts only objects or Hashes.');
- return;
- }
- params = $H(params);
- if (pattern)
- {
- params.each(function(pattern, pair) {
- this.set(pair.key, pair.value.interpolate(pattern));
- }.bind(params, pattern));
- }
- this.params = this.params.merge(params);
- return this;
- },
- requestSuccess: function(json)
- {
- this.observeForm(json);
- },
- observeForm: function(response)
- {
- this.requestOnSuccess(response);
- this.formContainer.setStyle({
- position:'absolute',
- top: (document.viewport.getScrollOffsets().top+100) + 'px',
- left: (document.viewport.getWidth()-740)/2+'px'
- });
- this.formContainer.update(response.responseJSON.content);
- },
- requestError: function()
- {
- this.veil.destroy();
- delete this.veil;
- },
- formCancel: function(ev)
- {
- ev.stop();
- this.formContainer.update();
- this.veil.destroy();
- delete this.veil;
- },
- formError: function()
- {
- }
- });
- var PasswordChange = Class.create(InplaceForm, {
- initialize: function($super, hash) {
- this.hash = hash;
- $super();
- this.formContainer = $('subform');
- this.veil = new Veil.Veil(this.formContainer);
- this.formContainer.show().update();
- this.showForm();
- },
- showForm: function()
- {
- new Ajax.Request(
- '/denergia_login/d_login/setup_password/'+this.hash+'/1',
- {
- asynchronous:true,
- evalScripts:true,
- parameters: this.params,
- onSuccess: function (response, json) {
- this.observeForm(response);
- }.bind(this)
- }
- );
- }
- });
- Veil.Veil = Class.create({
- initialize: function(ontop)
- {
- this.ontop = $(ontop);
- this.mayaVeil = new Element('div', {className: 'veil'}).setOpacity(0);
- document.body.appendChild(this.mayaVeil);
- this.mayaVeil.insert({after: ontop});
- this.mayaVeil.style.zIndex = 999;
- new Effect.Opacity(this.mayaVeil, {from:0, to:0.61, duration: 0.1, afterFinish: Element.show.bind(ontop, ontop)});
- ontop.makePositioned().setStyle({zIndex: 1000}).hide();
- this.resizeBinded = this.resize.bind(this);
- Event.observe(window, 'resize', this.resizeBinded);
- Event.observe(window, 'scroll', this.resizeBinded);
- Event.observe(this.mayaVeil, 'click', this.destroy.bind(this));
- this.resize();
- },
- resize: function()
- {
- this.mayaVeil.setStyle({
- 'top': document.viewport.getScrollOffsets().top+'px',
- 'left': document.viewport.getScrollOffsets().left+'px',
- 'height': document.viewport.getHeight()+'px',
- 'width': document.viewport.getWidth()+'px'
- });
- },
- destroy: function()
- {
- Event.stopObserving(window, 'resize', this.resizeBinded);
- Event.stopObserving(window, 'scroll', this.resizeBinded);
- this.mayaVeil.remove();
- this.ontop.undoPositioned();
- }
- });
- var dusers = {
- block: function(id, uuid)
- {
- new Ajax.Request(
- baseUrl+"block_user/"+id,
- {
- asynchronous:true,
- evalScripts:true,
- parameters: this.params,
- onSuccess: function (response, json) {
- redirectLocation = response.getHeader('X-Location');
- if (redirectLocation)
- {
- window.location.href = redirectLocation;
- return;
- }
- $('block_'+uuid).hide();
- $('unblock_'+uuid).show();
- }
- }
- );
- },
- unblock: function(id, uuid)
- {
- new Ajax.Request(
- baseUrl+"unblock_user/"+id,
- {
- asynchronous:true,
- evalScripts:true,
- parameters: this.params,
- onSuccess: function (response, json) {
- redirectLocation = response.getHeader('X-Location');
- if (redirectLocation)
- {
- window.location.href = redirectLocation;
- return;
- }
- $('block_'+uuid).show();
- $('unblock_'+uuid).hide();
- }.bind(this)
- }
- );
- },
- delete: function(id, uuid)
- {
- new Ajax.Request(
- baseUrl+"delete_user/"+id,
- {
- asynchronous:true,
- evalScripts:true,
- parameters: this.params,
- onSuccess: function (response, json) {
- redirectLocation = response.getHeader('X-Location');
- if (redirectLocation)
- {
- window.location.href = redirectLocation;
- return;
- }
- $('d_user_'+uuid).dropOut();
- }.bind(this)
- }
- );
- },
- ask_change_password: function(id, uuid)
- {
- new Ajax.Request(
- baseUrl+"ask_change_password/"+id,
- {
- asynchronous:true,
- evalScripts:true,
- parameters: this.params,
- onSuccess: function (response, json) {
- redirectLocation = response.getHeader('X-Location');
- if (redirectLocation)
- {
- window.location.href = redirectLocation;
- return;
- }
- alert('Um email foi enviado ao usuário');
- }.bind(this)
- }
- );
- },
- };
- var Password = Class.create(InplaceForm, {
- initialize: function($super)
- {
- $super();
- this.formContainer = $('subform');
- this.veil = new Veil.Veil(this.formContainer);
- this.formContainer.show().update();
- this.showForm();
- },
- showForm: function()
- {
- new Ajax.Request(
- '/denergia_login/d_login/forgot_password',
- {
- asynchronous:true,
- evalScripts:true,
- parameters: this.params,
- onSuccess: function (response, json) {
- this.observeForm(response);
- }.bind(this)
- }
- );
- },
- });
- var User = Class.create(InplaceForm, {
- initialize: function($super, id)
- {
- $super();
- this.formContainer = $('subform');
- this.veil = new Veil.Veil(this.formContainer);
- this.formContainer.show().update();
- this.showForm(id);
- },
- showForm: function(id)
- {
- new Ajax.Request(
- baseUrl+"user/"+id,
- {
- asynchronous:true,
- evalScripts:true,
- parameters: this.params,
- onSuccess: function (response, json) {
- redirectLocation = response.getHeader('X-Location');
- if (redirectLocation)
- {
- window.location.href = redirectLocation;
- return;
- }
- this.observeForm(response);
- }.bind(this)
- }
- );
- },
- });
- var Group = Class.create(InplaceForm, {
- initialize: function($super, id)
- {
- $super();
- this.formContainer = $('subform');
- this.veil = new Veil.Veil(this.formContainer);
- this.formContainer.show().update();
- this.showForm(id);
- },
- showForm: function(id)
- {
- new Ajax.Request(
- baseUrl+"group/"+id,
- {
- asynchronous:true,
- evalScripts:true,
- parameters: this.params,
- onSuccess: function (response, json) {
- redirectLocation = response.getHeader('X-Location');
- if (redirectLocation)
- {
- window.location.href = redirectLocation;
- return;
- }
- this.observeForm(response);
- }.bind(this)
- }
- );
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement