Work in Progress: Content Editing in Admin Section
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
Our data model for interacting with custom site content
|
||||
|
||||
@class SiteContent
|
||||
@extends Discourse.Model
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.SiteContent = Discourse.Model.extend({
|
||||
|
||||
markdown: Ember.computed.equal('format', 'markdown'),
|
||||
plainText: Ember.computed.equal('format', 'plain'),
|
||||
html: Ember.computed.equal('format', 'html'),
|
||||
css: Ember.computed.equal('format', 'css'),
|
||||
|
||||
/**
|
||||
Save the content
|
||||
|
||||
@method save
|
||||
@return {jqXHR} a jQuery Promise object
|
||||
**/
|
||||
save: function() {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/site_contents/" + this.get('content_type')), {
|
||||
type: 'PUT',
|
||||
data: {content: this.get('content')}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Discourse.SiteContent.reopenClass({
|
||||
|
||||
find: function(type) {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/site_contents/" + type)).then(function (data) {
|
||||
return Discourse.SiteContent.create(data.site_content);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
Our data model that represents types of editing site content
|
||||
|
||||
@class SiteContentType
|
||||
@extends Discourse.Model
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.SiteContentType = Discourse.Model.extend({});
|
||||
|
||||
Discourse.SiteContentType.reopenClass({
|
||||
findAll: function() {
|
||||
var contentTypes = Em.A();
|
||||
Discourse.ajax(Discourse.getURL("/admin/site_content_types")).then(function(data) {
|
||||
data.forEach(function (ct) {
|
||||
contentTypes.pushObject(Discourse.SiteContentType.create(ct));
|
||||
});
|
||||
});
|
||||
return contentTypes;
|
||||
}
|
||||
});
|
||||
@@ -14,19 +14,17 @@ Discourse.SiteCustomization = Discourse.Model.extend({
|
||||
return this.startTrackingChanges();
|
||||
},
|
||||
|
||||
description: (function() {
|
||||
description: function() {
|
||||
return "" + this.name + (this.enabled ? ' (*)' : '');
|
||||
}).property('selected', 'name'),
|
||||
}.property('selected', 'name'),
|
||||
|
||||
changed: (function() {
|
||||
changed: function() {
|
||||
var _this = this;
|
||||
if (!this.originals) {
|
||||
return false;
|
||||
}
|
||||
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'),
|
||||
}.property('override_default_style', 'enabled', 'name', 'stylesheet', 'header', 'originals'),
|
||||
|
||||
startTrackingChanges: function() {
|
||||
var _this = this;
|
||||
@@ -37,18 +35,17 @@ Discourse.SiteCustomization = Discourse.Model.extend({
|
||||
});
|
||||
},
|
||||
|
||||
previewUrl: (function() {
|
||||
previewUrl: function() {
|
||||
return "/?preview-style=" + (this.get('key'));
|
||||
}).property('key'),
|
||||
}.property('key'),
|
||||
|
||||
disableSave: (function() {
|
||||
disableSave: function() {
|
||||
return !this.get('changed');
|
||||
}).property('changed'),
|
||||
}.property('changed'),
|
||||
|
||||
save: function() {
|
||||
var data;
|
||||
this.startTrackingChanges();
|
||||
data = {
|
||||
var data = {
|
||||
name: this.name,
|
||||
enabled: this.enabled,
|
||||
stylesheet: this.stylesheet,
|
||||
@@ -66,7 +63,6 @@ Discourse.SiteCustomization = Discourse.Model.extend({
|
||||
|
||||
destroy: function() {
|
||||
if (!this.id) return;
|
||||
|
||||
return Discourse.ajax({
|
||||
url: Discourse.getURL("/admin/site_customizations/") + this.id,
|
||||
type: 'DELETE'
|
||||
@@ -76,13 +72,12 @@ Discourse.SiteCustomization = Discourse.Model.extend({
|
||||
});
|
||||
|
||||
var SiteCustomizations = Ember.ArrayProxy.extend({
|
||||
selectedItemChanged: (function() {
|
||||
var selected;
|
||||
selected = this.get('selectedItem');
|
||||
selectedItemChanged: function() {
|
||||
var selected = this.get('selectedItem');
|
||||
return this.get('content').each(function(i) {
|
||||
return i.set('selected', selected === i);
|
||||
});
|
||||
}).observes('selectedItem')
|
||||
}.observes('selectedItem')
|
||||
});
|
||||
|
||||
Discourse.SiteCustomization.reopenClass({
|
||||
|
||||
Reference in New Issue
Block a user