From a2db90289a637ce6a64ac9e18914946bd3ffb8c1 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 23 May 2013 12:12:33 +0000 Subject: [PATCH] Create SoundManager model in Chat JS Application It help to unbind messages collection view and message form model --- .../collection_views/messages_collection.js | 3 +- .../chat/model_views/controls/sound.js | 2 +- .../js/compiled/chat/models/controls/sound.js | 2 +- .../chat/models/sound_managers/base.js | 8 ++ .../chat/models/sound_managers/chat.js | 9 +++ .../webim/js/compiled/chat/modules/chat.js | 8 +- src/messenger/webim/js/compiled/chat_app.js | 30 ++++++-- .../collection_views/messages_collection.js | 47 +----------- .../source/chat/model_views/controls/sound.js | 4 +- .../js/source/chat/models/controls/sound.js | 13 ++++ .../source/chat/models/sound_managers/base.js | 40 ++++++++++ .../source/chat/models/sound_managers/chat.js | 75 +++++++++++++++++++ .../webim/js/source/chat/modules/chat.js | 1 + 13 files changed, 177 insertions(+), 65 deletions(-) create mode 100644 src/messenger/webim/js/compiled/chat/models/sound_managers/base.js create mode 100644 src/messenger/webim/js/compiled/chat/models/sound_managers/chat.js create mode 100644 src/messenger/webim/js/source/chat/models/sound_managers/base.js create mode 100644 src/messenger/webim/js/source/chat/models/sound_managers/chat.js diff --git a/src/messenger/webim/js/compiled/chat/collection_views/messages_collection.js b/src/messenger/webim/js/compiled/chat/collection_views/messages_collection.js index 74444f89..3485c078 100644 --- a/src/messenger/webim/js/compiled/chat/collection_views/messages_collection.js +++ b/src/messenger/webim/js/compiled/chat/collection_views/messages_collection.js @@ -5,5 +5,4 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(a){a.Views.MessagesCollection=a.Views.CollectionBase.extend({itemView:a.Views.Message,className:"messages-collection",initialize:function(){this.collection.on("multiple:add",this.messagesAdded,this);a.Objects.Models.messageForm.on("before:post",this.messagePost,this)},skipNextSound:!0,messagePost:function(){this.skipNextSound=!0},messagesAdded:function(){if(!this.skipNextSound&&a.Objects.Models.Controls.sound.get("enabled")){var b=a.Objects.Models.page.get("webimRoot");b&&a.Utils.playSound(b+ -"/sounds/new_message.wav")}this.skipNextSound=!1}})})(Mibew); +(function(a){a.Views.MessagesCollection=a.Views.CollectionBase.extend({itemView:a.Views.Message,className:"messages-collection"})})(Mibew); diff --git a/src/messenger/webim/js/compiled/chat/model_views/controls/sound.js b/src/messenger/webim/js/compiled/chat/model_views/controls/sound.js index 3c1e1e4b..ae0b98b2 100644 --- a/src/messenger/webim/js/compiled/chat/model_views/controls/sound.js +++ b/src/messenger/webim/js/compiled/chat/model_views/controls/sound.js @@ -5,4 +5,4 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(a,b,c){a.Views.SoundControl=a.Views.Control.extend({template:b.templates.chat_controls_sound,events:c.extend({},a.Views.Control.prototype.events,{click:"toggle"}),toggle:function(){this.model.set({enabled:!this.model.get("enabled")})}})})(Mibew,Handlebars,_); +(function(a,b,c){a.Views.SoundControl=a.Views.Control.extend({template:b.templates.chat_controls_sound,events:c.extend({},a.Views.Control.prototype.events,{click:"toggle"}),toggle:function(){this.model.toggle()}})})(Mibew,Handlebars,_); diff --git a/src/messenger/webim/js/compiled/chat/models/controls/sound.js b/src/messenger/webim/js/compiled/chat/models/controls/sound.js index cd0d5d21..409cf863 100644 --- a/src/messenger/webim/js/compiled/chat/models/controls/sound.js +++ b/src/messenger/webim/js/compiled/chat/models/controls/sound.js @@ -5,4 +5,4 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(a,b){a.Models.SoundControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{enabled:!0}),getModelType:function(){return"SoundControl"}})})(Mibew,_); +(function(a,c){a.Models.SoundControl=a.Models.Control.extend({defaults:c.extend({},a.Models.Control.prototype.defaults,{enabled:!0}),toggle:function(){var b=!this.get("enabled");a.Objects.Models.soundManager.set({enabled:b});this.set({enabled:b})},getModelType:function(){return"SoundControl"}})})(Mibew,_); diff --git a/src/messenger/webim/js/compiled/chat/models/sound_managers/base.js b/src/messenger/webim/js/compiled/chat/models/sound_managers/base.js new file mode 100644 index 00000000..dcbc825d --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/models/sound_managers/base.js @@ -0,0 +1,8 @@ +/* + Copyright 2005-2013 the original author or authors. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +*/ +(function(b,a){b.Models.BaseSoundManager=a.Model.extend({defaults:{enabled:!0},play:function(a){this.get("enabled")&&b.Utils.playSound(a)}})})(Mibew,Backbone); diff --git a/src/messenger/webim/js/compiled/chat/models/sound_managers/chat.js b/src/messenger/webim/js/compiled/chat/models/sound_managers/chat.js new file mode 100644 index 00000000..aedc5653 --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/models/sound_managers/chat.js @@ -0,0 +1,9 @@ +/* + Copyright 2005-2013 the original author or authors. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +*/ +(function(a,c){a.Models.ChatSoundManager=a.Models.BaseSoundManager.extend({defaults:c.extend({},a.Models.BaseSoundManager.prototype.defaults,{skipNextMessageSound:!1}),initialize:function(){var b=a.Objects,c=this;b.Collections.messages.on("multiple:add",this.playNewMessageSound,this);b.Models.messageForm.on("before:post",function(){c.set({skipNextMessageSound:!0})})},playNewMessageSound:function(){if(!this.get("skipNextMessageSound")){var b=a.Objects.Models.page.get("webimRoot");b&&this.play(b+"/sounds/new_message.wav")}this.set({skipNextMessageSound:!1})}})})(Mibew, +_); diff --git a/src/messenger/webim/js/compiled/chat/modules/chat.js b/src/messenger/webim/js/compiled/chat/modules/chat.js index 16698c41..b33308e0 100644 --- a/src/messenger/webim/js/compiled/chat/modules/chat.js +++ b/src/messenger/webim/js/compiled/chat/modules/chat.js @@ -8,7 +8,7 @@ (function(a){a.Objects.Models.Controls={};a.Objects.Models.Status={};var j=[],l=a.Application,k=l.module("Chat",{startWithParent:!1});k.addInitializer(function(b){var f=a.Objects,d=a.Objects.Models,c=a.Objects.Models.Controls,h=a.Objects.Models.Status;b.page&&d.page.set(b.page);d.thread=new a.Models.Thread(b.thread);d.user=new a.Models.ChatUser(b.user);var g=new a.Layouts.Chat;f.chatLayout=g;l.mainRegion.show(g);var e=new a.Collections.Controls;d.user.get("isAgent")||(c.userName=new a.Models.UserNameControl({weight:220}), e.add(c.userName),c.sendMail=new a.Models.SendMailControl({weight:200,link:b.links.mail,windowParams:b.windowsParams.mail}),e.add(c.sendMail));d.user.get("isAgent")&&(c.redirect=new a.Models.RedirectControl({weight:200,link:b.links.redirect}),e.add(c.redirect),c.history=new a.Models.HistoryControl({weight:180,link:b.links.history,windowParams:b.windowsParams.history}),e.add(c.history));c.sound=new a.Models.SoundControl({weight:160});e.add(c.sound);c.refresh=new a.Models.RefreshControl({weight:140}); e.add(c.refresh);b.links.ssl&&(c.secureMode=new a.Models.SecureModeControl({weight:120,link:b.links.ssl}),e.add(c.secureMode));c.close=new a.Models.CloseControl({weight:100});e.add(c.close);f.Collections.controls=e;g.controlsRegion.show(new a.Views.ControlsCollection({collection:e}));h.message=new a.Models.StatusMessage({hideTimeout:5E3});h.typing=new a.Models.StatusTyping({hideTimeout:5E3});f.Collections.status=new a.Collections.Status([h.message,h.typing]);g.statusRegion.show(new a.Views.StatusCollection({collection:f.Collections.status})); -d.user.get("isAgent")||(d.avatar=new a.Models.Avatar,g.avatarRegion.show(new a.Views.Avatar({model:d.avatar})));f.Collections.messages=new a.Collections.Messages;d.messageForm=new a.Models.MessageForm(b.messageForm);g.messageFormRegion.show(new a.Views.MessageForm({model:d.messageForm}));g.messagesRegion.show(new a.Views.MessagesCollection({collection:f.Collections.messages}));j.push(f.server.callFunctionsPeriodically(function(){var b=a.Objects.Models.thread,c=a.Objects.Models.user;return[{"function":"update", -arguments:{"return":{typing:"typing",canPost:"canPost"},references:{},threadId:b.get("id"),token:b.get("token"),lastId:b.get("lastId"),typed:c.get("typing"),user:!c.get("isAgent")}}]},function(b){b.errorCode?a.Objects.Models.Status.message.setMessage(b.errorMessage||"refresh failed"):(b.typing&&a.Objects.Models.Status.typing.show(),a.Objects.Models.user.set({canPost:b.canPost||!1}))}))});k.on("start",function(){a.Objects.server.restartUpdater()});k.addFinalizer(function(){a.Objects.chatLayout.close(); -for(var b=0;b