diff --git a/openslides/core/static/js/core/base.js b/openslides/core/static/js/core/base.js index d8ebf59db..00282d3da 100644 --- a/openslides/core/static/js/core/base.js +++ b/openslides/core/static/js/core/base.js @@ -80,9 +80,10 @@ angular.module('OpenSlidesApp.core', [ .factory('loadGlobalData', [ '$rootScope', '$http', + 'ChatMessage', 'Config', 'Projector', - function ($rootScope, $http, Config, Projector) { + function ($rootScope, $http, ChatMessage, Config, Projector) { return function () { // Puts the config object into each scope. Config.findAll().then(function() { @@ -100,6 +101,9 @@ angular.module('OpenSlidesApp.core', [ // Loads all projector data Projector.findAll(); + // Loads all chat messages data + ChatMessage.findAll(); + // Loads server time and calculates server offset $http.get('/core/servertime/').then(function(data) { $rootScope.serverOffset = Math.floor( Date.now() / 1000 - data.data ); @@ -181,6 +185,20 @@ angular.module('OpenSlidesApp.core', [ }); }]) +.factory('ChatMessage', ['DS', function(DS) { + return DS.defineResource({ + name: 'core/chatmessage', + relations: { + belongsTo: { + 'users/user': { + localField: 'user', + localKey: 'user_id', + } + } + } + }); +}]) + /* Model for a projector. * * At the moment we use only one projector, so there will be only one object @@ -258,6 +276,13 @@ angular.module('OpenSlidesApp.core', [ }) // Make sure that the DS factories are loaded by making them a dependency -.run(['Projector', 'Config', 'Tag', 'Customslide', function(Projector, Config, Tag, Customslide){}]); +.run([ + 'ChatMessage', + 'Config', + 'Customslide', + 'Projector', + 'Tag', + function (ChatMessage, Config, Customslide, Projector, Tag) {} +]); }()); diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index 5946bd4bd..ef1e9c913 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -752,6 +752,25 @@ angular.module('OpenSlidesApp.core.site', [ }; }) +// ChatMessage Controller +.controller('ChatMessageCtrl', [ + '$scope', + '$http', + 'ChatMessage', + function ($scope, $http, ChatMessage) { + ChatMessage.bindAll({}, $scope, 'chatmessages'); + $scope.sendMessage = function () { + $http.post( + '/rest/core/chatmessage/', + {message: $scope.newMessage} + ) + .success(function () { + $scope.newMessage = ''; + }); + }; + } +]) + .directive('osFocusMe', function ($timeout) { return { link: function (scope, element, attrs, model) { diff --git a/openslides/core/static/templates/index.html b/openslides/core/static/templates/index.html index 0281d79a1..eee8f230e 100644 --- a/openslides/core/static/templates/index.html +++ b/openslides/core/static/templates/index.html @@ -127,9 +127,10 @@ -