+var ThemeEditDialog = AbstractDialog.extend({
+
+ validate: function()
+ {
+ var active = $('input.theme-list-item:checked', this.$window);
+
+ if(active.length < 1) {
+ this.errors.push("You must select at least one theme.");
+ return false;
+ }
+
+ console.log("Active:", active);
+ this.userData.themes = $.makeArray(active.map(function() { return this.value; }) );
+ console.log('After validate:', this.userData);
+ return this._super();
+ },
+
+ setFromString: function(string)
+ {
+ var $unmatchedList = $('tbody.unknown-themes', this.$window);
+
+ $("tr:not(.header)", $unmatchedList).remove();
+ $unmatchedList.hide();
+
+ $('input.theme-list-item', this.$window).removeAttr('checked');
+
+ var unmatched = [];
+
+ $.each(string.split(','), function() {
+ var name = $.trim(this);
+ if(!name) return;
+
+ console.log('Selecting:', name);
+ var checkbox = $("input.theme-list-item[value='"+name+"']", this.$window);
+
+ if(checkbox.length > 0)
+ checkbox.attr('checked', 'checked');
+ else
+ unmatched.push(name);
+ });
+
+ if(unmatched.length > 0)
+ {
+ $.each(unmatched, function() {
+ $('<tr><td colspan="5"><label><input type="checkbox"'+
+ ' checked="checked" class="theme-list-item" value="'
+ + this+ '" />"'+this+'"</label></td></tr>').
+ appendTo($unmatchedList);
+ });
+
+ $unmatchedList.show();
+ }
+ },
+
+ displayErrors: function() {
+ var errorP = $('.error-messages-inline-box', this.$window);
+ if(errorP.length > 0) {
+ var html = '';
+ $.each(this.errors, function() {
+ html += '<span>' + this + '</span>';
+ });
+ errorP.html(html);
+ errorP.show();
+ console.log('Validation errors:', html);
+ }
+ else
+ this._super();
+ },
+
+ reset: function()
+ {
+ this._super();
+ $('.error-messages-inline-box', this.$window).html('').hide();
+ }
+
+ });
+