From 7bffeba93ea54e3d79af13344a4b5940f979df66 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Wed, 9 Dec 2015 20:02:08 +0100 Subject: [PATCH] Project related object (Fixes #1704) - Override generic project and isProjected function in agenda. - Fix project and isProjected function for list of speakers and move to jsDataModel of Agenda. --- openslides/agenda/static/js/agenda/base.js | 32 ++++++++++++++++++- openslides/agenda/static/js/agenda/site.js | 14 -------- .../static/templates/agenda/item-detail.html | 6 ++-- .../static/templates/agenda/item-list.html | 2 +- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/openslides/agenda/static/js/agenda/base.js b/openslides/agenda/static/js/agenda/base.js index 12da9bc59..40053d9e7 100644 --- a/openslides/agenda/static/js/agenda/base.js +++ b/openslides/agenda/static/js/agenda/base.js @@ -22,12 +22,13 @@ angular.module('OpenSlidesApp.agenda', ['OpenSlidesApp.users']) ]) .factory('Agenda', [ + '$http', 'DS', 'Speaker', 'jsDataModel', 'Projector', 'gettextCatalog', - function(DS, Speaker, jsDataModel, Projector, gettextCatalog) { + function($http, DS, Speaker, jsDataModel, Projector, gettextCatalog) { var name = 'agenda/item'; return DS.defineResource({ name: name, @@ -56,6 +57,14 @@ angular.module('OpenSlidesApp.agenda', ['OpenSlidesApp.users']) } return title; }, + // override project function of jsDataModel factory + project: function() { + return $http.post( + '/rest/core/projector/1/prune_elements/', + [{name: this.content_object.collection, id: this.content_object.id}] + ); + }, + // override isProjected function of jsDataModel factory isProjected: function () { var projector = Projector.get(1); if (typeof projector === 'undefined') return false; @@ -66,6 +75,27 @@ angular.module('OpenSlidesApp.agenda', ['OpenSlidesApp.users']) element.id == self.content_object.id; }; return typeof _.findKey(projector.elements, predicate) === 'string'; + }, + // project list of speakers + projectListOfSpeakers: function() { + return $http.post( + '/rest/core/projector/1/prune_elements/', + [{name: 'agenda/item', id: this.id, list_of_speakers: true}] + ); + }, + // check if list of speakers is projected + isListOfSpeakersProjected: function () { + // Returns true if there is a projector element with the same + // name and agenda is active. + var projector = Projector.get(1); + if (typeof projector === 'undefined') return false; + var self = this; + var predicate = function (element) { + return element.name == 'agenda/item' && + element.id == self.id && + element.list_of_speakers; + }; + return typeof _.findKey(projector.elements, predicate) === 'string'; } }, relations: { diff --git a/openslides/agenda/static/js/agenda/site.js b/openslides/agenda/static/js/agenda/site.js index 42f6766d4..075c55d1c 100644 --- a/openslides/agenda/static/js/agenda/site.js +++ b/openslides/agenda/static/js/agenda/site.js @@ -86,15 +86,6 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) $scope.alert = {}; $scope.isFilter = true; - // project related item (content object) - $scope.project = function (item) { - item.getContentResource().find(item.content_object.id).then( - function(object) { - object.project(); - } - ); - }; - // open new dialog $scope.newDialog = function () { ngDialog.open({ @@ -244,11 +235,6 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) $scope.alert = { type: 'danger', msg: data.detail, show: true }; }); }; - // project list of speakers - $scope.projectListOfSpeakers = function () { - $http.post('/rest/core/projector/1/prune_elements/', - [{name: 'agenda/item', id: item.id, list_of_speakers: true}]); - }; } ]) diff --git a/openslides/agenda/static/templates/agenda/item-detail.html b/openslides/agenda/static/templates/agenda/item-detail.html index 213896fcb..876dd642e 100644 --- a/openslides/agenda/static/templates/agenda/item-detail.html +++ b/openslides/agenda/static/templates/agenda/item-detail.html @@ -5,10 +5,10 @@ Back to agenda - + + ng-class="{ 'btn-primary': item.isListOfSpeakersProjected() }" + ng-click="item.projectListOfSpeakers()"> List of speakers diff --git a/openslides/agenda/static/templates/agenda/item-list.html b/openslides/agenda/static/templates/agenda/item-list.html index 7e1b2c7d6..5a328645f 100644 --- a/openslides/agenda/static/templates/agenda/item-list.html +++ b/openslides/agenda/static/templates/agenda/item-list.html @@ -123,7 +123,7 @@