Cleaned up JS, added basic documentation support for Admin Controllers

This commit is contained in:
Robin Ward 2013-02-21 12:58:21 -05:00
parent 6096a447b7
commit 13f8f3c45e
9 changed files with 101 additions and 72 deletions

View File

@ -1,25 +1,30 @@
(function() { (function() {
/**
This controller supports interface for creating custom CSS skins in Discourse.
@class AdminCustomizeController
@extends Ember.Controller
@namespace Discourse
@module Discourse
**/
window.Discourse.AdminCustomizeController = Ember.Controller.extend({ window.Discourse.AdminCustomizeController = Ember.Controller.extend({
newCustomization: function() { newCustomization: function() {
var item; var item = Discourse.SiteCustomization.create({name: 'New Style'});
item = Discourse.SiteCustomization.create({
name: 'New Style'
});
this.get('content').pushObject(item); this.get('content').pushObject(item);
return this.set('content.selectedItem', item); this.set('content.selectedItem', item);
}, },
selectStyle: function(style) { selectStyle: function(style) {
return this.set('content.selectedItem', style); this.set('content.selectedItem', style);
}, },
save: function() { save: function() {
return this.get('content.selectedItem').save(); this.get('content.selectedItem').save();
}, },
"delete": function() { destroy: function() {
var _this = this; var _this = this;
return bootbox.confirm(Em.String.i18n("admin.customize.delete_confirm"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) { return bootbox.confirm(Em.String.i18n("admin.customize.delete_confirm"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) {
var selected; var selected;

View File

@ -1,5 +1,13 @@
(function() { (function() {
/**
This controller supports the default interface when you enter the admin section.
@class AdminDashboardController
@extends Ember.Controller
@namespace Discourse
@module Discourse
**/
window.Discourse.AdminDashboardController = Ember.Controller.extend({ window.Discourse.AdminDashboardController = Ember.Controller.extend({
loading: true, loading: true,
versionCheck: null, versionCheck: null,
@ -7,9 +15,8 @@
upToDate: (function() { upToDate: (function() {
if (this.versionCheck) { if (this.versionCheck) {
return this.versionCheck.latest_version === this.versionCheck.installed_version; return this.versionCheck.latest_version === this.versionCheck.installed_version;
} else {
return true;
} }
return true;
}).property('versionCheck'), }).property('versionCheck'),
updateIconClasses: (function() { updateIconClasses: (function() {
@ -26,9 +33,8 @@
priorityClass: (function() { priorityClass: (function() {
if (this.get('versionCheck.critical_updates')) { if (this.get('versionCheck.critical_updates')) {
return 'version-check critical'; return 'version-check critical';
} else {
return 'version-check normal';
} }
return 'version-check normal';
}).property('versionCheck') }).property('versionCheck')
}); });

View File

@ -1,5 +1,13 @@
(function() { (function() {
/**
This controller supports the interface for reviewing email logs.
@class AdminEmailLogsController
@extends Ember.ArrayController
@namespace Discourse
@module Discourse
**/
window.Discourse.AdminEmailLogsController = Ember.ArrayController.extend(Discourse.Presence, { window.Discourse.AdminEmailLogsController = Ember.ArrayController.extend(Discourse.Presence, {
sendTestEmailDisabled: (function() { sendTestEmailDisabled: (function() {
@ -8,13 +16,11 @@
sendTestEmail: function() { sendTestEmail: function() {
var _this = this; var _this = this;
this.set('sentTestEmail', false); _this.set('sentTestEmail', false);
jQuery.ajax({ jQuery.ajax({
url: '/admin/email_logs/test', url: '/admin/email_logs/test',
type: 'POST', type: 'POST',
data: { data: { email_address: this.get('testEmailAddress') },
email_address: this.get('testEmailAddress')
},
success: function() { success: function() {
return _this.set('sentTestEmail', true); return _this.set('sentTestEmail', true);
} }

View File

@ -1,22 +1,30 @@
(function() { (function() {
/**
This controller supports the interface for dealing with flags in the admin section.
@class AdminFlagsController
@extends Ember.Controller
@namespace Discourse
@module Discourse
**/
window.Discourse.AdminFlagsController = Ember.Controller.extend({ window.Discourse.AdminFlagsController = Ember.Controller.extend({
clearFlags: function(item) { clearFlags: function(item) {
var _this = this; var _this = this;
return item.clearFlags().then((function() { item.clearFlags().then((function() {
return _this.content.removeObject(item); _this.content.removeObject(item);
}), (function() { }), (function() {
return bootbox.alert("something went wrong"); bootbox.alert("something went wrong");
})); }));
}, },
deletePost: function(item) { deletePost: function(item) {
var _this = this; var _this = this;
return item.deletePost().then((function() { item.deletePost().then((function() {
return _this.content.removeObject(item); _this.content.removeObject(item);
}), (function() { }), (function() {
return bootbox.alert("something went wrong"); bootbox.alert("something went wrong");
})); }));
}, },

View File

@ -1,5 +1,13 @@
(function() { (function() {
/**
This controller supports the interface for SiteSettings.
@class AdminSiteSettingsController
@extends Ember.ArrayController
@namespace Discourse
@module Discourse
**/
window.Discourse.AdminSiteSettingsController = Ember.ArrayController.extend(Discourse.Presence, { window.Discourse.AdminSiteSettingsController = Ember.ArrayController.extend(Discourse.Presence, {
filter: null, filter: null,
onlyOverridden: false, onlyOverridden: false,
@ -7,44 +15,35 @@
filteredContent: (function() { filteredContent: (function() {
var filter, var filter,
_this = this; _this = this;
if (!this.present('content')) { if (!this.present('content')) return null;
return null;
}
if (this.get('filter')) { if (this.get('filter')) {
filter = this.get('filter').toLowerCase(); filter = this.get('filter').toLowerCase();
} }
return this.get('content').filter(function(item, index, enumerable) { return this.get('content').filter(function(item, index, enumerable) {
if (_this.get('onlyOverridden') && !item.get('overridden')) { if (_this.get('onlyOverridden') && !item.get('overridden')) return false;
return false;
}
if (filter) { if (filter) {
if (item.get('setting').toLowerCase().indexOf(filter) > -1) { if (item.get('setting').toLowerCase().indexOf(filter) > -1) return true;
return true; if (item.get('description').toLowerCase().indexOf(filter) > -1) return true;
} if (item.get('value').toLowerCase().indexOf(filter) > -1) return true;
if (item.get('description').toLowerCase().indexOf(filter) > -1) {
return true;
}
if (item.get('value').toLowerCase().indexOf(filter) > -1) {
return true;
}
return false; return false;
} else {
return true;
} }
return true;
}); });
}).property('filter', 'content.@each', 'onlyOverridden'), }).property('filter', 'content.@each', 'onlyOverridden'),
resetDefault: function(setting) { resetDefault: function(setting) {
setting.set('value', setting.get('default')); setting.set('value', setting.get('default'));
return setting.save(); setting.save();
}, },
save: function(setting) { save: function(setting) {
return setting.save(); setting.save();
}, },
cancel: function(setting) { cancel: function(setting) {
return setting.resetValue(); setting.resetValue();
} }
}); });

View File

@ -1,5 +1,13 @@
(function() { (function() {
/**
This controller supports the interface for listing users in the admin section.
@class AdminUsersListController
@extends Ember.ArrayController
@namespace Discourse
@module Discourse
**/
window.Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Presence, { window.Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Presence, {
username: null, username: null,
query: null, query: null,
@ -8,35 +16,27 @@
selectAllChanged: (function() { selectAllChanged: (function() {
var _this = this; var _this = this;
return this.get('content').each(function(user) { this.get('content').each(function(user) {
return user.set('selected', _this.get('selectAll')); user.set('selected', _this.get('selectAll'));
}); });
}).observes('selectAll'), }).observes('selectAll'),
filterUsers: Discourse.debounce(function() { filterUsers: Discourse.debounce(function() {
return this.refreshUsers(); this.refreshUsers();
}, 250).observes('username'), }, 250).observes('username'),
orderChanged: (function() { orderChanged: (function() {
return this.refreshUsers(); this.refreshUsers();
}).observes('query'), }).observes('query'),
showApproval: (function() { showApproval: (function() {
if (!Discourse.SiteSettings.must_approve_users) { if (!Discourse.SiteSettings.must_approve_users) return false;
return false; if (this.get('query') === 'new') return true;
} if (this.get('query') === 'pending') return true;
if (this.get('query') === 'new') {
return true;
}
if (this.get('query') === 'pending') {
return true;
}
}).property('query'), }).property('query'),
selectedCount: (function() { selectedCount: (function() {
if (this.blank('content')) { if (this.blank('content')) return 0;
return 0;
}
return this.get('content').filterProperty('selected').length; return this.get('content').filterProperty('selected').length;
}).property('content.@each.selected'), }).property('content.@each.selected'),
@ -45,19 +45,20 @@
}).property('selectedCount'), }).property('selectedCount'),
refreshUsers: function() { refreshUsers: function() {
return this.set('content', Discourse.AdminUser.findAll(this.get('query'), this.get('username'))); this.set('content', Discourse.AdminUser.findAll(this.get('query'), this.get('username')));
}, },
show: function(term) { show: function(term) {
if (this.get('query') === term) { if (this.get('query') === term) {
return this.refreshUsers(); this.refreshUsers();
} else { return;
return this.set('query', term);
} }
this.set('query', term);
}, },
approveUsers: function() { approveUsers: function() {
return Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected')); Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected'));
} }
}); });

View File

@ -1,11 +1,6 @@
(function() { (function() {
window.Discourse.VersionCheck = Discourse.Model.extend({ window.Discourse.VersionCheck = Discourse.Model.extend({});
hasInstalledSha: function() {
console.log( 'hello??' );
return( this.get('installed_sha') && this.get('installed_sha') != 'unknown' );
}.property('installed_sha')
});
Discourse.VersionCheck.reopenClass({ Discourse.VersionCheck.reopenClass({
find: function() { find: function() {

View File

@ -46,7 +46,7 @@
<div class='buttons'> <div class='buttons'>
<button {{action save target="controller"}} {{bindAttr disabled="content.selectedItem.disableSave"}} class='btn btn-primary'>{{i18n admin.customize.save}}</button> <button {{action save target="controller"}} {{bindAttr disabled="content.selectedItem.disableSave"}} class='btn btn-primary'>{{i18n admin.customize.save}}</button>
<a {{action delete target="controller"}} class='delete-link'>{{i18n admin.customize.delete}}</a> <a {{action destroy target="controller"}} class='delete-link'>{{i18n admin.customize.delete}}</a>
<span class='saving'>{{content.savingStatus}}</span> <span class='saving'>{{content.savingStatus}}</span>
</div> </div>

View File

@ -0,0 +1,9 @@
{
"name": "Discourse Client",
"description": "This is the EmberJS client to access a Discourse Server",
"url": "http://www.discourse.org/",
"options": {
"exclude": "external,external_production",
"outdir": "./build"
}
}