// Generated by CoffeeScript 1.6.1 var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CODEVIEW_CONTROL, WSF_CONTROL, WSF_DROPDOWN_CONTROL, WSF_FILE_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_NAVLIST_ITEM_CONTROL, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PASSWORD_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_SLIDER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, loaded, parseSuggestions, redirect, show_alert, start_modal, start_modal_big, 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; }; cache = {}; jQuery.cachedAsset = function(url, options) { var head, onload, script, success, successful, timeoutHandle; if (/\.css$/.test(url)) { $("", { rel: "stylesheet", type: "text/css", href: url }).appendTo("head"); return { done: function(fn) { return fn(); } }; } else { success = []; head = document.head || document.getElementsByTagName('head')[0] || document.documentElement; script = document.createElement('script'); script.async = 'async'; script.src = url; successful = false; onload = function(_, aborted) { var s, _i, _len; if (aborted == null) { aborted = false; } if (!(aborted || !script.readyState || script.readyState === 'complete')) { return; } clearTimeout(timeoutHandle); script.onload = script.onreadystatechange = script.onerror = null; if (head && script.parentNode) { head.removeChild(script); } script = void 0; if (success && !aborted) { successful = true; for (_i = 0, _len = success.length; _i < _len; _i++) { s = success[_i]; s(); } return success = []; } }; script.onload = script.onreadystatechange = onload; script.onerror = function() { return onload(null, true); }; timeoutHandle = setTimeout(script.onerror, 7500); head.insertBefore(script, head.firstChild); return { done: function(fn) { if (!successful) { success.push(fn); } else { fn(); } } }; } }; jQuery.unparam = function(value) { var i, l, pair, params, pieces; params = {}; pieces = value.split("&"); pair = void 0; i = void 0; l = void 0; i = 0; l = pieces.length; while (i < l) { pair = pieces[i].split("=", 2); params[decodeURIComponent(pair[0])] = (pair.length === 2 ? decodeURIComponent(pair[1].replace(/\+/g, " ")) : true); i++; } return params; }; template = tmpl = function(str, data) { var fn; fn = (!/\W/.test(str) ? cache[str] = cache[str] || tmpl(str) : new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").split("{{").join("\t").replace(/((^|}})[^\t]*)'/g, "$1\r").replace(/\t=(.*?)}}/g, "',$1,'").split("\t").join("');").split("}}").join("p.push('").split("\r").join("\\'") + "');}return p.join('');")); if (data) { return fn(data); } else { return fn; } }; Mini = { compile: function(t) { return { render: template(t) }; } }; parseSuggestions = function(data) { var a, d; for (a in data) { if (a === 'suggestions') { return data[a]; } else { d = parseSuggestions(data[a]); if (d != null) { return d; } } } return null; }; loaded = {}; lazy_load = function(requirements, fn, that) { if (requirements.length === 0) { return function() { var a; a = arguments; return fn.apply(that, a); }; } if (that == null) { that = window; } return function() { var a, args, counter, done, r, self, _i, _len; a = arguments; if (typeof args === "undefined" || args === null) { args = []; } counter = requirements.length + 1; self = this; done = function() { counter = counter - 1; if (counter === 0) { fn.apply(that, a); } }; for (_i = 0, _len = requirements.length; _i < _len; _i++) { r = requirements[_i]; if (loaded[r] == null) { loaded[r] = $.cachedAsset(r); } loaded[r].done(done); } return done(); }; }; build_control = function(control_name, state, control) { var $el, type, typeclass; $el = control.$el.find('[data-name=' + control_name + ']').first(); type = $el.data('type'); typeclass = null; try { typeclass = eval(type); } catch (e) { typeclass = WSF_CONTROL; } if ((type != null) && (typeclass != null)) { return new typeclass(control, $el, control_name, state); } return null; }; WSF_VALIDATOR = (function() { function WSF_VALIDATOR(parent_control, settings) { this.parent_control = parent_control; this.settings = settings; this.error = this.settings.error; return; } WSF_VALIDATOR.prototype.validate = function() { return true; }; return WSF_VALIDATOR; })(); WSF_REGEXP_VALIDATOR = (function(_super) { __extends(WSF_REGEXP_VALIDATOR, _super); function WSF_REGEXP_VALIDATOR() { WSF_REGEXP_VALIDATOR.__super__.constructor.apply(this, arguments); this.pattern = new RegExp(this.settings.expression, 'g'); } WSF_REGEXP_VALIDATOR.prototype.validate = function() { var res, val; val = this.parent_control.value(); res = val.match(this.pattern); return res !== null; }; return WSF_REGEXP_VALIDATOR; })(WSF_VALIDATOR); WSF_MIN_VALIDATOR = (function(_super) { __extends(WSF_MIN_VALIDATOR, _super); function WSF_MIN_VALIDATOR() { return WSF_MIN_VALIDATOR.__super__.constructor.apply(this, arguments); } WSF_MIN_VALIDATOR.prototype.validate = function() { var val; val = this.parent_control.value(); return val.length >= this.settings.min; }; return WSF_MIN_VALIDATOR; })(WSF_VALIDATOR); WSF_MAX_VALIDATOR = (function(_super) { __extends(WSF_MAX_VALIDATOR, _super); function WSF_MAX_VALIDATOR() { return WSF_MAX_VALIDATOR.__super__.constructor.apply(this, arguments); } WSF_MAX_VALIDATOR.prototype.validate = function() { var val; val = this.parent_control.value(); return val.length <= this.settings.max; }; return WSF_MAX_VALIDATOR; })(WSF_VALIDATOR); WSF_CONTROL = (function() { WSF_CONTROL.prototype.requirements = []; function WSF_CONTROL(parent_control, $el, control_name, fullstate) { this.parent_control = parent_control; this.$el = $el; this.control_name = control_name; this.fullstate = fullstate; this.state = this.fullstate.state; this.load_subcontrols(); this.isolation = "" + this.$el.data('isolation') === "1"; this.$el.data('control', this); this.initialize = lazy_load(this.requirements, this.attach_events, this); return; } WSF_CONTROL.prototype.load_subcontrols = function() { var control_name, state; if (this.fullstate.controls != null) { return this.controls = (function() { var _ref, _results; _ref = this.fullstate.controls; _results = []; for (control_name in _ref) { state = _ref[control_name]; _results.push(build_control(control_name, state, this)); } return _results; }).call(this); } else { return this.controls = []; } }; WSF_CONTROL.prototype.attach_events = function() { var control, _i, _len, _ref; console.log("Attached " + this.control_name); _ref = this.controls; for (_i = 0, _len = _ref.length; _i < _len; _i++) { control = _ref[_i]; if (control != null) { control.initialize(); } } }; 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 = null; if (this[action.type] != null) { fn = this[action.type]; _results.push(fn.call(this, action)); } else { 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; try { if (new_states.actions != null) { this.process_actions(new_states.actions); } if (new_states[this.control_name] != null) { this.update(new_states[this.control_name]); _ref = this.controls; for (_i = 0, _len = _ref.length; _i < _len; _i++) { control = _ref[_i]; if (control != null) { control.process_update(new_states[this.control_name]['controls']); } } } } catch (e) { return; } }; WSF_CONTROL.prototype.get_context_state = function() { if ((this.parent_control != null) && !this.isolation) { return this.parent_control.get_context_state(); } return this.wrap(this.control_name, this.fullstate); }; WSF_CONTROL.prototype.get_full_control_name = function() { var val; if (this.parent_control != null) { val = this.parent_control.get_full_control_name(); if (val !== "") { val = val + "-"; } return val + this.control_name; } return this.control_name; }; WSF_CONTROL.prototype.wrap = function(cname, state) { var ctrs; ctrs = {}; ctrs[cname] = state; state = { "controls": ctrs }; if (this.parent_control != null) { return this.parent_control.wrap(this.parent_control.control_name, state); } return state; }; WSF_CONTROL.prototype.callback_url = function(params) { if (this.parent_control != null) { return this.parent_control.callback_url(params); } $.extend(params, this.url_params); return this.url + '?' + $.param(params); }; WSF_CONTROL.prototype.trigger_callback = function(control_name, event, event_parameter) { return this.run_trigger_callback(this.get_full_control_name(), event, event_parameter); }; WSF_CONTROL.prototype.get_page = function() { if (this.parent_control != null) { return this.parent_control.get_page(); } return this; }; WSF_CONTROL.prototype.run_trigger_callback = function(control_name, event, event_parameter) { var self; if ((this.parent_control != null) && !this.isolation) { return this.parent_control.run_trigger_callback(control_name, event, event_parameter); } self = this; return $.ajax({ type: 'POST', url: this.callback_url({ control_name: control_name, event: event, event_parameter: event_parameter }), data: JSON.stringify(this.get_context_state()), processData: false, contentType: 'application/json', cache: false }).done(function(new_states) { return self.get_page().process_update(new_states); }); }; WSF_CONTROL.prototype.on = function(name, callback, context) { if (this._events == null) { this._events = {}; } if (this._events[name] == null) { this._events[name] = []; } this._events[name].push({ callback: callback, context: context }); return this; }; WSF_CONTROL.prototype.trigger = function(name) { var ev, _i, _len, _ref, _ref1; if (((_ref = this._events) != null ? _ref[name] : void 0) == null) { return this; } _ref1 = this._events[name]; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { ev = _ref1[_i]; ev.callback.call(ev.context); } return this; }; WSF_CONTROL.prototype.remove = function() { console.log("Removed " + this.control_name); return this.$el.remove(); }; return WSF_CONTROL; })(); WSF_PAGE_CONTROL = (function(_super) { __extends(WSF_PAGE_CONTROL, _super); function WSF_PAGE_CONTROL(fullstate) { this.fullstate = fullstate; this.state = this.fullstate.state; this.parent_control = null; this.$el = $('[data-name=' + this.state.id + ']'); 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.initialize = lazy_load(this.requirements, this.attach_events, this); this.load_subcontrols(); } WSF_PAGE_CONTROL.prototype.process_update = function(new_states) { var control, _i, _len, _ref; _ref = this.controls; for (_i = 0, _len = _ref.length; _i < _len; _i++) { control = _ref[_i]; if (control != null) { control.process_update(new_states); } } }; WSF_PAGE_CONTROL.prototype.get_full_control_name = function() { return ""; }; WSF_PAGE_CONTROL.prototype.wrap = function(cname, state) { return state; }; WSF_PAGE_CONTROL.prototype.remove = function() { console.log("Removed " + this.control_name); return this.$el.remove(); }; return WSF_PAGE_CONTROL; })(WSF_CONTROL); WSF_SLIDER_CONTROL = (function(_super) { __extends(WSF_SLIDER_CONTROL, _super); function WSF_SLIDER_CONTROL() { return WSF_SLIDER_CONTROL.__super__.constructor.apply(this, arguments); } WSF_SLIDER_CONTROL.prototype.requirements = ['/assets/bootstrap.min.js']; WSF_SLIDER_CONTROL.prototype.attach_events = function() { var id; WSF_SLIDER_CONTROL.__super__.attach_events.apply(this, arguments); id = "slider" + Math.round(Math.random() * 10000); this.$el.attr("id", id); this.$el.find("ol li").attr("data-target", "#" + id); return this.$el.find(".carousel-control").attr("href", "#" + id); }; return WSF_SLIDER_CONTROL; })(WSF_CONTROL); WSF_DROPDOWN_CONTROL = (function(_super) { __extends(WSF_DROPDOWN_CONTROL, _super); function WSF_DROPDOWN_CONTROL() { return WSF_DROPDOWN_CONTROL.__super__.constructor.apply(this, arguments); } WSF_DROPDOWN_CONTROL.prototype.requirements = ['/assets/bootstrap.min.js']; return WSF_DROPDOWN_CONTROL; })(WSF_CONTROL); controls = {}; WSF_BUTTON_CONTROL = (function(_super) { __extends(WSF_BUTTON_CONTROL, _super); function WSF_BUTTON_CONTROL() { return WSF_BUTTON_CONTROL.__super__.constructor.apply(this, arguments); } WSF_BUTTON_CONTROL.prototype.attach_events = function() { var self; WSF_BUTTON_CONTROL.__super__.attach_events.apply(this, arguments); self = this; return this.$el.click(function(e) { e.preventDefault(); return self.click(); }); }; WSF_BUTTON_CONTROL.prototype.click = function() { if (this.state['callback_click']) { return this.trigger_callback(this.control_name, 'click'); } }; WSF_BUTTON_CONTROL.prototype.update = function(state) { if (state.text != null) { this.state['text'] = state.text; return this.$el.text(state.text); } }; return WSF_BUTTON_CONTROL; })(WSF_CONTROL); WSF_INPUT_CONTROL = (function(_super) { __extends(WSF_INPUT_CONTROL, _super); function WSF_INPUT_CONTROL() { return WSF_INPUT_CONTROL.__super__.constructor.apply(this, arguments); } WSF_INPUT_CONTROL.prototype.attach_events = function() { var self; WSF_INPUT_CONTROL.__super__.attach_events.apply(this, arguments); self = this; return this.$el.change(function() { return self.change(); }); }; WSF_INPUT_CONTROL.prototype.change = function() { this.state['text'] = this.$el.val(); if (this.state['callback_change']) { this.trigger_callback(this.control_name, 'change'); } return this.trigger('change'); }; WSF_INPUT_CONTROL.prototype.value = function() { return this.$el.val(); }; WSF_INPUT_CONTROL.prototype.update = function(state) { if (state.text != null) { this.state['text'] = state.text; return this.$el.val(state.text); } }; return WSF_INPUT_CONTROL; })(WSF_CONTROL); WSF_FILE_CONTROL = (function(_super) { __extends(WSF_FILE_CONTROL, _super); function WSF_FILE_CONTROL() { WSF_FILE_CONTROL.__super__.constructor.apply(this, arguments); this.uploading = false; } WSF_FILE_CONTROL.prototype.start_upload = function() { var action, file, formData; if (this.uploading) { return; } this.uploading = true; this.$el.hide(); this.progressbar = $("