2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
Our data model for interacting with site customizations.
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-03-05 15:39:21 -05:00
|
|
|
@class SiteCustomization
|
2013-02-22 15:41:12 -05:00
|
|
|
@extends Discourse.Model
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-03-05 15:39:21 -05:00
|
|
|
**/
|
2013-02-22 15:41:12 -05:00
|
|
|
Discourse.SiteCustomization = Discourse.Model.extend({
|
|
|
|
trackedProperties: ['enabled', 'name', 'stylesheet', 'header', 'override_default_style'],
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
init: function() {
|
|
|
|
this._super();
|
|
|
|
return this.startTrackingChanges();
|
|
|
|
},
|
2013-03-05 15:39:21 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
description: (function() {
|
|
|
|
return "" + this.name + (this.enabled ? ' (*)' : '');
|
|
|
|
}).property('selected', 'name'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
changed: (function() {
|
|
|
|
var _this = this;
|
|
|
|
if (!this.originals) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.trackedProperties.any(function(p) {
|
|
|
|
return _this.originals[p] !== _this.get(p);
|
|
|
|
});
|
|
|
|
}).property('override_default_style', 'enabled', 'name', 'stylesheet', 'header', 'originals'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
startTrackingChanges: function() {
|
|
|
|
var _this = this;
|
|
|
|
this.set('originals', {});
|
|
|
|
return this.trackedProperties.each(function(p) {
|
|
|
|
_this.originals[p] = _this.get(p);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
},
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
previewUrl: (function() {
|
|
|
|
return "/?preview-style=" + (this.get('key'));
|
|
|
|
}).property('key'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
disableSave: (function() {
|
|
|
|
return !this.get('changed');
|
|
|
|
}).property('changed'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
save: function() {
|
|
|
|
var data;
|
|
|
|
this.startTrackingChanges();
|
|
|
|
data = {
|
|
|
|
name: this.name,
|
|
|
|
enabled: this.enabled,
|
|
|
|
stylesheet: this.stylesheet,
|
|
|
|
header: this.header,
|
|
|
|
override_default_style: this.override_default_style
|
|
|
|
};
|
2013-03-05 15:39:21 -05:00
|
|
|
return $.ajax({
|
2013-02-22 15:41:12 -05:00
|
|
|
url: "/admin/site_customizations" + (this.id ? '/' + this.id : ''),
|
|
|
|
data: {
|
|
|
|
site_customization: data
|
|
|
|
},
|
|
|
|
type: this.id ? 'PUT' : 'POST'
|
|
|
|
});
|
|
|
|
},
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
"delete": function() {
|
|
|
|
if (!this.id) return;
|
2013-03-05 15:39:21 -05:00
|
|
|
|
|
|
|
return $.ajax({
|
2013-02-22 15:41:12 -05:00
|
|
|
url: "/admin/site_customizations/" + this.id,
|
|
|
|
type: 'DELETE'
|
|
|
|
});
|
|
|
|
}
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
var SiteCustomizations = Ember.ArrayProxy.extend({
|
|
|
|
selectedItemChanged: (function() {
|
|
|
|
var selected;
|
|
|
|
selected = this.get('selectedItem');
|
|
|
|
return this.get('content').each(function(i) {
|
|
|
|
return i.set('selected', selected === i);
|
|
|
|
});
|
|
|
|
}).observes('selectedItem')
|
|
|
|
});
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
Discourse.SiteCustomization.reopenClass({
|
|
|
|
findAll: function() {
|
|
|
|
var content,
|
|
|
|
_this = this;
|
|
|
|
content = SiteCustomizations.create({
|
|
|
|
content: [],
|
|
|
|
loading: true
|
|
|
|
});
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax({
|
2013-02-22 15:41:12 -05:00
|
|
|
url: "/admin/site_customizations",
|
|
|
|
dataType: "json",
|
|
|
|
success: function(data) {
|
|
|
|
if (data) {
|
|
|
|
data.site_customizations.each(function(c) {
|
|
|
|
var item;
|
|
|
|
item = Discourse.SiteCustomization.create(c);
|
|
|
|
return content.pushObject(item);
|
|
|
|
});
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
return content.set('loading', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
});
|