Implement remove

This commit is contained in:
YNH Webdev
2013-09-24 00:18:38 +02:00
parent 7e673b4628
commit 3f089d6811
2 changed files with 43 additions and 8 deletions

View File

@@ -75,6 +75,7 @@ class WSF_CONTROL
@state = @fullstate.state
@load_subcontrols()
@isolation = (""+@$el.data('isolation')=="1")
@$el.data('control',@)
return
load_subcontrols: ()->
@@ -93,6 +94,7 @@ class WSF_CONTROL
update: (state)->
return
process_actions: (actions)->
for action in actions
try
@@ -146,6 +148,7 @@ class WSF_CONTROL
if new_states.actions?
self.process_actions(new_states.actions)
self.process_update(new_states)
#Simple event listener
#subscribe to an event
@@ -165,6 +168,11 @@ class WSF_CONTROL
ev.callback.call(ev.context)
return @
remove:()->
console.log "Removed #{@control_name}"
@$el.remove()
class WSF_PAGE_CONTROL extends WSF_CONTROL
constructor: (@fullstate)->
@state = @fullstate.state
@@ -173,11 +181,16 @@ class WSF_PAGE_CONTROL extends WSF_CONTROL
@control_name = @state.id
@url = @state['url']
@url_params = jQuery.unparam(@state['url_params'])
@$el.data('control',@)
@load_subcontrols()
wrap : (cname,state)->
state
remove:()->
console.log "Removed #{@control_name}"
@$el.remove()
controls = {}
class WSF_BUTTON_CONTROL extends WSF_CONTROL
@@ -357,14 +370,17 @@ class WSF_PROGRESS_CONTROL extends WSF_CONTROL
fetch: ()->
@trigger_callback(@control_name, 'progress_fetch')
if @$el.closest('body').length <= 0
clearInterval(@int)
update: (state)->
if state.progress?
@state['progress'] = state.progress
@$el.children('.progress-bar').attr('aria-valuenow', state.progress).width(state.progress + '%')
remove: ()->
clearInterval(@int)
super
class WSF_PAGINATION_CONTROL extends WSF_CONTROL
attach_events: ()->
@@ -436,7 +452,10 @@ start_modal = (action)->
modal.appendTo('body')
modal.modal('show')
modal.on 'hidden.bs.modal', ()->
modal.remove()
$(modal.find('[data-name]').get().reverse()).each (i,value)->
$(value).data('control').remove()
return
return
$.get( action.url, { ajax: 1 } )
.done (data) ->
modal.find('.modal-body').append(data)

View File

@@ -139,6 +139,7 @@ WSF_CONTROL = (function() {
this.state = this.fullstate.state;
this.load_subcontrols();
this.isolation = "" + this.$el.data('isolation') === "1";
this.$el.data('control', this);
return;
}
@@ -287,6 +288,11 @@ WSF_CONTROL = (function() {
return this;
};
WSF_CONTROL.prototype.remove = function() {
console.log("Removed " + this.control_name);
return this.$el.remove();
};
return WSF_CONTROL;
})();
@@ -303,6 +309,7 @@ WSF_PAGE_CONTROL = (function(_super) {
this.control_name = this.state.id;
this.url = this.state['url'];
this.url_params = jQuery.unparam(this.state['url_params']);
this.$el.data('control', this);
this.load_subcontrols();
}
@@ -310,6 +317,11 @@ WSF_PAGE_CONTROL = (function(_super) {
return state;
};
WSF_PAGE_CONTROL.prototype.remove = function() {
console.log("Removed " + this.control_name);
return this.$el.remove();
};
return WSF_PAGE_CONTROL;
})(WSF_CONTROL);
@@ -642,10 +654,7 @@ WSF_PROGRESS_CONTROL = (function(_super) {
};
WSF_PROGRESS_CONTROL.prototype.fetch = function() {
this.trigger_callback(this.control_name, 'progress_fetch');
if (this.$el.closest('body').length <= 0) {
return clearInterval(this.int);
}
return this.trigger_callback(this.control_name, 'progress_fetch');
};
WSF_PROGRESS_CONTROL.prototype.update = function(state) {
@@ -655,6 +664,11 @@ WSF_PROGRESS_CONTROL = (function(_super) {
}
};
WSF_PROGRESS_CONTROL.prototype.remove = function() {
clearInterval(this.int);
return WSF_PROGRESS_CONTROL.__super__.remove.apply(this, arguments);
};
return WSF_PROGRESS_CONTROL;
})(WSF_CONTROL);
@@ -763,7 +777,9 @@ start_modal = function(action) {
modal.appendTo('body');
modal.modal('show');
modal.on('hidden.bs.modal', function() {
return modal.remove();
$(modal.find('[data-name]').get().reverse()).each(function(i, value) {
$(value).data('control').remove();
});
});
return $.get(action.url, {
ajax: 1