From 5374b2f398a3bb792186aa64eebf0d147529956f Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Tue, 21 Feb 2017 08:51:31 +0100 Subject: [PATCH] Collection name to CamelCase (fixes #2983) --- openslides/agenda/static/js/agenda/base.js | 11 ++++- openslides/agenda/static/js/agenda/site.js | 18 +------- .../static/templates/agenda/item-list.html | 2 +- openslides/core/static/js/core/base.js | 41 +++++++++++++++---- openslides/topics/static/js/topics/site.js | 2 - 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/openslides/agenda/static/js/agenda/base.js b/openslides/agenda/static/js/agenda/base.js index ac60aeb0e..8650742bc 100644 --- a/openslides/agenda/static/js/agenda/base.js +++ b/openslides/agenda/static/js/agenda/base.js @@ -55,7 +55,9 @@ angular.module('OpenSlidesApp.agenda', ['OpenSlidesApp.users']) 'Projector', 'gettextCatalog', 'gettext', - function($http, DS, Speaker, jsDataModel, Projector, gettextCatalog, gettext) { + 'CamelCase', + 'EditForm', + function($http, DS, Speaker, jsDataModel, Projector, gettextCatalog, gettext, CamelCase, EditForm) { var name = 'agenda/item'; return DS.defineResource({ name: name, @@ -68,6 +70,13 @@ angular.module('OpenSlidesApp.agenda', ['OpenSlidesApp.users']) getContentObject: function () { return DS.get(this.content_object.collection, this.content_object.id); }, + getContentObjectDetailState: function () { + return CamelCase(this.content_object.collection).replace('/', '.') + + '.detail({id: ' + this.content_object.id + '})'; + }, + getContentObjectForm: function () { + return EditForm.fromCollectionString(this.content_object.collection); + }, getContentResource: function () { return DS.definitions[this.content_object.collection]; }, diff --git a/openslides/agenda/static/js/agenda/site.js b/openslides/agenda/static/js/agenda/site.js index b99ddf073..9913c4baa 100644 --- a/openslides/agenda/static/js/agenda/site.js +++ b/openslides/agenda/static/js/agenda/site.js @@ -81,7 +81,6 @@ angular.module('OpenSlidesApp.agenda.site', [ '$filter', '$http', '$state', - '$injector', 'DS', 'operator', 'ngDialog', @@ -97,7 +96,7 @@ angular.module('OpenSlidesApp.agenda.site', [ 'osTableFilter', 'AgendaCsvExport', 'PdfCreate', - function($scope, $filter, $http, $state, $injector, DS, operator, ngDialog, Agenda, TopicForm, + function($scope, $filter, $http, $state, DS, operator, ngDialog, Agenda, TopicForm, AgendaTree, Projector, ProjectionDefault, AgendaContentProvider, PdfMakeDocumentProvider, gettextCatalog, gettext, osTableFilter, AgendaCsvExport, PdfCreate) { // Bind agenda tree to the scope @@ -269,21 +268,8 @@ angular.module('OpenSlidesApp.agenda.site', [ return false; } }; - $scope.getDetailStatePrefix = function (item) { - var prefix = item.content_object.collection.replace('/','.'); - // Hotfix for Issue 2566. - // The changes could be reverted if Issue 2480 is closed. - prefix = prefix.replace('motion-block', 'motionBlock'); - return prefix; - }; $scope.edit = function (item) { - var formName = item.content_object.collection.split('/')[1]; - // Hotfix for Issue 2566. - // The changes could be reverted if Issue 2480 is closed. - formName = formName.replace('motion-block', 'motionBlock'); - formName = formName.charAt(0).toUpperCase() + formName.slice(1) + 'Form'; - var form = $injector.get(formName); - ngDialog.open(form.getDialog({id: item.content_object.id})); + ngDialog.open(item.getContentObjectForm().getDialog({id: item.content_object.id})); }; // export $scope.pdfExport = function () { diff --git a/openslides/agenda/static/templates/agenda/item-list.html b/openslides/agenda/static/templates/agenda/item-list.html index 0ca7023d3..f2fc8f3f1 100644 --- a/openslides/agenda/static/templates/agenda/item-list.html +++ b/openslides/agenda/static/templates/agenda/item-list.html @@ -271,7 +271,7 @@
- + {{ item.getListViewTitle() }} diff --git a/openslides/core/static/js/core/base.js b/openslides/core/static/js/core/base.js index d52d34d14..05c8ef4c7 100644 --- a/openslides/core/static/js/core/base.js +++ b/openslides/core/static/js/core/base.js @@ -682,9 +682,9 @@ angular.module('OpenSlidesApp.core', [ .factory('Projector', [ 'DS', '$http', - '$injector', + 'EditForm', 'Config', - function(DS, $http, $injector, Config) { + function(DS, $http, EditForm, Config) { return DS.defineResource({ name: 'core/projector', onConflict: 'replace', @@ -716,14 +716,9 @@ angular.module('OpenSlidesApp.core', [ value.name != 'core/countdown' && value.name != 'core/projector-message' && value.name != 'agenda/current-list-of-speakers' ) { - var formName = value.name.split('/')[1]; - // Hotfix for Issue 2566. - // The changes could be reverted if Issue 2480 is closed. - formName = formName.replace('motion-block', 'motionBlock'); - formName = formName.charAt(0).toUpperCase() + formName.slice(1) + 'Form'; return_dict = { - form: $injector.get(formName), - id: value.id + form: EditForm.fromCollectionString(value.name), + id: value.id, }; } }); @@ -953,6 +948,34 @@ angular.module('OpenSlidesApp.core', [ } ]) +/* Converts a snake-case string to camelCase. Example: + * 'motion-block-config' -> 'motionBlockConfig' */ +.factory('CamelCase', [ + function () { + return function (str) { + return str.replace(/-([a-z])/g, function (match) { + return match[1].toUpperCase(); + }); + }; + } +]) + +/* Return the specific EditForm for a given model. */ +.factory('EditForm', [ + '$injector', + 'CamelCase', + function ($injector, CamelCase) { + return { + fromCollectionString: function (collection) { + var modelName = CamelCase(collection).split('/')[1]; + // Convert modelModel to ModelModelForm + var formName = modelName.charAt(0).toUpperCase() + modelName.slice(1) + 'Form'; + return $injector.get(formName); + }, + }; + } +]) + /* Converts number of seconds into string "h:mm:ss" or "mm:ss" */ .filter('osSecondsToTime', [ 'HumanTimeConverter', diff --git a/openslides/topics/static/js/topics/site.js b/openslides/topics/static/js/topics/site.js index 440d0238c..fe8d2beb5 100644 --- a/openslides/topics/static/js/topics/site.js +++ b/openslides/topics/static/js/topics/site.js @@ -17,9 +17,7 @@ angular.module('OpenSlidesApp.topics.site', ['OpenSlidesApp.topics', 'OpenSlides title: gettext('Topics'), }, }) - .state('topics.topic', { - url: '/topic', abstract: true, template: "", })