diff --git a/app/assets/javascripts/admin/controllers/admin_customize_controller.js b/app/assets/javascripts/admin/controllers/admin_customize_controller.js index dfa0fb9054b..ca5ad7f731f 100644 --- a/app/assets/javascripts/admin/controllers/admin_customize_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_customize_controller.js @@ -1,63 +1,59 @@ -(function() { +/** + This controller supports interface for creating custom CSS skins in Discourse. + + @class AdminCustomizeController + @extends Ember.Controller + @namespace Discourse + @module Discourse +**/ +Discourse.AdminCustomizeController = Ember.Controller.extend({ /** - This controller supports interface for creating custom CSS skins in Discourse. + Create a new customization style - @class AdminCustomizeController - @extends Ember.Controller - @namespace Discourse - @module Discourse - **/ - window.Discourse.AdminCustomizeController = Ember.Controller.extend({ + @method newCustomization + **/ + newCustomization: function() { + var item = Discourse.SiteCustomization.create({name: 'New Style'}); + this.get('content').pushObject(item); + this.set('content.selectedItem', item); + }, - /** - Create a new customization style + /** + Select a given style - @method newCustomization - **/ - newCustomization: function() { - var item = Discourse.SiteCustomization.create({name: 'New Style'}); - this.get('content').pushObject(item); - this.set('content.selectedItem', item); - }, + @method selectStyle + @param {Discourse.SiteCustomization} style The style we are selecting + **/ + selectStyle: function(style) { + this.set('content.selectedItem', style); + }, - /** - Select a given style + /** + Save the current customization - @method selectStyle - @param {Discourse.SiteCustomization} style The style we are selecting - **/ - selectStyle: function(style) { - this.set('content.selectedItem', style); - }, + @method save + **/ + save: function() { + this.get('content.selectedItem').save(); + }, - /** - Save the current customization + /** + Destroy the current customization - @method save - **/ - save: function() { - this.get('content.selectedItem').save(); - }, + @method destroy + **/ + destroy: function() { + 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) { + var selected; + if (result) { + selected = _this.get('content.selectedItem'); + selected["delete"](); + _this.set('content.selectedItem', null); + return _this.get('content').removeObject(selected); + } + }); + } - /** - Destroy the current customization - - @method destroy - **/ - destroy: function() { - 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) { - var selected; - if (result) { - selected = _this.get('content.selectedItem'); - selected["delete"](); - _this.set('content.selectedItem', null); - return _this.get('content').removeObject(selected); - } - }); - } - - }); - -}).call(this); +}); diff --git a/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js b/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js index 5c00923dcb9..8ec0442a3ba 100644 --- a/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js @@ -1,16 +1,12 @@ -(function() { +/** + This controller supports the default interface when you enter the admin section. - /** - 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({ - loading: true, - versionCheck: null - }); - -}).call(this); + @class AdminDashboardController + @extends Ember.Controller + @namespace Discourse + @module Discourse +**/ +Discourse.AdminDashboardController = Ember.Controller.extend({ + loading: true, + versionCheck: null +}); diff --git a/app/assets/javascripts/admin/controllers/admin_email_logs_controller.js b/app/assets/javascripts/admin/controllers/admin_email_logs_controller.js index fbe31fed562..ef088cbaa23 100644 --- a/app/assets/javascripts/admin/controllers/admin_email_logs_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_email_logs_controller.js @@ -1,43 +1,39 @@ -(function() { +/** + This controller supports the interface for reviewing email logs. + + @class AdminEmailLogsController + @extends Ember.ArrayController + @namespace Discourse + @module Discourse +**/ +Discourse.AdminEmailLogsController = Ember.ArrayController.extend(Discourse.Presence, { + + /** + Is the "send test email" button disabled? + + @property sendTestEmailDisabled + **/ + sendTestEmailDisabled: (function() { + return this.blank('testEmailAddress'); + }).property('testEmailAddress'), /** - This controller supports the interface for reviewing email logs. + Sends a test email to the currently entered email address - @class AdminEmailLogsController - @extends Ember.ArrayController - @namespace Discourse - @module Discourse - **/ - window.Discourse.AdminEmailLogsController = Ember.ArrayController.extend(Discourse.Presence, { - - /** - Is the "send test email" button disabled? - - @property sendTestEmailDisabled - **/ - sendTestEmailDisabled: (function() { - return this.blank('testEmailAddress'); - }).property('testEmailAddress'), - - /** - Sends a test email to the currently entered email address - - @method sendTestEmail - **/ - sendTestEmail: function() { - var _this = this; - _this.set('sentTestEmail', false); - jQuery.ajax({ - url: '/admin/email_logs/test', - type: 'POST', - data: { email_address: this.get('testEmailAddress') }, - success: function() { - return _this.set('sentTestEmail', true); - } - }); - return false; - } - - }); - -}).call(this); + @method sendTestEmail + **/ + sendTestEmail: function() { + var _this = this; + _this.set('sentTestEmail', false); + jQuery.ajax({ + url: '/admin/email_logs/test', + type: 'POST', + data: { email_address: this.get('testEmailAddress') }, + success: function() { + return _this.set('sentTestEmail', true); + } + }); + return false; + } + +}); diff --git a/app/assets/javascripts/admin/controllers/admin_flags_controller.js b/app/assets/javascripts/admin/controllers/admin_flags_controller.js index a3a6107ed3f..8663e347329 100644 --- a/app/assets/javascripts/admin/controllers/admin_flags_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_flags_controller.js @@ -1,63 +1,59 @@ -(function() { +/** + This controller supports the interface for dealing with flags in the admin section. + + @class AdminFlagsController + @extends Ember.Controller + @namespace Discourse + @module Discourse +**/ +Discourse.AdminFlagsController = Ember.Controller.extend({ + + /** + Clear all flags on a post + + @method clearFlags + @param {Discourse.FlaggedPost} item The post whose flags we want to clear + **/ + clearFlags: function(item) { + var _this = this; + item.clearFlags().then((function() { + _this.content.removeObject(item); + }), (function() { + bootbox.alert("something went wrong"); + })); + }, /** - This controller supports the interface for dealing with flags in the admin section. + Deletes a post - @class AdminFlagsController - @extends Ember.Controller - @namespace Discourse - @module Discourse - **/ - window.Discourse.AdminFlagsController = Ember.Controller.extend({ - - /** - Clear all flags on a post + @method deletePost + @param {Discourse.FlaggedPost} item The post to delete + **/ + deletePost: function(item) { + var _this = this; + item.deletePost().then((function() { + _this.content.removeObject(item); + }), (function() { + bootbox.alert("something went wrong"); + })); + }, - @method clearFlags - @param {Discourse.FlaggedPost} item The post whose flags we want to clear - **/ - clearFlags: function(item) { - var _this = this; - item.clearFlags().then((function() { - _this.content.removeObject(item); - }), (function() { - bootbox.alert("something went wrong"); - })); - }, + /** + Are we viewing the 'old' view? - /** - Deletes a post + @property adminOldFlagsView + **/ + adminOldFlagsView: (function() { + return this.query === 'old'; + }).property('query'), - @method deletePost - @param {Discourse.FlaggedPost} item The post to delete - **/ - deletePost: function(item) { - var _this = this; - item.deletePost().then((function() { - _this.content.removeObject(item); - }), (function() { - bootbox.alert("something went wrong"); - })); - }, + /** + Are we viewing the 'active' view? - /** - Are we viewing the 'old' view? - - @property adminOldFlagsView - **/ - adminOldFlagsView: (function() { - return this.query === 'old'; - }).property('query'), - - /** - Are we viewing the 'active' view? - - @property adminActiveFlagsView - **/ - adminActiveFlagsView: (function() { - return this.query === 'active'; - }).property('query') - - }); - -}).call(this); + @property adminActiveFlagsView + **/ + adminActiveFlagsView: (function() { + return this.query === 'active'; + }).property('query') + +}); diff --git a/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js b/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js index da618df7895..3891f72aa8e 100644 --- a/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js @@ -1,74 +1,70 @@ -(function() { +/** + This controller supports the interface for SiteSettings. + + @class AdminSiteSettingsController + @extends Ember.ArrayController + @namespace Discourse + @module Discourse +**/ +Discourse.AdminSiteSettingsController = Ember.ArrayController.extend(Discourse.Presence, { + filter: null, + onlyOverridden: false, /** - This controller supports the interface for SiteSettings. + The list of settings based on the current filters - @class AdminSiteSettingsController - @extends Ember.ArrayController - @namespace Discourse - @module Discourse - **/ - window.Discourse.AdminSiteSettingsController = Ember.ArrayController.extend(Discourse.Presence, { - filter: null, - onlyOverridden: false, + @property filteredContent + **/ + filteredContent: (function() { + var filter, + _this = this; + if (!this.present('content')) return null; + if (this.get('filter')) { + filter = this.get('filter').toLowerCase(); + } - /** - The list of settings based on the current filters - - @property filteredContent - **/ - filteredContent: (function() { - var filter, - _this = this; - if (!this.present('content')) return null; - if (this.get('filter')) { - filter = this.get('filter').toLowerCase(); + return this.get('content').filter(function(item, index, enumerable) { + if (_this.get('onlyOverridden') && !item.get('overridden')) return false; + if (filter) { + if (item.get('setting').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 this.get('content').filter(function(item, index, enumerable) { - if (_this.get('onlyOverridden') && !item.get('overridden')) return false; - if (filter) { - if (item.get('setting').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 true; + }); + }).property('filter', 'content.@each', 'onlyOverridden'), - return true; - }); - }).property('filter', 'content.@each', 'onlyOverridden'), + /** + Reset a setting to its default value - /** - Reset a setting to its default value + @method resetDefault + @param {Discourse.SiteSetting} setting The setting we want to revert + **/ + resetDefault: function(setting) { + setting.set('value', setting.get('default')); + setting.save(); + }, - @method resetDefault - @param {Discourse.SiteSetting} setting The setting we want to revert - **/ - resetDefault: function(setting) { - setting.set('value', setting.get('default')); - setting.save(); - }, + /** + Save changes to a site setting - /** - Save changes to a site setting + @method save + @param {Discourse.SiteSetting} setting The setting we've changed + **/ + save: function(setting) { + setting.save(); + }, - @method save - @param {Discourse.SiteSetting} setting The setting we've changed - **/ - save: function(setting) { - setting.save(); - }, + /** + Cancel changes to a site setting - /** - Cancel changes to a site setting - - @method cancel - @param {Discourse.SiteSetting} setting The setting we've changed but want to revert - **/ - cancel: function(setting) { - setting.resetValue(); - } - - }); - -}).call(this); + @method cancel + @param {Discourse.SiteSetting} setting The setting we've changed but want to revert + **/ + cancel: function(setting) { + setting.resetValue(); + } + +}); diff --git a/app/assets/javascripts/admin/controllers/admin_users_list_controller.js b/app/assets/javascripts/admin/controllers/admin_users_list_controller.js index 535602a60da..f9c40a79d7d 100644 --- a/app/assets/javascripts/admin/controllers/admin_users_list_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_users_list_controller.js @@ -1,111 +1,107 @@ -(function() { +/** + This controller supports the interface for listing users in the admin section. + + @class AdminUsersListController + @extends Ember.ArrayController + @namespace Discourse + @module Discourse +**/ +Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Presence, { + username: null, + query: null, + selectAll: false, + content: null, /** - This controller supports the interface for listing users in the admin section. + Triggered when the selectAll property is changed - @class AdminUsersListController - @extends Ember.ArrayController - @namespace Discourse - @module Discourse - **/ - window.Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Presence, { - username: null, - query: null, - selectAll: false, - content: null, + @event selectAll + **/ + selectAllChanged: (function() { + var _this = this; + this.get('content').each(function(user) { + user.set('selected', _this.get('selectAll')); + }); + }).observes('selectAll'), - /** - Triggered when the selectAll property is changed + /** + Triggered when the username filter is changed - @event selectAll - **/ - selectAllChanged: (function() { - var _this = this; - this.get('content').each(function(user) { - user.set('selected', _this.get('selectAll')); - }); - }).observes('selectAll'), + @event filterUsers + **/ + filterUsers: Discourse.debounce(function() { + this.refreshUsers(); + }, 250).observes('username'), - /** - Triggered when the username filter is changed + /** + Triggered when the order of the users list is changed - @event filterUsers - **/ - filterUsers: Discourse.debounce(function() { + @event orderChanged + **/ + orderChanged: (function() { + this.refreshUsers(); + }).observes('query'), + + /** + Do we want to show the approval controls? + + @property showApproval + **/ + showApproval: (function() { + if (!Discourse.SiteSettings.must_approve_users) return false; + if (this.get('query') === 'new') return true; + if (this.get('query') === 'pending') return true; + }).property('query'), + + /** + How many users are currently selected + + @property selectedCount + **/ + selectedCount: (function() { + if (this.blank('content')) return 0; + return this.get('content').filterProperty('selected').length; + }).property('content.@each.selected'), + + /** + Do we have any selected users? + + @property hasSelection + **/ + hasSelection: (function() { + return this.get('selectedCount') > 0; + }).property('selectedCount'), + + /** + Refresh the current list of users. + + @method refreshUsers + **/ + refreshUsers: function() { + this.set('content', Discourse.AdminUser.findAll(this.get('query'), this.get('username'))); + }, + + + /** + Show the list of users. + + @method show + **/ + show: function(term) { + if (this.get('query') === term) { this.refreshUsers(); - }, 250).observes('username'), - - /** - Triggered when the order of the users list is changed - - @event orderChanged - **/ - orderChanged: (function() { - this.refreshUsers(); - }).observes('query'), - - /** - Do we want to show the approval controls? - - @property showApproval - **/ - showApproval: (function() { - if (!Discourse.SiteSettings.must_approve_users) return false; - if (this.get('query') === 'new') return true; - if (this.get('query') === 'pending') return true; - }).property('query'), - - /** - How many users are currently selected - - @property selectedCount - **/ - selectedCount: (function() { - if (this.blank('content')) return 0; - return this.get('content').filterProperty('selected').length; - }).property('content.@each.selected'), - - /** - Do we have any selected users? - - @property hasSelection - **/ - hasSelection: (function() { - return this.get('selectedCount') > 0; - }).property('selectedCount'), - - /** - Refresh the current list of users. - - @method refreshUsers - **/ - refreshUsers: function() { - this.set('content', Discourse.AdminUser.findAll(this.get('query'), this.get('username'))); - }, - - - /** - Show the list of users. - - @method show - **/ - show: function(term) { - if (this.get('query') === term) { - this.refreshUsers(); - return; - } - this.set('query', term); - }, - - /** - Approve all the currently selected users. - - @method approveUsers - **/ - approveUsers: function() { - Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected')); + return; } - - }); + this.set('query', term); + }, -}).call(this); + /** + Approve all the currently selected users. + + @method approveUsers + **/ + approveUsers: function() { + Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected')); + } + +}); diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index fdc69957ec9..2886f927827 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -1,190 +1,186 @@ -(function() { +/** + Our data model for dealing with users from the admin section. - /** - Our data model for dealing with users from the admin section. + @class AdminUser + @extends Discourse.Model + @namespace Discourse + @module Discourse +**/ +Discourse.AdminUser = Discourse.Model.extend({ + + deleteAllPosts: function() { + this.set('can_delete_all_posts', false); + jQuery.ajax("/admin/users/" + (this.get('id')) + "/delete_all_posts", {type: 'PUT'}); + }, - @class AdminUser - @extends Discourse.Model - @namespace Discourse - @module Discourse - **/ - window.Discourse.AdminUser = Discourse.Model.extend({ - - deleteAllPosts: function() { - this.set('can_delete_all_posts', false); - jQuery.ajax("/admin/users/" + (this.get('id')) + "/delete_all_posts", {type: 'PUT'}); - }, + // Revoke the user's admin access + revokeAdmin: function() { + this.set('admin', false); + this.set('can_grant_admin', true); + this.set('can_revoke_admin', false); + return jQuery.ajax("/admin/users/" + (this.get('id')) + "/revoke_admin", {type: 'PUT'}); + }, - // Revoke the user's admin access - revokeAdmin: function() { - this.set('admin', false); - this.set('can_grant_admin', true); - this.set('can_revoke_admin', false); - return jQuery.ajax("/admin/users/" + (this.get('id')) + "/revoke_admin", {type: 'PUT'}); - }, + grantAdmin: function() { + this.set('admin', true); + this.set('can_grant_admin', false); + this.set('can_revoke_admin', true); + jQuery.ajax("/admin/users/" + (this.get('id')) + "/grant_admin", {type: 'PUT'}); + }, - grantAdmin: function() { - this.set('admin', true); - this.set('can_grant_admin', false); - this.set('can_revoke_admin', true); - jQuery.ajax("/admin/users/" + (this.get('id')) + "/grant_admin", {type: 'PUT'}); - }, + // Revoke the user's moderation access + revokeModeration: function() { + this.set('moderator', false); + this.set('can_grant_moderation', true); + this.set('can_revoke_moderation', false); + return jQuery.ajax("/admin/users/" + (this.get('id')) + "/revoke_moderation", {type: 'PUT'}); + }, - // Revoke the user's moderation access - revokeModeration: function() { - this.set('moderator', false); - this.set('can_grant_moderation', true); - this.set('can_revoke_moderation', false); - return jQuery.ajax("/admin/users/" + (this.get('id')) + "/revoke_moderation", {type: 'PUT'}); - }, + grantModeration: function() { + this.set('moderator', true); + this.set('can_grant_moderation', false); + this.set('can_revoke_moderation', true); + jQuery.ajax("/admin/users/" + (this.get('id')) + "/grant_moderation", {type: 'PUT'}); + }, - grantModeration: function() { - this.set('moderator', true); - this.set('can_grant_moderation', false); - this.set('can_revoke_moderation', true); - jQuery.ajax("/admin/users/" + (this.get('id')) + "/grant_moderation", {type: 'PUT'}); - }, + refreshBrowsers: function() { + jQuery.ajax("/admin/users/" + (this.get('id')) + "/refresh_browsers", {type: 'POST'}); + bootbox.alert("Message sent to all clients!"); + }, - refreshBrowsers: function() { - jQuery.ajax("/admin/users/" + (this.get('id')) + "/refresh_browsers", {type: 'POST'}); - bootbox.alert("Message sent to all clients!"); - }, + approve: function() { + this.set('can_approve', false); + this.set('approved', true); + this.set('approved_by', Discourse.get('currentUser')); + jQuery.ajax("/admin/users/" + (this.get('id')) + "/approve", {type: 'PUT'}); + }, - approve: function() { - this.set('can_approve', false); - this.set('approved', true); - this.set('approved_by', Discourse.get('currentUser')); - jQuery.ajax("/admin/users/" + (this.get('id')) + "/approve", {type: 'PUT'}); - }, + username_lower: (function() { + return this.get('username').toLowerCase(); + }).property('username'), - username_lower: (function() { - return this.get('username').toLowerCase(); - }).property('username'), + trustLevel: (function() { + return Discourse.get('site.trust_levels').findProperty('id', this.get('trust_level')); + }).property('trust_level'), - trustLevel: (function() { - return Discourse.get('site.trust_levels').findProperty('id', this.get('trust_level')); - }).property('trust_level'), + canBan: (function() { + return !this.admin && !this.moderator; + }).property('admin', 'moderator'), - canBan: (function() { - return !this.admin && !this.moderator; - }).property('admin', 'moderator'), + banDuration: (function() { + var banned_at, banned_till; + banned_at = Date.create(this.banned_at); + banned_till = Date.create(this.banned_till); + return "" + (banned_at.short()) + " - " + (banned_till.short()); + }).property('banned_till', 'banned_at'), - banDuration: (function() { - var banned_at, banned_till; - banned_at = Date.create(this.banned_at); - banned_till = Date.create(this.banned_till); - return "" + (banned_at.short()) + " - " + (banned_till.short()); - }).property('banned_till', 'banned_at'), + ban: function() { + var duration, + _this = this; + if (duration = parseInt(window.prompt(Em.String.i18n('admin.user.ban_duration')), 10)) { + if (duration > 0) { + return jQuery.ajax("/admin/users/" + this.id + "/ban", { + type: 'PUT', + data: {duration: duration}, + success: function() { + window.location.reload(); + }, + error: function(e) { + var error; + error = Em.String.i18n('admin.user.ban_failed', { + error: "http: " + e.status + " - " + e.body + }); + bootbox.alert(error); + } + }); + } + } + }, - ban: function() { - var duration, - _this = this; - if (duration = parseInt(window.prompt(Em.String.i18n('admin.user.ban_duration')), 10)) { - if (duration > 0) { - return jQuery.ajax("/admin/users/" + this.id + "/ban", { - type: 'PUT', - data: {duration: duration}, - success: function() { - window.location.reload(); - }, - error: function(e) { - var error; - error = Em.String.i18n('admin.user.ban_failed', { - error: "http: " + e.status + " - " + e.body - }); - bootbox.alert(error); - } - }); + unban: function() { + var _this = this; + return jQuery.ajax("/admin/users/" + this.id + "/unban", { + type: 'PUT', + success: function() { + window.location.reload(); + }, + error: function(e) { + var error; + error = Em.String.i18n('admin.user.unban_failed', { + error: "http: " + e.status + " - " + e.body + }); + bootbox.alert(error); + } + }); + }, + + impersonate: function() { + var _this = this; + return jQuery.ajax("/admin/impersonate", { + type: 'POST', + data: { + username_or_email: this.get('username') + }, + success: function() { + document.location = "/"; + }, + error: function(e) { + _this.set('loading', false); + if (e.status === 404) { + return bootbox.alert(Em.String.i18n('admin.impersonate.not_found')); + } else { + return bootbox.alert(Em.String.i18n('admin.impersonate.invalid')); } } - }, + }); + } - unban: function() { - var _this = this; - return jQuery.ajax("/admin/users/" + this.id + "/unban", { - type: 'PUT', - success: function() { - window.location.reload(); - }, - error: function(e) { - var error; - error = Em.String.i18n('admin.user.unban_failed', { - error: "http: " + e.status + " - " + e.body - }); - bootbox.alert(error); - } - }); - }, +}); - impersonate: function() { - var _this = this; - return jQuery.ajax("/admin/impersonate", { - type: 'POST', - data: { - username_or_email: this.get('username') - }, - success: function() { - document.location = "/"; - }, - error: function(e) { - _this.set('loading', false); - if (e.status === 404) { - return bootbox.alert(Em.String.i18n('admin.impersonate.not_found')); - } else { - return bootbox.alert(Em.String.i18n('admin.impersonate.invalid')); - } - } - }); - } +window.Discourse.AdminUser.reopenClass({ - }); + bulkApprove: function(users) { + users.each(function(user) { + user.set('approved', true); + user.set('can_approve', false); + return user.set('selected', false); + }); + return jQuery.ajax("/admin/users/approve-bulk", { + type: 'PUT', + data: { + users: users.map(function(u) { + return u.id; + }) + } + }); + }, - window.Discourse.AdminUser.reopenClass({ + find: function(username) { + var promise; + promise = new RSVP.Promise(); + jQuery.ajax({ + url: "/admin/users/" + username, + success: function(result) { + return promise.resolve(Discourse.AdminUser.create(result)); + } + }); + return promise; + }, - bulkApprove: function(users) { - users.each(function(user) { - user.set('approved', true); - user.set('can_approve', false); - return user.set('selected', false); - }); - return jQuery.ajax("/admin/users/approve-bulk", { - type: 'PUT', - data: { - users: users.map(function(u) { - return u.id; - }) - } - }); - }, - - find: function(username) { - var promise; - promise = new RSVP.Promise(); - jQuery.ajax({ - url: "/admin/users/" + username, - success: function(result) { - return promise.resolve(Discourse.AdminUser.create(result)); - } - }); - return promise; - }, - - findAll: function(query, filter) { - var result; - result = Em.A(); - jQuery.ajax({ - url: "/admin/users/list/" + query + ".json", - data: { - filter: filter - }, - success: function(users) { - return users.each(function(u) { - return result.pushObject(Discourse.AdminUser.create(u)); - }); - } - }); - return result; - } - }); - -}).call(this); + findAll: function(query, filter) { + var result; + result = Em.A(); + jQuery.ajax({ + url: "/admin/users/list/" + query + ".json", + data: { + filter: filter + }, + success: function(users) { + return users.each(function(u) { + return result.pushObject(Discourse.AdminUser.create(u)); + }); + } + }); + return result; + } +}); diff --git a/app/assets/javascripts/admin/models/email_log.js b/app/assets/javascripts/admin/models/email_log.js index 4169397ae00..1fd292567b4 100644 --- a/app/assets/javascripts/admin/models/email_log.js +++ b/app/assets/javascripts/admin/models/email_log.js @@ -1,38 +1,36 @@ -(function() { +/** + Our data model for representing an email log. - /** - Our data model for representing an email log. + @class EmailLog + @extends Discourse.Model + @namespace Discourse + @module Discourse +**/ +Discourse.EmailLog = Discourse.Model.extend({}); - @class EmailLog - @extends Discourse.Model - @namespace Discourse - @module Discourse - **/ - window.Discourse.EmailLog = Discourse.Model.extend({}); +Discourse.EmailLog.reopenClass({ - window.Discourse.EmailLog.reopenClass({ - - create: function(attrs) { - if (attrs.user) { - attrs.user = Discourse.AdminUser.create(attrs.user); - } - return this._super(attrs); - }, - - findAll: function(filter) { - var result; - result = Em.A(); - jQuery.ajax({ - url: "/admin/email_logs.json", - data: { filter: filter }, - success: function(logs) { - logs.each(function(log) { - result.pushObject(Discourse.EmailLog.create(log)); - }); - } - }); - return result; + create: function(attrs) { + if (attrs.user) { + attrs.user = Discourse.AdminUser.create(attrs.user); } - }); + return this._super(attrs); + }, + + findAll: function(filter) { + var result; + result = Em.A(); + jQuery.ajax({ + url: "/admin/email_logs.json", + data: { filter: filter }, + success: function(logs) { + logs.each(function(log) { + result.pushObject(Discourse.EmailLog.create(log)); + }); + } + }); + return result; + } +}); + -}).call(this); diff --git a/app/assets/javascripts/admin/models/flagged_post.js b/app/assets/javascripts/admin/models/flagged_post.js index ef8fc8cfd6e..cf937dbc883 100644 --- a/app/assets/javascripts/admin/models/flagged_post.js +++ b/app/assets/javascripts/admin/models/flagged_post.js @@ -1,85 +1,56 @@ -(function() { +/** + Our data model for interacting with flagged posts. - /** - Our data model for interacting with flagged posts. + @class FlaggedPost + @extends Discourse.Post + @namespace Discourse + @module Discourse +**/ +Discourse.FlaggedPost = Discourse.Post.extend({ - @class FlaggedPost - @extends Discourse.Post - @namespace Discourse - @module Discourse - **/ - window.Discourse.FlaggedPost = Discourse.Post.extend({ + flaggers: (function() { + var r, + _this = this; + r = []; + this.post_actions.each(function(a) { + return r.push(_this.userLookup[a.user_id]); + }); + return r; + }).property(), - flaggers: (function() { - var r, - _this = this; - r = []; - this.post_actions.each(function(a) { - return r.push(_this.userLookup[a.user_id]); - }); - return r; - }).property(), - - messages: (function() { - var r, - _this = this; - r = []; - this.post_actions.each(function(a) { - if (a.message) { - return r.push({ - user: _this.userLookup[a.user_id], - message: a.message - }); - } - }); - return r; - }).property(), - - lastFlagged: (function() { - return this.post_actions[0].created_at; - }).property(), - - user: (function() { - return this.userLookup[this.user_id]; - }).property(), - - topicHidden: (function() { - return this.get('topic_visible') === 'f'; - }).property('topic_hidden'), - - deletePost: function() { - var promise; - promise = new RSVP.Promise(); - if (this.get('post_number') === "1") { - return jQuery.ajax("/t/" + this.topic_id, { - type: 'DELETE', - cache: false, - success: function() { - promise.resolve(); - }, - error: function(e) { - promise.reject(); - } - }); - } else { - return jQuery.ajax("/posts/" + this.id, { - type: 'DELETE', - cache: false, - success: function() { - promise.resolve(); - }, - error: function(e) { - promise.reject(); - } + messages: (function() { + var r, + _this = this; + r = []; + this.post_actions.each(function(a) { + if (a.message) { + return r.push({ + user: _this.userLookup[a.user_id], + message: a.message }); } - }, + }); + return r; + }).property(), - clearFlags: function() { - var promise; - promise = new RSVP.Promise(); - jQuery.ajax("/admin/flags/clear/" + this.id, { - type: 'POST', + lastFlagged: (function() { + return this.post_actions[0].created_at; + }).property(), + + user: (function() { + return this.userLookup[this.user_id]; + }).property(), + + topicHidden: (function() { + return this.get('topic_visible') === 'f'; + }).property('topic_hidden'), + + deletePost: function() { + var promise; + promise = new RSVP.Promise(); + if (this.get('post_number') === "1") { + return jQuery.ajax("/t/" + this.topic_id, { + type: 'DELETE', cache: false, success: function() { promise.resolve(); @@ -88,37 +59,64 @@ promise.reject(); } }); - return promise; - }, - - hiddenClass: (function() { - if (this.get('hidden') === "t") return "hidden-post"; - }).property() - - }); - - window.Discourse.FlaggedPost.reopenClass({ - findAll: function(filter) { - var result; - result = Em.A(); - jQuery.ajax({ - url: "/admin/flags/" + filter + ".json", - success: function(data) { - var userLookup; - userLookup = {}; - data.users.each(function(u) { - userLookup[u.id] = Discourse.User.create(u); - }); - return data.posts.each(function(p) { - var f; - f = Discourse.FlaggedPost.create(p); - f.userLookup = userLookup; - return result.pushObject(f); - }); + } else { + return jQuery.ajax("/posts/" + this.id, { + type: 'DELETE', + cache: false, + success: function() { + promise.resolve(); + }, + error: function(e) { + promise.reject(); } }); - return result; } - }); + }, + + clearFlags: function() { + var promise; + promise = new RSVP.Promise(); + jQuery.ajax("/admin/flags/clear/" + this.id, { + type: 'POST', + cache: false, + success: function() { + promise.resolve(); + }, + error: function(e) { + promise.reject(); + } + }); + return promise; + }, + + hiddenClass: (function() { + if (this.get('hidden') === "t") return "hidden-post"; + }).property() + +}); + +Discourse.FlaggedPost.reopenClass({ + findAll: function(filter) { + var result; + result = Em.A(); + jQuery.ajax({ + url: "/admin/flags/" + filter + ".json", + success: function(data) { + var userLookup; + userLookup = {}; + data.users.each(function(u) { + userLookup[u.id] = Discourse.User.create(u); + }); + return data.posts.each(function(p) { + var f; + f = Discourse.FlaggedPost.create(p); + f.userLookup = userLookup; + return result.pushObject(f); + }); + } + }); + return result; + } +}); + -}).call(this); diff --git a/app/assets/javascripts/admin/models/site_customization.js b/app/assets/javascripts/admin/models/site_customization.js index 9820ecaf8c3..19f2a3bacfa 100644 --- a/app/assets/javascripts/admin/models/site_customization.js +++ b/app/assets/javascripts/admin/models/site_customization.js @@ -1,117 +1,112 @@ -(function() { - var SiteCustomizations; +/** + Our data model for interacting with site customizations. - /** - Our data model for interacting with site customizations. + @class SiteCustomization + @extends Discourse.Model + @namespace Discourse + @module Discourse +**/ +Discourse.SiteCustomization = Discourse.Model.extend({ + trackedProperties: ['enabled', 'name', 'stylesheet', 'header', 'override_default_style'], - @class SiteCustomization - @extends Discourse.Model - @namespace Discourse - @module Discourse - **/ - window.Discourse.SiteCustomization = Discourse.Model.extend({ - trackedProperties: ['enabled', 'name', 'stylesheet', 'header', 'override_default_style'], + init: function() { + this._super(); + return this.startTrackingChanges(); + }, + + description: (function() { + return "" + this.name + (this.enabled ? ' (*)' : ''); + }).property('selected', 'name'), - init: function() { - this._super(); - return this.startTrackingChanges(); - }, - - description: (function() { - return "" + this.name + (this.enabled ? ' (*)' : ''); - }).property('selected', 'name'), - - 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'), - - startTrackingChanges: function() { - var _this = this; - this.set('originals', {}); - return this.trackedProperties.each(function(p) { - _this.originals[p] = _this.get(p); - return true; - }); - }, - - previewUrl: (function() { - return "/?preview-style=" + (this.get('key')); - }).property('key'), - - disableSave: (function() { - return !this.get('changed'); - }).property('changed'), - - 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 - }; - return jQuery.ajax({ - url: "/admin/site_customizations" + (this.id ? '/' + this.id : ''), - data: { - site_customization: data - }, - type: this.id ? 'PUT' : 'POST' - }); - }, - - "delete": function() { - if (!this.id) return; - - return jQuery.ajax({ - url: "/admin/site_customizations/" + this.id, - type: 'DELETE' - }); + 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'), - }); + startTrackingChanges: function() { + var _this = this; + this.set('originals', {}); + return this.trackedProperties.each(function(p) { + _this.originals[p] = _this.get(p); + return true; + }); + }, - 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') - }); + previewUrl: (function() { + return "/?preview-style=" + (this.get('key')); + }).property('key'), - Discourse.SiteCustomization.reopenClass({ - findAll: function() { - var content, - _this = this; - content = SiteCustomizations.create({ - content: [], - loading: true - }); - jQuery.ajax({ - 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); - }); - } - return content.set('loading', false); + disableSave: (function() { + return !this.get('changed'); + }).property('changed'), + + 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 + }; + return jQuery.ajax({ + url: "/admin/site_customizations" + (this.id ? '/' + this.id : ''), + data: { + site_customization: data + }, + type: this.id ? 'PUT' : 'POST' + }); + }, + + "delete": function() { + if (!this.id) return; + + return jQuery.ajax({ + url: "/admin/site_customizations/" + this.id, + type: 'DELETE' + }); + } + +}); + +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') +}); + +Discourse.SiteCustomization.reopenClass({ + findAll: function() { + var content, + _this = this; + content = SiteCustomizations.create({ + content: [], + loading: true + }); + jQuery.ajax({ + 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); + }); } - }); - return content; - } - }); - -}).call(this); + return content.set('loading', false); + } + }); + return content; + } +}); diff --git a/app/assets/javascripts/admin/models/site_setting.js b/app/assets/javascripts/admin/models/site_setting.js index 155871f7218..86eeaac39f1 100644 --- a/app/assets/javascripts/admin/models/site_setting.js +++ b/app/assets/javascripts/admin/models/site_setting.js @@ -1,65 +1,63 @@ -(function() { +/** + Our data model for interacting with site settings. - /** - Our data model for interacting with site settings. + @class SiteSetting + @extends Discourse.Model + @namespace Discourse + @module Discourse +**/ +Discourse.SiteSetting = Discourse.Model.extend({ + + // Whether a property is short. + short: (function() { + if (this.blank('value')) return true; + return this.get('value').toString().length < 80; + }).property('value'), - @class SiteSetting - @extends Discourse.Model - @namespace Discourse - @module Discourse - **/ - window.Discourse.SiteSetting = Discourse.Model.extend({ - - // Whether a property is short. - short: (function() { - if (this.blank('value')) return true; - return this.get('value').toString().length < 80; - }).property('value'), + // Whether the site setting has changed + dirty: (function() { + return this.get('originalValue') !== this.get('value'); + }).property('originalValue', 'value'), - // Whether the site setting has changed - dirty: (function() { - return this.get('originalValue') !== this.get('value'); - }).property('originalValue', 'value'), + overridden: (function() { + var defaultVal, val; + val = this.get('value'); + defaultVal = this.get('default'); + if (val && defaultVal) { + return val.toString() !== defaultVal.toString(); + } + return val !== defaultVal; + }).property('value'), - overridden: (function() { - var defaultVal, val; - val = this.get('value'); - defaultVal = this.get('default'); - if (val && defaultVal) { - return val.toString() !== defaultVal.toString(); + resetValue: function() { + this.set('value', this.get('originalValue')); + }, + + save: function() { + // Update the setting + var _this = this; + return jQuery.ajax("/admin/site_settings/" + (this.get('setting')), { + data: { value: this.get('value') }, + type: 'PUT', + success: function() { + _this.set('originalValue', _this.get('value')); } - return val !== defaultVal; - }).property('value'), + }); + } +}); - resetValue: function() { - this.set('value', this.get('originalValue')); - }, - - save: function() { - // Update the setting - var _this = this; - return jQuery.ajax("/admin/site_settings/" + (this.get('setting')), { - data: { value: this.get('value') }, - type: 'PUT', - success: function() { - _this.set('originalValue', _this.get('value')); - } +Discourse.SiteSetting.reopenClass({ + findAll: function() { + var result; + result = Em.A(); + jQuery.get("/admin/site_settings", function(settings) { + return settings.each(function(s) { + s.originalValue = s.value; + return result.pushObject(Discourse.SiteSetting.create(s)); }); - } - }); + }); + return result; + } +}); - window.Discourse.SiteSetting.reopenClass({ - findAll: function() { - var result; - result = Em.A(); - jQuery.get("/admin/site_settings", function(settings) { - return settings.each(function(s) { - s.originalValue = s.value; - return result.pushObject(Discourse.SiteSetting.create(s)); - }); - }); - return result; - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/models/version_check.js b/app/assets/javascripts/admin/models/version_check.js index 5692b7d2885..6a42b1eff51 100644 --- a/app/assets/javascripts/admin/models/version_check.js +++ b/app/assets/javascripts/admin/models/version_check.js @@ -1,39 +1,35 @@ -(function() { +/** + Our data model for determining whether there's a new version of Discourse - /** - Our data model for determining whether there's a new version of Discourse + @class VersionCheck + @extends Discourse.Model + @namespace Discourse + @module Discourse +**/ +Discourse.VersionCheck = Discourse.Model.extend({ + upToDate: function() { + return this.get('latest_version') === this.get('installed_version'); + }.property('latest_version', 'installed_version'), - @class VersionCheck - @extends Discourse.Model - @namespace Discourse - @module Discourse - **/ - window.Discourse.VersionCheck = Discourse.Model.extend({ - upToDate: function() { - return this.get('latest_version') === this.get('installed_version'); - }.property('latest_version', 'installed_version'), + gitLink: function() { + return "https://github.com/discourse/discourse/tree/" + this.get('installed_sha'); + }.property('installed_sha'), - gitLink: function() { - return "https://github.com/discourse/discourse/tree/" + this.get('installed_sha'); - }.property('installed_sha'), + shortSha: function() { + return this.get('installed_sha').substr(0,10); + }.property('installed_sha') +}); - shortSha: function() { - return this.get('installed_sha').substr(0,10); - }.property('installed_sha') - }); - - Discourse.VersionCheck.reopenClass({ - find: function() { - var promise = new RSVP.Promise(); - jQuery.ajax({ - url: '/admin/version_check', - dataType: 'json', - success: function(json) { - promise.resolve(Discourse.VersionCheck.create(json)); - } - }); - return promise; - } - }); - -}).call(this); +Discourse.VersionCheck.reopenClass({ + find: function() { + var promise = new RSVP.Promise(); + jQuery.ajax({ + url: '/admin/version_check', + dataType: 'json', + success: function(json) { + promise.resolve(Discourse.VersionCheck.create(json)); + } + }); + return promise; + } +}); \ No newline at end of file diff --git a/app/assets/javascripts/admin/routes/admin_customize_route.js b/app/assets/javascripts/admin/routes/admin_customize_route.js index cd5f60f5513..e085791561b 100644 --- a/app/assets/javascripts/admin/routes/admin_customize_route.js +++ b/app/assets/javascripts/admin/routes/admin_customize_route.js @@ -1,21 +1,19 @@ -(function() { +/** + Handles routes related to customization - /** - Handles routes related to customization + @class AdminCustomizeRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminCustomizeRoute = Discourse.Route.extend({ + model: function() { + return Discourse.SiteCustomization.findAll(); + }, - @class AdminCustomizeRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminCustomizeRoute = Discourse.Route.extend({ - model: function() { - return Discourse.SiteCustomization.findAll(); - }, + renderTemplate: function() { + this.render({into: 'admin/templates/admin'}); + } +}); - renderTemplate: function() { - this.render({into: 'admin/templates/admin'}); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_dashboard_route.js b/app/assets/javascripts/admin/routes/admin_dashboard_route.js index 7293f341bc0..49a745eadb2 100644 --- a/app/assets/javascripts/admin/routes/admin_dashboard_route.js +++ b/app/assets/javascripts/admin/routes/admin_dashboard_route.js @@ -1,33 +1,30 @@ -(function() { +/** + Handles the default admin route - /** - Handles the default admin route - - @class AdminDashboardRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminDashboardRoute = Discourse.Route.extend({ - setupController: function(c) { - if( !c.get('versionCheckedAt') || Date.create('12 hours ago') > c.get('versionCheckedAt') ) { - this.checkVersion(c); - } - }, - - renderTemplate: function() { - this.render({into: 'admin/templates/admin'}); - }, - - checkVersion: function(c) { - if( Discourse.SiteSettings.version_checks ) { - Discourse.VersionCheck.find().then(function(vc) { - c.set('versionCheck', vc); - c.set('versionCheckedAt', new Date()); - c.set('loading', false); - }); - } + @class AdminDashboardRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminDashboardRoute = Discourse.Route.extend({ + setupController: function(c) { + if( !c.get('versionCheckedAt') || Date.create('12 hours ago') > c.get('versionCheckedAt') ) { + this.checkVersion(c); } - }); + }, + + renderTemplate: function() { + this.render({into: 'admin/templates/admin'}); + }, + + checkVersion: function(c) { + if( Discourse.SiteSettings.version_checks ) { + Discourse.VersionCheck.find().then(function(vc) { + c.set('versionCheck', vc); + c.set('versionCheckedAt', new Date()); + c.set('loading', false); + }); + } + } +}); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_email_logs_route.js b/app/assets/javascripts/admin/routes/admin_email_logs_route.js index 3b763c3f575..f1fa425131d 100644 --- a/app/assets/javascripts/admin/routes/admin_email_logs_route.js +++ b/app/assets/javascripts/admin/routes/admin_email_logs_route.js @@ -1,21 +1,19 @@ -(function() { +/** + Handles routes related to viewing email logs. - /** - Handles routes related to viewing email logs. + @class AdminEmailLogsRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminEmailLogsRoute = Discourse.Route.extend({ + model: function() { + return Discourse.EmailLog.findAll(); + }, - @class AdminEmailLogsRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminEmailLogsRoute = Discourse.Route.extend({ - model: function() { - return Discourse.EmailLog.findAll(); - }, + renderTemplate: function() { + this.render('admin/templates/email_logs'); + } +}); - renderTemplate: function() { - this.render('admin/templates/email_logs'); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_flags_active_route.js b/app/assets/javascripts/admin/routes/admin_flags_active_route.js index 8623feb576e..9ae171a0a3e 100644 --- a/app/assets/javascripts/admin/routes/admin_flags_active_route.js +++ b/app/assets/javascripts/admin/routes/admin_flags_active_route.js @@ -1,25 +1,23 @@ -(function() { +/** + Handles routes related to viewing active flags. - /** - Handles routes related to viewing active flags. + @class AdminFlagsActiveRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminFlagsActiveRoute = Discourse.Route.extend({ - @class AdminFlagsActiveRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminFlagsActiveRoute = Discourse.Route.extend({ + model: function() { + return Discourse.FlaggedPost.findAll('active'); + }, - model: function() { - return Discourse.FlaggedPost.findAll('active'); - }, + setupController: function(controller, model) { + var adminFlagsController = this.controllerFor('adminFlags'); + adminFlagsController.set('content', model); + adminFlagsController.set('query', 'active'); + } - setupController: function(controller, model) { - var adminFlagsController = this.controllerFor('adminFlags'); - adminFlagsController.set('content', model); - adminFlagsController.set('query', 'active'); - } +}); - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_flags_old_route.js b/app/assets/javascripts/admin/routes/admin_flags_old_route.js index 0ac9079287e..df967f53c83 100644 --- a/app/assets/javascripts/admin/routes/admin_flags_old_route.js +++ b/app/assets/javascripts/admin/routes/admin_flags_old_route.js @@ -1,25 +1,23 @@ -(function() { +/** + Handles routes related to viewing old flags. - /** - Handles routes related to viewing old flags. + @class AdminFlagsOldRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminFlagsOldRoute = Discourse.Route.extend({ + + model: function() { + return Discourse.FlaggedPost.findAll('old'); + }, - @class AdminFlagsOldRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminFlagsOldRoute = Discourse.Route.extend({ - - model: function() { - return Discourse.FlaggedPost.findAll('old'); - }, + setupController: function(controller, model) { + var adminFlagsController = this.controllerFor('adminFlags'); + adminFlagsController.set('content', model); + adminFlagsController.set('query', 'old'); + } - setupController: function(controller, model) { - var adminFlagsController = this.controllerFor('adminFlags'); - adminFlagsController.set('content', model); - adminFlagsController.set('query', 'old'); - } +}); - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_flags_route.js b/app/assets/javascripts/admin/routes/admin_flags_route.js index c78f0caafc8..7def67540d9 100644 --- a/app/assets/javascripts/admin/routes/admin_flags_route.js +++ b/app/assets/javascripts/admin/routes/admin_flags_route.js @@ -1,17 +1,15 @@ -(function() { +/** + Basic route for admin flags - /** - Basic route for admin flags + @class AdminFlagsRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminFlagsRoute = Discourse.Route.extend({ + renderTemplate: function() { + this.render('admin/templates/flags'); + } +}); - @class AdminFlagsRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminFlagsRoute = Discourse.Route.extend({ - renderTemplate: function() { - this.render('admin/templates/flags'); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_route.js b/app/assets/javascripts/admin/routes/admin_route.js index a168172a3dc..a28ffff2eba 100644 --- a/app/assets/javascripts/admin/routes/admin_route.js +++ b/app/assets/javascripts/admin/routes/admin_route.js @@ -1,17 +1,15 @@ -(function() { +/** + The base admin route - /** - The base admin route + @class AdminRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminRoute = Discourse.Route.extend({ + renderTemplate: function() { + this.render('admin/templates/admin'); + } +}); - @class AdminRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminRoute = Discourse.Route.extend({ - renderTemplate: function() { - this.render('admin/templates/admin'); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_routes.js b/app/assets/javascripts/admin/routes/admin_routes.js index bebaddcbaaf..215a7ba14c1 100644 --- a/app/assets/javascripts/admin/routes/admin_routes.js +++ b/app/assets/javascripts/admin/routes/admin_routes.js @@ -1,31 +1,32 @@ -(function() { +/** + Builds the routes for the admin section - /** - Declare all the routes used in the admin section. - **/ - Discourse.buildRoutes(function() { - return this.resource('admin', { path: '/admin' }, function() { - - this.route('dashboard', { path: '/' }); - this.route('site_settings', { path: '/site_settings' }); - this.route('email_logs', { path: '/email_logs' }); - this.route('customize', { path: '/customize' }); + @method buildRoutes + @for Discourse.AdminRoute +**/ +Discourse.buildRoutes(function() { + this.resource('admin', { path: '/admin' }, function() { - this.resource('adminFlags', { path: '/flags' }, function() { - this.route('active', { path: '/active' }); - this.route('old', { path: '/old' }); - }); - - this.resource('adminUsers', { path: '/users' }, function() { - this.resource('adminUser', { path: '/:username' }); - this.resource('adminUsersList', { path: '/list' }, function() { - this.route('active', { path: '/active' }); - this.route('new', { path: '/new' }); - this.route('pending', { path: '/pending' }); - }); - }); + this.route('dashboard', { path: '/' }); + this.route('site_settings', { path: '/site_settings' }); + this.route('email_logs', { path: '/email_logs' }); + this.route('customize', { path: '/customize' }); + this.resource('adminFlags', { path: '/flags' }, function() { + this.route('active', { path: '/active' }); + this.route('old', { path: '/old' }); }); - }); -}).call(this); + this.resource('adminUsers', { path: '/users' }, function() { + this.resource('adminUser', { path: '/:username' }); + this.resource('adminUsersList', { path: '/list' }, function() { + this.route('active', { path: '/active' }); + this.route('new', { path: '/new' }); + this.route('pending', { path: '/pending' }); + }); + }); + + }); +}); + + diff --git a/app/assets/javascripts/admin/routes/admin_site_settings_route.js b/app/assets/javascripts/admin/routes/admin_site_settings_route.js index 66d51d77919..5043b40a0c7 100644 --- a/app/assets/javascripts/admin/routes/admin_site_settings_route.js +++ b/app/assets/javascripts/admin/routes/admin_site_settings_route.js @@ -1,21 +1,19 @@ -(function() { +/** + Handles routes related to viewing and editing site settings. - /** - Handles routes related to viewing and editing site settings. + @class AdminSiteSettingsRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminSiteSettingsRoute = Discourse.Route.extend({ + model: function() { + return Discourse.SiteSetting.findAll(); + }, - @class AdminSiteSettingsRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminSiteSettingsRoute = Discourse.Route.extend({ - model: function() { - return Discourse.SiteSetting.findAll(); - }, + renderTemplate: function() { + this.render('admin/templates/site_settings', {into: 'admin/templates/admin'}); + } +}); - renderTemplate: function() { - this.render('admin/templates/site_settings', {into: 'admin/templates/admin'}); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_user_route.js b/app/assets/javascripts/admin/routes/admin_user_route.js index 1e67210d82b..343dce69549 100644 --- a/app/assets/javascripts/admin/routes/admin_user_route.js +++ b/app/assets/javascripts/admin/routes/admin_user_route.js @@ -1,22 +1,20 @@ -(function() { +/** + Handles routes related to users in the admin section. - /** - Handles routes related to users in the admin section. + @class AdminUserRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminUserRoute = Discourse.Route.extend({ + model: function(params) { + return Discourse.AdminUser.find(params.username); + }, - @class AdminUserRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminUserRoute = Discourse.Route.extend({ - model: function(params) { - return Discourse.AdminUser.find(params.username); - }, + renderTemplate: function() { + this.render('admin/templates/user', {into: 'admin/templates/admin'}); + } - renderTemplate: function() { - this.render('admin/templates/user', {into: 'admin/templates/admin'}); - } +}); - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_users_list_active_route.js b/app/assets/javascripts/admin/routes/admin_users_list_active_route.js index 9d80ed52e91..46b23537bf7 100644 --- a/app/assets/javascripts/admin/routes/admin_users_list_active_route.js +++ b/app/assets/javascripts/admin/routes/admin_users_list_active_route.js @@ -1,17 +1,15 @@ -(function() { +/** + Handles the route that lists active users. - /** - Handles the route that lists active users. + @class AdminUsersListActiveRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminUsersListActiveRoute = Discourse.Route.extend({ + setupController: function() { + return this.controllerFor('adminUsersList').show('active'); + } +}); - @class AdminUsersListActiveRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminUsersListActiveRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('active'); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_users_list_new_route.js b/app/assets/javascripts/admin/routes/admin_users_list_new_route.js index bc6008f1a4e..48f22a38e22 100644 --- a/app/assets/javascripts/admin/routes/admin_users_list_new_route.js +++ b/app/assets/javascripts/admin/routes/admin_users_list_new_route.js @@ -1,17 +1,15 @@ -(function() { +/** + Handles the route that lists new users. - /** - Handles the route that lists new users. + @class AdminUsersListNewRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminUsersListNewRoute = Discourse.Route.extend({ + setupController: function() { + return this.controllerFor('adminUsersList').show('new'); + } +}); - @class AdminUsersListNewRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminUsersListNewRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('new'); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_users_list_pending_route.js b/app/assets/javascripts/admin/routes/admin_users_list_pending_route.js index 3b5376a64f1..bd2efaf6a4c 100644 --- a/app/assets/javascripts/admin/routes/admin_users_list_pending_route.js +++ b/app/assets/javascripts/admin/routes/admin_users_list_pending_route.js @@ -1,17 +1,15 @@ -(function() { +/** + Handles the route that lists pending users. - /** - Handles the route that lists pending users. + @class AdminUsersListNewRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminUsersListPendingRoute = Discourse.Route.extend({ + setupController: function() { + return this.controllerFor('adminUsersList').show('pending'); + } +}); - @class AdminUsersListNewRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminUsersListPendingRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('pending'); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/routes/admin_users_list_route.js b/app/assets/javascripts/admin/routes/admin_users_list_route.js index a08336be0df..757c7efa2ca 100644 --- a/app/assets/javascripts/admin/routes/admin_users_list_route.js +++ b/app/assets/javascripts/admin/routes/admin_users_list_route.js @@ -1,17 +1,15 @@ -(function() { +/** + Handles the route that deals with listing users - /** - Handles the route that deals with listing users + @class AdminUsersListRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminUsersListRoute = Discourse.Route.extend({ + renderTemplate: function() { + this.render('admin/templates/users_list', {into: 'admin/templates/admin'}); + } +}); - @class AdminUsersListRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.AdminUsersListRoute = Discourse.Route.extend({ - renderTemplate: function() { - this.render('admin/templates/users_list', {into: 'admin/templates/admin'}); - } - }); -}).call(this); diff --git a/app/assets/javascripts/admin/views/ace_editor_view.js b/app/assets/javascripts/admin/views/ace_editor_view.js index f31c19d57aa..fc9849ab16b 100644 --- a/app/assets/javascripts/admin/views/ace_editor_view.js +++ b/app/assets/javascripts/admin/views/ace_editor_view.js @@ -1,66 +1,65 @@ /*global ace:true */ -(function() { - /** - A view that wraps the ACE editor (http://ace.ajax.org/) +/** + A view that wraps the ACE editor (http://ace.ajax.org/) - @class AceEditorView - @extends Em.View - @namespace Discourse - @module Discourse - **/ - Discourse.AceEditorView = Discourse.View.extend({ - mode: 'css', - classNames: ['ace-wrapper'], + @class AceEditorView + @extends Em.View + @namespace Discourse + @module Discourse +**/ +Discourse.AceEditorView = Discourse.View.extend({ + mode: 'css', + classNames: ['ace-wrapper'], - contentChanged: (function() { - if (this.editor && !this.skipContentChangeEvent) { - return this.editor.getSession().setValue(this.get('content')); - } - }).observes('content'), - - render: function(buffer) { - buffer.push("
" + content + ""; - }, - "url": function(_, url) { - return "" + url + ""; - }, - "email": function(_, address) { - return "" + address + ""; - }, - "img": function(_, src) { - return "
" + content + ""; }, + "url": function(_, url) { return "" + url + ""; }, + "email": function(_, address) { return "" + address + ""; }, + "img": function(_, src) { return "
"); - } - return text; - }, - format: function(text, opts) { - var environment; - if (opts && opts.environment) environment = opts.environment; - if (!environment) environment = 'default'; - - text = Discourse.BBCode.apply(text, environment); - // Add quotes - text = Discourse.BBCode.formatQuote(text, opts); - return text; } - }; + }, -}).call(this); + // Apply a particular set of replacers + apply: function(text, environment) { + var replacer; + replacer = Discourse.BBCode.parsedReplacers()[environment]; + + replacer.forEach(function(r) { + text = text.replace(r.regexp, r.fn); + }); + return text; + }, + + parsedReplacers: function() { + var result; + if (this.parsed) return this.parsed; + + result = {}; + Object.keys(Discourse.BBCode.replacers, function(name, rules) { + var parsed; + parsed = result[name] = []; + Object.keys(Object.merge(Discourse.BBCode.replacers.base.withoutArgs, rules.withoutArgs), function(tag, val) { + return parsed.push({ + regexp: new RegExp("\\[" + tag + "\\]([\\s\\S]*?)\\[\\/" + tag + "\\]", "igm"), + fn: val + }); + }); + return Object.keys(Object.merge(Discourse.BBCode.replacers.base.withArgs, rules.withArgs), function(tag, val) { + return parsed.push({ + regexp: new RegExp("\\[" + tag + "=?(.+?)\\]([\\s\\S]*?)\\[\\/" + tag + "\\]", "igm"), + fn: val + }); + }); + }); + this.parsed = result; + return this.parsed; + }, + + buildQuoteBBCode: function(post, contents) { + var contents_hashed, result, sansQuotes, stripped, stripped_hashed, tmp; + if (!contents) contents = ""; + + sansQuotes = contents.replace(this.QUOTE_REGEXP, '').trim(); + if (sansQuotes.length === 0) return ""; + + /* Strip the HTML from cooked */ + tmp = document.createElement('div'); + tmp.innerHTML = post.get('cooked'); + stripped = tmp.textContent || tmp.innerText; + + /* + Let's remove any non alphanumeric characters as a kind of hash. Yes it's + not accurate but it should work almost every time we need it to. It would be unlikely + that the user would quote another post that matches in exactly this way. + */ + stripped_hashed = stripped.replace(/[^a-zA-Z0-9]/g, ''); + contents_hashed = contents.replace(/[^a-zA-Z0-9]/g, ''); + result = "[quote=\"" + (post.get('username')) + ", post:" + (post.get('post_number')) + ", topic:" + (post.get('topic_id')); + + /* If the quote is the full message, attribute it as such */ + if (stripped_hashed === contents_hashed) { + result += ", full:true"; + } + result += "\"]\n" + sansQuotes + "\n[/quote]\n\n"; + return result; + }, + + formatQuote: function(text, opts) { + + /* Replace quotes with appropriate markup */ + var args, matches, params, paramsSplit, paramsString, templateName, username; + while (matches = this.QUOTE_REGEXP.exec(text)) { + paramsString = matches[1]; + paramsString = paramsString.replace(/\"/g, ''); + paramsSplit = paramsString.split(/\, */); + params = []; + paramsSplit.each(function(p, i) { + var assignment; + if (i > 0) { + assignment = p.split(':'); + if (assignment[0] && assignment[1]) { + return params.push({ + key: assignment[0], + value: assignment[1].trim() + }); + } + } + }); + username = paramsSplit[0]; + + /* Arguments for formatting */ + args = { + username: username, + params: params, + quote: matches[2].trim(), + avatarImg: opts.lookupAvatar ? opts.lookupAvatar(username) : void 0 + }; + templateName = 'quote'; + if (opts && opts.environment) { + templateName = "quote_" + opts.environment; + } + text = text.replace(matches[0], "
" + HANDLEBARS_TEMPLATES[templateName](args) + ""); + } + return text; + }, + + /** + Format a text string using BBCode + + @method format + @param {String} text The text we want to format + @param {Object} opts Rendering options + **/ + format: function(text, opts) { + var environment; + if (opts && opts.environment) environment = opts.environment; + if (!environment) environment = 'default'; + + text = Discourse.BBCode.apply(text, environment); + // Add quotes + text = Discourse.BBCode.formatQuote(text, opts); + return text; + } +}; \ No newline at end of file diff --git a/app/assets/javascripts/discourse/components/caret_position.js b/app/assets/javascripts/discourse/components/caret_position.js index 5081d1f30e5..4bdb9b316ab 100644 --- a/app/assets/javascripts/discourse/components/caret_position.js +++ b/app/assets/javascripts/discourse/components/caret_position.js @@ -1,135 +1,134 @@ +// http://stackoverflow.com/questions/263743/how-to-get-caret-position-in-textarea +var clone, getCaret; +getCaret = function(el) { + var r, rc, re; + if (el.selectionStart) { + return el.selectionStart; + } else if (document.selection) { + el.focus(); + r = document.selection.createRange(); + if (!r) return 0; + re = el.createTextRange(); + rc = re.duplicate(); + re.moveToBookmark(r.getBookmark()); + rc.setEndPoint("EndToStart", re); + return rc.text.length; + } + return 0; +}; -/* caret position in textarea ... very hacky ... sorry -*/ +clone = null; +/** + This is a jQuery plugin to retrieve the caret position in a textarea -(function() { + @module $.fn.caretPosition +**/ +$.fn.caretPosition = function(options) { + var after, before, getStyles, guard, html, important, insertSpaceAfterBefore, letter, makeCursor, p, pPos, pos, span, styles, textarea, val; + if (clone) { + clone.remove(); + } + span = $("#pos span"); + textarea = $(this); - (function($) { - /* http://stackoverflow.com/questions/263743/how-to-get-caret-position-in-textarea - */ + getStyles = function(el, prop) { + if (el.currentStyle) { + return el.currentStyle; + } else { + return document.defaultView.getComputedStyle(el, ""); + } + }; - var clone, getCaret; - getCaret = function(el) { - var r, rc, re; - if (el.selectionStart) { - return el.selectionStart; - } else if (document.selection) { - el.focus(); - r = document.selection.createRange(); - if (!r) return 0; - re = el.createTextRange(); - rc = re.duplicate(); - re.moveToBookmark(r.getBookmark()); - rc.setEndPoint("EndToStart", re); - return rc.text.length; - } - return 0; - }; - clone = null; - $.fn.caretPosition = function(options) { - var after, before, getStyles, guard, html, important, insertSpaceAfterBefore, letter, makeCursor, p, pPos, pos, span, styles, textarea, val; - if (clone) { - clone.remove(); - } - span = jQuery("#pos span"); - textarea = jQuery(this); - getStyles = function(el, prop) { - if (el.currentStyle) { - return el.currentStyle; - } else { - return document.defaultView.getComputedStyle(el, ""); - } - }; - styles = getStyles(textarea[0]); - clone = jQuery("
" + escaped + "
";
- });
+ // github style fenced code
+ converter.hooks.chain("preConversion", function(text) {
+ return text.replace(/^`{3}(?:(.*$)\n)?([\s\S]*?)^`{3}/gm, function(wholeMatch, m1, m2) {
+ var escaped;
+ escaped = Handlebars.Utils.escapeExpression(m2);
+ return "" + escaped + "
";
});
+ });
+
+ converter.hooks.chain("postConversion", function(text) {
+ if (!text) return "";
+
+ // don't to mention voodoo in pres
+ text = text.replace(/([\s\S]*@[\s\S]*)<\/pre>/gi, function(wholeMatch, inner) { + return "" + (inner.replace(/@/g, '@')) + ""; + }); + + // Add @mentions of names + text = text.replace(/([\s\t>,:'|";\]])(@[A-Za-z0-9_-|\.]*[A-Za-z0-9_-|]+)(?=[\s\t<\!:|;',"\?\.])/g, function(x, pre, name) { + if (mentionLookup(name.substr(1))) { + return "" + pre + "" + name + ""; + } else { + return "" + pre + "" + name + ""; + } + }); + + // a primitive attempt at oneboxing, this regex gives me much eye sores + text = text.replace(/(
|
)[\s\n\r]*)(]*)>([^<]+<\/a>[\s\n\r]*(?=<\/p>|
))/gi, function() {
+ // We don't onebox items in a list
+ var onebox, url;
+ if (arguments[1]) {
+ return arguments[0];
+ }
+ url = arguments[5];
+ if (Discourse && Discourse.Onebox) {
+ onebox = Discourse.Onebox.lookupCache(url);
+ }
+ if (onebox && !onebox.isBlank()) {
+ return arguments[2] + onebox;
+ } else {
+ return arguments[2] + arguments[4] + " class=\"onebox\" target=\"_blank\">" + arguments[6];
+ }
+ });
+
+ return(text);
+ });
+
+ converter.hooks.chain("postConversion", function(text) {
+ return Discourse.BBCode.format(text, opts);
+ });
+
+ if (opts.sanitize) {
converter.hooks.chain("postConversion", function(text) {
- if (!text) {
+ if (!window.sanitizeHtml) {
return "";
}
- /* don't to mention voodoo in pres
- */
-
- text = text.replace(/([\s\S]*@[\s\S]*)<\/pre>/gi, function(wholeMatch, inner) {
- return "
" + (inner.replace(/@/g, '@')) + "
";
- });
- /* Add @mentions of names
- */
-
- text = text.replace(/([\s\t>,:'|";\]])(@[A-Za-z0-9_-|\.]*[A-Za-z0-9_-|]+)(?=[\s\t<\!:|;',"\?\.])/g, function(x, pre, name) {
- if (mentionLookup(name.substr(1))) {
- return "" + pre + "" + name + "";
- } else {
- return "" + pre + "" + name + "";
- }
- });
- /* a primitive attempt at oneboxing, this regex gives me much eye sores
- */
-
- text = text.replace(/(