Introduce actions

First working modal
This commit is contained in:
YNH Webdev
2013-09-23 00:15:43 +02:00
parent 7dd726ca42
commit ca633d3524
8 changed files with 230 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.6.1
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, template, tmpl,
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, show_alert, start_modal, template, tmpl,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@@ -174,6 +174,21 @@ WSF_CONTROL = (function() {
WSF_CONTROL.prototype.update = function(state) {};
WSF_CONTROL.prototype.process_actions = function(actions) {
var action, fn, _i, _len, _results;
_results = [];
for (_i = 0, _len = actions.length; _i < _len; _i++) {
action = actions[_i];
try {
fn = eval(action.type);
_results.push(fn(action));
} catch (e) {
_results.push(console.log("Failed preforming action " + action.type));
}
}
return _results;
};
WSF_CONTROL.prototype.process_update = function(new_states) {
var control, _i, _len, _ref, _results;
if (new_states[this.control_name] != null) {
@@ -238,6 +253,9 @@ WSF_CONTROL = (function() {
contentType: 'application/json',
cache: false
}).done(function(new_states) {
if (new_states.actions != null) {
self.process_actions(new_states.actions);
}
return self.process_update(new_states);
});
};
@@ -731,3 +749,19 @@ WSF_REPEATER_CONTROL = (function(_super) {
return WSF_REPEATER_CONTROL;
})(WSF_CONTROL);
show_alert = function(action) {
return alert(action.message);
};
start_modal = function(action) {
var modal;
modal = $("<div class=\"modal fade\">\n<div class=\"modal-dialog\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">&times;</button>\n <h4 class=\"modal-title\">Modal title</h4>\n </div>\n <div class=\"modal-body\">\n \n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>\n <button type=\"button\" class=\"btn btn-primary\">Save changes</button>\n </div>\n </div><!-- /.modal-content -->\n</div><!-- /.modal-dialog -->\n</div><!-- /.modal -->");
modal.appendTo('body');
modal.modal();
return $.get(action.url, {
ajax: 1
}).done(function(data) {
return modal.find('.modal-body').append(data);
});
};