From 367404b20d4fc8c53620d29a3f4db2fb793f2dbf Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Wed, 24 Jun 2015 12:31:39 +0200 Subject: [PATCH] Added projector methods to user model --- openslides/core/static/js/core.js | 50 +++++++++++++------ openslides/users/static/js/users/users.js | 15 +++--- .../static/templates/users/user-list.html | 5 +- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/openslides/core/static/js/core.js b/openslides/core/static/js/core.js index 1cd4dfae4..6cda0b444 100644 --- a/openslides/core/static/js/core.js +++ b/openslides/core/static/js/core.js @@ -35,7 +35,7 @@ angular.module('OpenSlidesApp.core', []) }); }) -.run(function($rootScope, Config) { +.run(function($rootScope, Config, Projector) { // Puts the config object into each scope. // TODO: maybe rootscope.config has to set before findAll() is finished Config.findAll().then(function() { @@ -49,6 +49,9 @@ angular.module('OpenSlidesApp.core', []) } } }); + + // Loads all projector data + Projector.findAll(); }) .factory('autoupdate', function() { @@ -79,10 +82,38 @@ angular.module('OpenSlidesApp.core', []) return Autoupdate; }) -.factory('Customslide', function(DS) { +.factory('jsDataModel', function($http, Projector) { + var BaseModel = function() {}; + BaseModel.prototype.project = function() { + return $http.post( + '/rest/core/projector/1/prune_elements/', + [{name: this.getResourceName(), id: this.id}] + ); + } + BaseModel.prototype.isProjected = function() { + // Returns true if there is a projector element with the same + // name and the same id. + var projector = Projector.get(id=1); + var self = this; + return _.findIndex(projector.elements, function(element) { + return element.name == self.getResourceName() && + typeof(element.context.id) !== 'undefined' && + element.context.id == self.id; + }) > -1; + } + return BaseModel; +}) + +.factory('Customslide', function(DS, jsDataModel) { + var name = 'core/customslide' return DS.defineResource({ - name: 'core/customslide', - endpoint: '/rest/core/customslide/' + name: name, + endpoint: '/rest/core/customslide/', + methods: { + getResourceName: function () { + return name; + }, + }, }); }) @@ -294,17 +325,6 @@ angular.module('OpenSlidesApp.core.site', ['OpenSlidesApp.core']) editableOptions.theme = 'bs3'; }) -// Activate an Element from the Rest-API on the projector -// At the moment it only activates item on projector 1 -.factory('projectorActivate', function($http) { - return function(model, id) { - return $http.post( - '/rest/core/projector/1/prune_elements/', - [{name: model.name, id: id}] - ); - }; -}) - .controller("LanguageCtrl", function ($scope, gettextCatalog) { // controller to switch app language // TODO: detect browser language for default language diff --git a/openslides/users/static/js/users/users.js b/openslides/users/static/js/users/users.js index d64d347be..5093677e6 100644 --- a/openslides/users/static/js/users/users.js +++ b/openslides/users/static/js/users/users.js @@ -1,10 +1,15 @@ angular.module('OpenSlidesApp.users', []) -.factory('User', function(DS, Group) { +.factory('User', function(DS, Group, jsDataModel) { + var name = 'users/user' return DS.defineResource({ - name: 'users/user', + name: name, endpoint: '/rest/users/user/', + useClass: jsDataModel, methods: { + getResourceName: function () { + return name; + }, get_short_name: function() { // should be the same as in the python user model. var firstName = _.trim(this.first_name), @@ -280,7 +285,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) }; }]) -.controller('UserListCtrl', function($scope, User, projectorActivate) { +.controller('UserListCtrl', function($scope, User) { User.bindAll({}, $scope, 'users'); // setup table sorting @@ -305,10 +310,6 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) $scope.delete = function (user) { User.destroy(user.id); }; - - $scope.project = function(user) { - projectorActivate(User, user.id).error(function() {console.log('success')}); - }; }) .controller('UserDetailCtrl', function($scope, User, user) { diff --git a/openslides/users/static/templates/users/user-list.html b/openslides/users/static/templates/users/user-list.html index 08059d803..5ccd6053f 100644 --- a/openslides/users/static/templates/users/user-list.html +++ b/openslides/users/static/templates/users/user-list.html @@ -105,11 +105,10 @@ {{ user.groups }} {{ user.last_login | date:'yyyy-MM-dd HH:mm:ss'}} - - + projected