From b1dfd2a4e912f22950e03c4b23f454b3501edcfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Mon, 21 Sep 2015 22:02:23 +0200 Subject: [PATCH] Added first chatbox draft on client side. --- openslides/core/static/js/core/base.js | 29 +++++++++++++++-- openslides/core/static/js/core/site.js | 19 +++++++++++ openslides/core/static/templates/index.html | 36 ++++++++++++++------- 3 files changed, 70 insertions(+), 14 deletions(-) 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 @@ -
+
-
@@ -146,16 +146,28 @@
-
-
+ +
+
    +
  • + {{ chatmessage.user.get_full_name() }} says {{ chatmessage.message }} on {{ chatmessage.timestamp }} +
+ + +
+ +
+