From 2b5be29d3cc254eb37992768f4a5ed429ebe26cc Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Fri, 22 Feb 2013 10:57:11 +1100 Subject: [PATCH] Revert "Remove old unused code." This reverts commit 6a617348e5ba2e376f8d41f5432e5c95940dd66a. --- .../admin/routes/admin_user_route.js | 2 +- .../admin/views/ace_editor_view.js | 4 +- .../admin/views/admin_customize_view.js | 4 +- .../admin/views/admin_dashboard_view.js | 4 +- app/assets/javascripts/application.js.erb | 1 + .../javascripts/discourse/models/model.js | 46 +++----- .../discourse/routes/application_routes.js | 110 ++++++++++++------ .../discourse/routes/discourse_route.js | 56 ++++++--- .../discourse/routes/user_route.js | 15 +-- .../discourse/views/composer_view.js | 2 +- .../discourse/views/modal/modal_body_view.js | 2 +- .../discourse/views/quote_buton_view.js | 2 +- .../javascripts/discourse/views/share_view.js | 2 +- .../discourse/views/topic_status_view.js | 2 +- .../views/topic_summary/topic_summary_view.js | 4 +- .../javascripts/discourse/views/view.js | 13 +++ spec/javascripts/spec.js | 1 + 17 files changed, 162 insertions(+), 108 deletions(-) create mode 100644 app/assets/javascripts/discourse/views/view.js diff --git a/app/assets/javascripts/admin/routes/admin_user_route.js b/app/assets/javascripts/admin/routes/admin_user_route.js index 1e67210d8..a0c2295ca 100644 --- a/app/assets/javascripts/admin/routes/admin_user_route.js +++ b/app/assets/javascripts/admin/routes/admin_user_route.js @@ -1,7 +1,7 @@ (function() { /** - Handles routes related to users in the admin section. + Handles routes related to users. @class AdminUserRoute @extends Discourse.Route diff --git a/app/assets/javascripts/admin/views/ace_editor_view.js b/app/assets/javascripts/admin/views/ace_editor_view.js index eb1f48f45..f928c7365 100644 --- a/app/assets/javascripts/admin/views/ace_editor_view.js +++ b/app/assets/javascripts/admin/views/ace_editor_view.js @@ -5,11 +5,11 @@ A view that wraps the ACE editor (http://ace.ajax.org/) @class AceEditorView - @extends Em.View + @extends Discourse.View @namespace Discourse @module Discourse **/ - Discourse.AceEditorView = window.Em.View.extend({ + Discourse.AceEditorView = window.Discourse.View.extend({ mode: 'css', classNames: ['ace-wrapper'], diff --git a/app/assets/javascripts/admin/views/admin_customize_view.js b/app/assets/javascripts/admin/views/admin_customize_view.js index 665c7ad05..895b0aa89 100644 --- a/app/assets/javascripts/admin/views/admin_customize_view.js +++ b/app/assets/javascripts/admin/views/admin_customize_view.js @@ -5,11 +5,11 @@ A view to handle site customizations @class AdminCustomizeView - @extends Em.View + @extends Discourse.View @namespace Discourse @module Discourse **/ - Discourse.AdminCustomizeView = window.Em.View.extend({ + Discourse.AdminCustomizeView = window.Discourse.View.extend({ templateName: 'admin/templates/customize', classNames: ['customize'], diff --git a/app/assets/javascripts/admin/views/admin_dashboard_view.js b/app/assets/javascripts/admin/views/admin_dashboard_view.js index 18e25bd97..55cbbbc88 100644 --- a/app/assets/javascripts/admin/views/admin_dashboard_view.js +++ b/app/assets/javascripts/admin/views/admin_dashboard_view.js @@ -4,11 +4,11 @@ The default view in the admin section @class AdminDashboardView - @extends Em.View + @extends Discourse.View @namespace Discourse @module Discourse **/ - Discourse.AdminDashboardView = window.Em.View.extend({ + Discourse.AdminDashboardView = window.Discourse.View.extend({ templateName: 'admin/templates/dashboard', updateIconClasses: function() { diff --git a/app/assets/javascripts/application.js.erb b/app/assets/javascripts/application.js.erb index 05bda9a29..0efcaf0b0 100644 --- a/app/assets/javascripts/application.js.erb +++ b/app/assets/javascripts/application.js.erb @@ -29,6 +29,7 @@ // Stuff we need to load first //= require_tree ./discourse/mixins //= require ./discourse/components/debounce +//= require ./discourse/views/view //= require ./discourse/controllers/controller //= require ./discourse/views/modal/modal_body_view //= require ./discourse/models/model diff --git a/app/assets/javascripts/discourse/models/model.js b/app/assets/javascripts/discourse/models/model.js index 486af47ee..acb3d3373 100644 --- a/app/assets/javascripts/discourse/models/model.js +++ b/app/assets/javascripts/discourse/models/model.js @@ -1,41 +1,30 @@ (function() { - /** - A base object we can use to handle models in the Discourse client application. - - @class Model - @extends Ember.Object - @namespace Discourse - @module Discourse - **/ window.Discourse.Model = Ember.Object.extend({ + /* Our own AJAX handler that handles erronous responses + */ - /** - Our own AJAX handler that handles erronous responses - - @method ajax - @param {String} url The url to contact - @param {Object} args The arguments to pass to jQuery.ajax - **/ ajax: function(url, args) { - var oldError = args.error; + /* Error handler + */ + + var oldError, + _this = this; + oldError = args.error; args.error = function(xhr) { return oldError(jQuery.parseJSON(xhr.responseText).errors); }; return jQuery.ajax(url, args); }, + /* Update our object from another object + */ - /** - Update our object from another object - - @method mergeAttributes - @param {Object} attrs The attributes we want to merge with - @param {Object} builders Optional builders to use when merging attributes - **/ mergeAttributes: function(attrs, builders) { var _this = this; return Object.keys(attrs, function(k, v) { - // If they're in a builder we use that + /* If they're in a builder we use that + */ + var builder, col; if (typeof v === 'object' && builders && (builder = builders[k])) { if (!_this.get(k)) { @@ -53,14 +42,9 @@ }); window.Discourse.Model.reopenClass({ + /* Given an array of values, return them in a hash + */ - /** - Given an array of values, return them in a hash - - @method extractByKey - @param {Object} collection The collection of values - @param {Object} klass Optional The class to instantiate - **/ extractByKey: function(collection, klass) { var retval; retval = {}; diff --git a/app/assets/javascripts/discourse/routes/application_routes.js b/app/assets/javascripts/discourse/routes/application_routes.js index 7e8d33a1b..8751b1953 100644 --- a/app/assets/javascripts/discourse/routes/application_routes.js +++ b/app/assets/javascripts/discourse/routes/application_routes.js @@ -1,49 +1,93 @@ + +/* Ways we can filter the topics list +*/ + + (function() { Discourse.buildRoutes(function() { - var router = this; - - // Topic routes - this.resource('topic', { path: '/t/:slug/:id' }, function() { - this.route('fromParams', { path: '/' }); - this.route('fromParams', { path: '/:nearPost' }); - this.route('bestOf', { path: '/best_of' }); + var router; + this.resource('topic', { + path: '/t/:slug/:id' + }, function() { + this.route('fromParams', { + path: '/' + }); + this.route('fromParams', { + path: '/:nearPost' + }); + return this.route('bestOf', { + path: '/best_of' + }); }); + /* Generate static page routes + */ - // Generate static page routes + router = this; Discourse.StaticController.pages.forEach(function(p) { - router.route(p, { path: "/" + p }); + return router.route(p, { + path: "/" + p + }); }); - - this.route('faq', { path: '/faq' }); - this.route('tos', { path: '/tos' }); - this.route('privacy', { path: '/privacy' }); - - // List routes - this.resource('list', { path: '/' }, function() { + this.route('faq', { + path: '/faq' + }); + this.route('tos', { + path: '/tos' + }); + this.route('privacy', { + path: '/privacy' + }); + this.resource('list', { + path: '/' + }, function() { router = this; + /* Generate routes for all our filters + */ - // Generate routes for all our filters Discourse.ListController.filters.forEach(function(r) { - router.route(r, { path: "/" + r }); - router.route(r, { path: "/" + r + "/more" }); + router.route(r, { + path: "/" + r + }); + return router.route(r, { + path: "/" + r + "/more" + }); + }); + router.route('popular', { + path: '/' + }); + router.route('categories', { + path: '/categories' + }); + router.route('category', { + path: '/category/:slug/more' + }); + return router.route('category', { + path: '/category/:slug' }); - - this.route('popular', { path: '/' }); - this.route('categories', { path: '/categories' }); - this.route('category', { path: '/category/:slug/more' }); - this.route('category', { path: '/category/:slug' }); }); - - // User routes - this.resource('user', { path: '/users/:username' }, function() { - this.route('activity', { path: '/' }); - this.resource('preferences', { path: '/preferences' }, function() { - this.route('username', { path: '/username' }); - this.route('email', { path: '/email' }); + return this.resource('user', { + path: '/users/:username' + }, function() { + this.route('activity', { + path: '/' + }); + this.resource('preferences', { + path: '/preferences' + }, function() { + this.route('username', { + path: '/username' + }); + return this.route('email', { + path: '/email' + }); + }); + this.route('privateMessages', { + path: '/private-messages' + }); + return this.route('invited', { + path: 'invited' }); - this.route('privateMessages', { path: '/private-messages' }); - this.route('invited', { path: 'invited' }); }); }); diff --git a/app/assets/javascripts/discourse/routes/discourse_route.js b/app/assets/javascripts/discourse/routes/discourse_route.js index 48246bfa6..9609d20bd 100644 --- a/app/assets/javascripts/discourse/routes/discourse_route.js +++ b/app/assets/javascripts/discourse/routes/discourse_route.js @@ -1,31 +1,49 @@ (function() { - /** - The base admin route for all routes on Discourse. Includes global enter functionality. + window.Discourse.Route = Em.Route.extend({ + /* Called every time we enter a route + */ - @class Route - @extends Em.Route - @namespace Discourse - @module Discourse - **/ - Discourse.Route = Em.Route.extend({ - - /** - Called every time we enter a route on Discourse. - - @method enter - **/ enter: function(router, context) { - // Close mini profiler - jQuery('.profiler-results .profiler-result').remove(); + /* Close mini profiler + */ + + var composerController, f, search, shareController; + jQuery('.profiler-results .profiler-result').remove(); + /* Close stuff that may be open + */ - // Close some elements that may be open jQuery('.d-dropdown').hide(); jQuery('header ul.icons li').removeClass('active'); jQuery('[data-toggle="dropdown"]').parent().removeClass('open'); + /* TODO: need to adjust these + */ + + if (false) { + if (shareController = router.get('shareController')) { + shareController.close(); + } + /* Hide any searches + */ + + if (search = router.get('searchController')) { + search.close(); + } + /* get rid of "save as draft stuff" + */ + + composerController = Discourse.get('router.composerController'); + if (composerController) { + composerController.closeIfCollapsed(); + } + } + f = jQuery('html').data('hide-dropdown'); + if (f) { + return f(); + } + /*return @_super(router, context) + */ - var hideDropDownFunction = jQuery('html').data('hide-dropdown'); - if (hideDropDownFunction) return hideDropDownFunction(); } }); diff --git a/app/assets/javascripts/discourse/routes/user_route.js b/app/assets/javascripts/discourse/routes/user_route.js index 698313874..8f1c37a03 100644 --- a/app/assets/javascripts/discourse/routes/user_route.js +++ b/app/assets/javascripts/discourse/routes/user_route.js @@ -1,20 +1,13 @@ (function() { - /** - Handles routes related to users. - - @class UserRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse - **/ - Discourse.UserRoute = Discourse.Route.extend({ + window.Discourse.UserRoute = Discourse.Route.extend({ model: function(params) { return Discourse.User.find(params.username); }, - serialize: function(params) { - return { username: Em.get(params, 'username').toLowerCase() }; + return { + username: Em.get(params, 'username').toLowerCase() + }; } }); diff --git a/app/assets/javascripts/discourse/views/composer_view.js b/app/assets/javascripts/discourse/views/composer_view.js index 14f17dbcf..8de0bd114 100644 --- a/app/assets/javascripts/discourse/views/composer_view.js +++ b/app/assets/javascripts/discourse/views/composer_view.js @@ -1,7 +1,7 @@ /*global Markdown:true assetPath:true */ (function() { - window.Discourse.ComposerView = window.Em.View.extend({ + window.Discourse.ComposerView = window.Discourse.View.extend({ templateName: 'composer', elementId: 'reply-control', classNameBindings: ['content.creatingPrivateMessage:private-message', diff --git a/app/assets/javascripts/discourse/views/modal/modal_body_view.js b/app/assets/javascripts/discourse/views/modal/modal_body_view.js index 3b7970ffc..3bd7079f5 100644 --- a/app/assets/javascripts/discourse/views/modal/modal_body_view.js +++ b/app/assets/javascripts/discourse/views/modal/modal_body_view.js @@ -1,6 +1,6 @@ (function() { - window.Discourse.ModalBodyView = window.Em.View.extend({ + window.Discourse.ModalBodyView = window.Discourse.View.extend({ // Focus on first element didInsertElement: function() { var _this = this; diff --git a/app/assets/javascripts/discourse/views/quote_buton_view.js b/app/assets/javascripts/discourse/views/quote_buton_view.js index 64f2cef14..3ffb6154b 100644 --- a/app/assets/javascripts/discourse/views/quote_buton_view.js +++ b/app/assets/javascripts/discourse/views/quote_buton_view.js @@ -1,6 +1,6 @@ (function() { - window.Discourse.QuoteButtonView = Em.View.extend({ + window.Discourse.QuoteButtonView = Discourse.View.extend({ classNames: ['quote-button'], classNameBindings: ['hasBuffer'], render: function(buffer) { diff --git a/app/assets/javascripts/discourse/views/share_view.js b/app/assets/javascripts/discourse/views/share_view.js index 7cdf7fa06..828fa4f54 100644 --- a/app/assets/javascripts/discourse/views/share_view.js +++ b/app/assets/javascripts/discourse/views/share_view.js @@ -1,6 +1,6 @@ (function() { - window.Discourse.ShareView = Em.View.extend({ + window.Discourse.ShareView = Discourse.View.extend({ templateName: 'share', elementId: 'share-link', classNameBindings: ['hasLink'], diff --git a/app/assets/javascripts/discourse/views/topic_status_view.js b/app/assets/javascripts/discourse/views/topic_status_view.js index ad52c85a3..e4cd2cc89 100644 --- a/app/assets/javascripts/discourse/views/topic_status_view.js +++ b/app/assets/javascripts/discourse/views/topic_status_view.js @@ -1,6 +1,6 @@ (function() { - window.Discourse.TopicStatusView = Em.View.extend({ + window.Discourse.TopicStatusView = Discourse.View.extend({ classNames: ['topic-statuses'], hasDisplayableStatus: (function() { if (this.get('topic.closed')) { diff --git a/app/assets/javascripts/discourse/views/topic_summary/topic_summary_view.js b/app/assets/javascripts/discourse/views/topic_summary/topic_summary_view.js index 05d0f6215..5115f790a 100644 --- a/app/assets/javascripts/discourse/views/topic_summary/topic_summary_view.js +++ b/app/assets/javascripts/discourse/views/topic_summary/topic_summary_view.js @@ -66,7 +66,7 @@ /* If we have a best of view */ if (this.get('controller.showBestOf')) { - container.pushObject(Em.View.create({ + container.pushObject(Discourse.View.create({ templateName: 'topic_summary/best_of_toggle', tagName: 'section', classNames: ['information'] @@ -76,7 +76,7 @@ */ if (this.get('topic.isPrivateMessage')) { - return container.pushObject(Em.View.create({ + return container.pushObject(Discourse.View.create({ templateName: 'topic_summary/private_message', tagName: 'section', classNames: ['information'] diff --git a/app/assets/javascripts/discourse/views/view.js b/app/assets/javascripts/discourse/views/view.js new file mode 100644 index 000000000..5731ef99c --- /dev/null +++ b/app/assets/javascripts/discourse/views/view.js @@ -0,0 +1,13 @@ +(function() { + + window.Discourse.View = Ember.View.extend(Discourse.Presence, { + /* Overwrite this to do a different display + */ + + displayErrors: function(errors, callback) { + alert(errors.join("\n")); + return typeof callback === "function" ? callback() : void 0; + } + }); + +}).call(this); diff --git a/spec/javascripts/spec.js b/spec/javascripts/spec.js index 83c82a970..bf5b6286a 100644 --- a/spec/javascripts/spec.js +++ b/spec/javascripts/spec.js @@ -26,6 +26,7 @@ // Stuff we need to load first //= require_tree ../../app/assets/javascripts/discourse/mixins //= require ../../app/assets/javascripts/discourse/components/debounce +//= require ../../app/assets/javascripts/discourse/views/view //= require ../../app/assets/javascripts/discourse/controllers/controller //= require ../../app/assets/javascripts/discourse/views/modal/modal_body_view //= require ../../app/assets/javascripts/discourse/models/model