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();
|
2013-05-06 14:20:20 -04:00
|
|
|
this.startTrackingChanges();
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
2013-03-05 15:39:21 -05:00
|
|
|
|
2013-04-04 12:59:44 -04:00
|
|
|
description: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
return "" + this.name + (this.enabled ? ' (*)' : '');
|
2013-04-04 12:59:44 -04:00
|
|
|
}.property('selected', 'name'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-04 12:59:44 -04:00
|
|
|
changed: function() {
|
2013-04-10 01:55:20 -04:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
var _this = this;
|
2013-04-10 01:55:20 -04:00
|
|
|
if(!this.originals) return false;
|
|
|
|
|
|
|
|
var changed = this.trackedProperties.any(function(p) {
|
2013-02-22 15:41:12 -05:00
|
|
|
return _this.originals[p] !== _this.get(p);
|
|
|
|
});
|
2013-04-10 01:55:20 -04:00
|
|
|
|
|
|
|
if(changed){
|
|
|
|
this.set('savingStatus','');
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
|
2013-04-04 12:59:44 -04:00
|
|
|
}.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;
|
2013-04-10 01:55:20 -04:00
|
|
|
var originals = {};
|
|
|
|
this.trackedProperties.each(function(p) {
|
|
|
|
originals[p] = _this.get(p);
|
2013-02-22 15:41:12 -05:00
|
|
|
return true;
|
|
|
|
});
|
2013-04-10 01:55:20 -04:00
|
|
|
this.set('originals', originals);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-04 12:59:44 -04:00
|
|
|
previewUrl: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
return "/?preview-style=" + (this.get('key'));
|
2013-04-04 12:59:44 -04:00
|
|
|
}.property('key'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-04 12:59:44 -04:00
|
|
|
disableSave: function() {
|
2013-04-10 01:55:20 -04:00
|
|
|
return !this.get('changed') || this.get('saving');
|
2013-04-04 12:59:44 -04:00
|
|
|
}.property('changed'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-10 01:55:20 -04:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
save: function() {
|
2013-04-10 01:55:20 -04:00
|
|
|
this.set('savingStatus', Em.String.i18n('saving'));
|
|
|
|
this.set('saving',true);
|
2013-04-04 12:59:44 -04:00
|
|
|
var data = {
|
2013-02-22 15:41:12 -05:00
|
|
|
name: this.name,
|
|
|
|
enabled: this.enabled,
|
|
|
|
stylesheet: this.stylesheet,
|
|
|
|
header: this.header,
|
|
|
|
override_default_style: this.override_default_style
|
|
|
|
};
|
2013-05-06 14:20:20 -04:00
|
|
|
|
|
|
|
var siteCustomization = this;
|
2013-04-01 16:28:26 -04:00
|
|
|
return Discourse.ajax({
|
2013-03-14 08:01:52 -04:00
|
|
|
url: Discourse.getURL("/admin/site_customizations") + (this.id ? '/' + this.id : ''),
|
2013-05-06 14:20:20 -04:00
|
|
|
data: { site_customization: data },
|
|
|
|
type: this.id ? 'PUT' : 'POST'
|
|
|
|
}).then(function (result) {
|
|
|
|
if (!siteCustomization.id) { siteCustomization.set('id', result.id); }
|
|
|
|
siteCustomization.set('savingStatus', Em.String.i18n('saved'));
|
|
|
|
siteCustomization.set('saving',false);
|
|
|
|
siteCustomization.startTrackingChanges();
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
2013-05-06 14:20:20 -04:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-03-21 15:10:34 -04:00
|
|
|
destroy: function() {
|
2013-04-10 01:55:20 -04:00
|
|
|
if(!this.id) return;
|
2013-04-01 16:28:26 -04:00
|
|
|
return Discourse.ajax({
|
2013-03-14 08:01:52 -04:00
|
|
|
url: Discourse.getURL("/admin/site_customizations/") + this.id,
|
2013-02-22 15:41:12 -05:00
|
|
|
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({
|
2013-04-04 12:59:44 -04:00
|
|
|
selectedItemChanged: function() {
|
|
|
|
var selected = this.get('selectedItem');
|
2013-02-22 15:41:12 -05:00
|
|
|
return this.get('content').each(function(i) {
|
|
|
|
return i.set('selected', selected === i);
|
|
|
|
});
|
2013-04-04 12:59:44 -04:00
|
|
|
}.observes('selectedItem')
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
Discourse.SiteCustomization.reopenClass({
|
|
|
|
findAll: function() {
|
2013-04-03 16:06:55 -04:00
|
|
|
var customizations = SiteCustomizations.create({ content: [], loading: true });
|
2013-04-01 16:28:26 -04:00
|
|
|
Discourse.ajax({
|
2013-03-14 08:01:52 -04:00
|
|
|
url: Discourse.getURL("/admin/site_customizations"),
|
2013-04-03 16:06:55 -04:00
|
|
|
dataType: "json"
|
|
|
|
}).then(function (data) {
|
|
|
|
if (data) {
|
|
|
|
data.site_customizations.each(function(c) {
|
2013-04-30 00:01:34 -04:00
|
|
|
customizations.pushObject(Discourse.SiteCustomization.create(c.site_customizations));
|
2013-04-03 16:06:55 -04:00
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
2013-04-03 16:06:55 -04:00
|
|
|
customizations.set('loading', false);
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
2013-04-03 16:06:55 -04:00
|
|
|
return customizations;
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
});
|