var App_WideSlide_Admin_Form = qs.createObject(); App_WideSlide_Admin_Form.prototype = { options: {}, form: null, elementId: { linkType: null, url: null, pageId: null, linkText: null }, hiddenClass: 'hidden', initialize: function(options) { options = $.extend({}, options); if (this.initOptions(options)) { $('#' + this.elementId.linkType).change(_.bind(this.onLinkTypeChange, this)).change(); } }, initOptions: function(options) { this.form = $('form#' + options.form); if (!$(this.form).size()) { this.showError('Form "#' + options.form + '" was not found.'); return false; } for (var key in this.elementId) { if (typeof options[key] != 'undefined') { this.elementId[key] = options[key]; options[key] = undefined; } else { this.showError('Option "' + key + '" is required.'); return false; } } for (key in options) { if (typeof options[key] != 'undefined') { this.options[key] = options[key]; } } return true; }, onLinkTypeChange: function(ev) { var type = $(ev.target).val(); this.hideElement(this.elementId.url); this.hideElement(this.elementId.pageId); this.hideElement(this.elementId.linkText); switch (type) { case 'url': this.showElement(this.elementId.url); this.showElement(this.elementId.linkText); break; case 'cms': this.showElement(this.elementId.pageId); this.showElement(this.elementId.linkText); break; } }, hideElement: function(id) { $('#' + id + '-label', this.form).addClass(this.hiddenClass); $('#' + id + '-element', this.form).addClass(this.hiddenClass); }, showElement: function(id) { $('#' + id + '-label', this.form).removeClass(this.hiddenClass); $('#' + id + '-element', this.form).removeClass(this.hiddenClass); }, showError: function(message) { alert('WideSlides: ' + message); } };