mirror of
				https://github.com/Mibew/i18n.git
				synced 2025-11-01 01:36:57 +03:00 
			
		
		
		
	Create chat module in Chat JavaScript application
This commit is contained in:
		
							parent
							
								
									8f1db81e83
								
							
						
					
					
						commit
						e4844832f1
					
				| @ -5,9 +5,4 @@ | ||||
|  Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  License: http://mibew.org/license.php
 | ||||
| */ | ||||
| (function(a,k){var h=a.Application;h.addRegions({mainRegion:"#main-region"});h.addInitializer(function(d){var g=a.Objects,c=a.Objects.Models,b=a.Objects.Models.Controls,j=a.Objects.Models.Status,f=new a.Layouts.Chat({model:new Backbone.Model(d.layoutsData.chat||{})});a.Objects.chatLayout=f;h.mainRegion.show(f);g.server=new a.Server(k.extend({interactionType:MibewAPIChatInteraction},d.server));c.thread=new a.Models.Thread(d.thread);c.user=new a.Models.ChatUser(d.user);c.page=new a.Models.Page(d.page); | ||||
| var e=new a.Collections.Controls;c.user.get("isAgent")||(b.userName=new a.Models.UserNameControl({weight:220}),e.add(b.userName),b.sendMail=new a.Models.SendMailControl({weight:200,link:d.links.mailLink}),e.add(b.sendMail));c.user.get("isAgent")&&(b.redirect=new a.Models.RedirectControl({weight:200,link:d.links.redirectLink}),e.add(b.redirect),b.history=new a.Models.HistoryControl({weight:180,link:d.links.historyLink}),e.add(b.history));b.sound=new a.Models.SoundControl({weight:160});e.add(b.sound); | ||||
| b.refresh=new a.Models.RefreshControl({weight:140});e.add(b.refresh);d.links.sslLink&&(b.secureMode=new a.Models.SecureModeControl({weight:120,link:d.links.sslLink}),e.add(b.secureMode));b.close=new a.Models.CloseControl({weight:100});e.add(b.close);g.Collections.controls=e;f.controlsRegion.show(new a.Views.ControlsCollection({collection:e}));j.message=new a.Models.StatusMessage({hideTimeout:5E3});j.typing=new a.Models.StatusTyping({hideTimeout:5E3});g.Collections.status=new a.Collections.Status([j.message, | ||||
| j.typing]);f.statusRegion.show(new a.Views.StatusCollection({collection:g.Collections.status}));c.user.get("isAgent")||(c.avatar=new a.Models.Avatar,f.avatarRegion.show(new a.Views.Avatar({model:c.avatar})));g.Collections.messages=new a.Collections.Messages;c.messageForm=new a.Models.MessageForm(d.messageForm);f.messageFormRegion.show(new a.Views.MessageForm({model:c.messageForm}));f.messagesRegion.show(new a.Views.MessagesCollection({collection:g.Collections.messages}));c.sound=new a.Models.Sound; | ||||
| f.soundRegion.show(new a.Views.Sound({model:c.sound}));g.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}))})});h.on("start",function(){a.Objects.server.runUpdater()})})(Mibew,_); | ||||
| (function(a,d){var b=a.Application;b.addRegions({mainRegion:"#main-region"});b.addInitializer(function(c){a.Objects.server=new a.Server(d.extend({interactionType:MibewAPIChatInteraction},c.server));b.Chat.start(c)});b.on("start",function(){a.Objects.server.runUpdater()})})(Mibew,_); | ||||
|  | ||||
| @ -5,4 +5,4 @@ | ||||
|  Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  License: http://mibew.org/license.php
 | ||||
| */ | ||||
| (function(a){a.Regions={};a.Layouts={};a.Objects.Models.Controls={};a.Objects.Models.Status={};a.Application=new Backbone.Marionette.Application})(Mibew); | ||||
| (function(a){a.Regions={};a.Layouts={};a.Application=new Backbone.Marionette.Application})(Mibew); | ||||
|  | ||||
							
								
								
									
										12
									
								
								src/messenger/webim/js/compiled/chat/modules/chat.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/messenger/webim/js/compiled/chat/modules/chat.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| /* | ||||
|  This file is part of Mibew Messenger project. | ||||
|  http://mibew.org
 | ||||
| 
 | ||||
|  Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  License: http://mibew.org/license.php
 | ||||
| */ | ||||
| (function(a){a.Objects.Models.Controls={};a.Objects.Models.Status={};var j=a.Application;j.module("Chat",{startWithParent:!1}).addInitializer(function(d){var g=a.Objects,c=a.Objects.Models,b=a.Objects.Models.Controls,h=a.Objects.Models.Status,f=new a.Layouts.Chat({model:new Backbone.Model(d.layoutsData.chat||{})});a.Objects.chatLayout=f;j.mainRegion.show(f);c.thread=new a.Models.Thread(d.thread);c.user=new a.Models.ChatUser(d.user);c.page=new a.Models.Page(d.page);var e=new a.Collections.Controls; | ||||
| c.user.get("isAgent")||(b.userName=new a.Models.UserNameControl({weight:220}),e.add(b.userName),b.sendMail=new a.Models.SendMailControl({weight:200,link:d.links.mailLink}),e.add(b.sendMail));c.user.get("isAgent")&&(b.redirect=new a.Models.RedirectControl({weight:200,link:d.links.redirectLink}),e.add(b.redirect),b.history=new a.Models.HistoryControl({weight:180,link:d.links.historyLink}),e.add(b.history));b.sound=new a.Models.SoundControl({weight:160});e.add(b.sound);b.refresh=new a.Models.RefreshControl({weight:140}); | ||||
| e.add(b.refresh);d.links.sslLink&&(b.secureMode=new a.Models.SecureModeControl({weight:120,link:d.links.sslLink}),e.add(b.secureMode));b.close=new a.Models.CloseControl({weight:100});e.add(b.close);g.Collections.controls=e;f.controlsRegion.show(new a.Views.ControlsCollection({collection:e}));h.message=new a.Models.StatusMessage({hideTimeout:5E3});h.typing=new a.Models.StatusTyping({hideTimeout:5E3});g.Collections.status=new a.Collections.Status([h.message,h.typing]);f.statusRegion.show(new a.Views.StatusCollection({collection:g.Collections.status})); | ||||
| c.user.get("isAgent")||(c.avatar=new a.Models.Avatar,f.avatarRegion.show(new a.Views.Avatar({model:c.avatar})));g.Collections.messages=new a.Collections.Messages;c.messageForm=new a.Models.MessageForm(d.messageForm);f.messageFormRegion.show(new a.Views.MessageForm({model:c.messageForm}));f.messagesRegion.show(new a.Views.MessagesCollection({collection:g.Collections.messages}));c.sound=new a.Models.Sound;f.soundRegion.show(new a.Views.Sound({model:c.sound}));g.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}))})})})(Mibew); | ||||
| @ -4,7 +4,7 @@ | ||||
|  Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  License: http://mibew.org/license.php
 | ||||
| */ | ||||
| (function(a){a.Regions={};a.Layouts={};a.Objects.Models.Controls={};a.Objects.Models.Status={};a.Application=new Backbone.Marionette.Application})(Mibew); | ||||
| (function(a){a.Regions={};a.Layouts={};a.Application=new Backbone.Marionette.Application})(Mibew); | ||||
| /* | ||||
|  This file is part of Mibew Messenger project. | ||||
|  http://mibew.org
 | ||||
| @ -256,9 +256,15 @@ c=""!=this.ui.message.val();c!=a.get("typing")&&a.set({typing:c})},setFocus:func | ||||
|  Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  License: http://mibew.org/license.php
 | ||||
| */ | ||||
| (function(a,k){var h=a.Application;h.addRegions({mainRegion:"#main-region"});h.addInitializer(function(d){var g=a.Objects,c=a.Objects.Models,b=a.Objects.Models.Controls,j=a.Objects.Models.Status,f=new a.Layouts.Chat({model:new Backbone.Model(d.layoutsData.chat||{})});a.Objects.chatLayout=f;h.mainRegion.show(f);g.server=new a.Server(k.extend({interactionType:MibewAPIChatInteraction},d.server));c.thread=new a.Models.Thread(d.thread);c.user=new a.Models.ChatUser(d.user);c.page=new a.Models.Page(d.page); | ||||
| var e=new a.Collections.Controls;c.user.get("isAgent")||(b.userName=new a.Models.UserNameControl({weight:220}),e.add(b.userName),b.sendMail=new a.Models.SendMailControl({weight:200,link:d.links.mailLink}),e.add(b.sendMail));c.user.get("isAgent")&&(b.redirect=new a.Models.RedirectControl({weight:200,link:d.links.redirectLink}),e.add(b.redirect),b.history=new a.Models.HistoryControl({weight:180,link:d.links.historyLink}),e.add(b.history));b.sound=new a.Models.SoundControl({weight:160});e.add(b.sound); | ||||
| b.refresh=new a.Models.RefreshControl({weight:140});e.add(b.refresh);d.links.sslLink&&(b.secureMode=new a.Models.SecureModeControl({weight:120,link:d.links.sslLink}),e.add(b.secureMode));b.close=new a.Models.CloseControl({weight:100});e.add(b.close);g.Collections.controls=e;f.controlsRegion.show(new a.Views.ControlsCollection({collection:e}));j.message=new a.Models.StatusMessage({hideTimeout:5E3});j.typing=new a.Models.StatusTyping({hideTimeout:5E3});g.Collections.status=new a.Collections.Status([j.message, | ||||
| j.typing]);f.statusRegion.show(new a.Views.StatusCollection({collection:g.Collections.status}));c.user.get("isAgent")||(c.avatar=new a.Models.Avatar,f.avatarRegion.show(new a.Views.Avatar({model:c.avatar})));g.Collections.messages=new a.Collections.Messages;c.messageForm=new a.Models.MessageForm(d.messageForm);f.messageFormRegion.show(new a.Views.MessageForm({model:c.messageForm}));f.messagesRegion.show(new a.Views.MessagesCollection({collection:g.Collections.messages}));c.sound=new a.Models.Sound; | ||||
| f.soundRegion.show(new a.Views.Sound({model:c.sound}));g.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}))})});h.on("start",function(){a.Objects.server.runUpdater()})})(Mibew,_); | ||||
| (function(a){a.Objects.Models.Controls={};a.Objects.Models.Status={};var j=a.Application;j.module("Chat",{startWithParent:!1}).addInitializer(function(d){var g=a.Objects,c=a.Objects.Models,b=a.Objects.Models.Controls,h=a.Objects.Models.Status,f=new a.Layouts.Chat({model:new Backbone.Model(d.layoutsData.chat||{})});a.Objects.chatLayout=f;j.mainRegion.show(f);c.thread=new a.Models.Thread(d.thread);c.user=new a.Models.ChatUser(d.user);c.page=new a.Models.Page(d.page);var e=new a.Collections.Controls; | ||||
| c.user.get("isAgent")||(b.userName=new a.Models.UserNameControl({weight:220}),e.add(b.userName),b.sendMail=new a.Models.SendMailControl({weight:200,link:d.links.mailLink}),e.add(b.sendMail));c.user.get("isAgent")&&(b.redirect=new a.Models.RedirectControl({weight:200,link:d.links.redirectLink}),e.add(b.redirect),b.history=new a.Models.HistoryControl({weight:180,link:d.links.historyLink}),e.add(b.history));b.sound=new a.Models.SoundControl({weight:160});e.add(b.sound);b.refresh=new a.Models.RefreshControl({weight:140}); | ||||
| e.add(b.refresh);d.links.sslLink&&(b.secureMode=new a.Models.SecureModeControl({weight:120,link:d.links.sslLink}),e.add(b.secureMode));b.close=new a.Models.CloseControl({weight:100});e.add(b.close);g.Collections.controls=e;f.controlsRegion.show(new a.Views.ControlsCollection({collection:e}));h.message=new a.Models.StatusMessage({hideTimeout:5E3});h.typing=new a.Models.StatusTyping({hideTimeout:5E3});g.Collections.status=new a.Collections.Status([h.message,h.typing]);f.statusRegion.show(new a.Views.StatusCollection({collection:g.Collections.status})); | ||||
| c.user.get("isAgent")||(c.avatar=new a.Models.Avatar,f.avatarRegion.show(new a.Views.Avatar({model:c.avatar})));g.Collections.messages=new a.Collections.Messages;c.messageForm=new a.Models.MessageForm(d.messageForm);f.messageFormRegion.show(new a.Views.MessageForm({model:c.messageForm}));f.messagesRegion.show(new a.Views.MessagesCollection({collection:g.Collections.messages}));c.sound=new a.Models.Sound;f.soundRegion.show(new a.Views.Sound({model:c.sound}));g.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}))})})})(Mibew); | ||||
| /* | ||||
|  This file is part of Mibew Messenger project. | ||||
|  http://mibew.org
 | ||||
|  Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  License: http://mibew.org/license.php
 | ||||
| */ | ||||
| (function(a,d){var b=a.Application;b.addRegions({mainRegion:"#main-region"});b.addInitializer(function(c){a.Objects.server=new a.Server(d.extend({interactionType:MibewAPIChatInteraction},c.server));b.Chat.start(c)});b.on("start",function(){a.Objects.server.runUpdater()})})(Mibew,_); | ||||
|  | ||||
| @ -9,217 +9,26 @@ | ||||
| (function (Mibew, _) { | ||||
| 
 | ||||
|     // Create shortcut for application
 | ||||
|     var App = Mibew.Application; | ||||
|     var app = Mibew.Application; | ||||
| 
 | ||||
|     // Define regions
 | ||||
|     App.addRegions({ | ||||
|     app.addRegions({ | ||||
|         mainRegion: '#main-region' | ||||
|     }); | ||||
| 
 | ||||
|     // Initialize application
 | ||||
|     App.addInitializer(function(options){ | ||||
|         // Create some shortcuts
 | ||||
|         var objs = Mibew.Objects; | ||||
|         var models = Mibew.Objects.Models; | ||||
|         var controls = Mibew.Objects.Models.Controls; | ||||
|         var status = Mibew.Objects.Models.Status; | ||||
| 
 | ||||
|         // Create instance of the chat layout
 | ||||
|         // Use undocumented feature of layouts: passing model to layout
 | ||||
|         var layout = new Mibew.Layouts.Chat({ | ||||
|             model: new Backbone.Model(options.layoutsData.chat || {}) | ||||
|         }); | ||||
|         Mibew.Objects.chatLayout = layout; | ||||
| 
 | ||||
|         // Show layout at page
 | ||||
|         App.mainRegion.show(layout); | ||||
| 
 | ||||
|     app.addInitializer(function(options){ | ||||
|         // Initialize Server, Thread and User
 | ||||
|         objs.server = new Mibew.Server(_.extend( | ||||
|         Mibew.Objects.server = new Mibew.Server(_.extend( | ||||
|             { | ||||
|                 'interactionType': MibewAPIChatInteraction | ||||
|             }, | ||||
|             options.server | ||||
|         )); | ||||
|         models.thread = new Mibew.Models.Thread(options.thread); | ||||
|         models.user = new Mibew.Models.ChatUser(options.user); | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize Page
 | ||||
|         models.page = new Mibew.Models.Page(options.page); | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize controls
 | ||||
|         // Create controls collection
 | ||||
|         var ctrlsCollection = new Mibew.Collections.Controls(); | ||||
| 
 | ||||
|         // Create controls only for user
 | ||||
|         if (! models.user.get('isAgent')) { | ||||
|             // Create user name control
 | ||||
|             controls.userName = new Mibew.Models.UserNameControl({ | ||||
|                 weight: 220 | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.userName); | ||||
| 
 | ||||
|             // Create mail control
 | ||||
|             controls.sendMail = new Mibew.Models.SendMailControl({ | ||||
|                 weight: 200, | ||||
|                 link: options.links.mailLink | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.sendMail); | ||||
|         } | ||||
| 
 | ||||
|         // Create controls only for agent
 | ||||
|         if (models.user.get('isAgent')) { | ||||
|             controls.redirect = new Mibew.Models.RedirectControl({ | ||||
|                 weight: 200, | ||||
|                 link: options.links.redirectLink | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.redirect); | ||||
| 
 | ||||
|             controls.history = new Mibew.Models.HistoryControl({ | ||||
|                 weight: 180, | ||||
|                 link: options.links.historyLink | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.history); | ||||
|         } | ||||
| 
 | ||||
|         // Create toggle sound button
 | ||||
|         controls.sound = new Mibew.Models.SoundControl({ | ||||
|             weight: 160 | ||||
|         }); | ||||
|         ctrlsCollection.add(controls.sound); | ||||
| 
 | ||||
|         // Create refresh button
 | ||||
|         controls.refresh = new Mibew.Models.RefreshControl({ | ||||
|             weight: 140 | ||||
|         }); | ||||
|         ctrlsCollection.add(controls.refresh); | ||||
| 
 | ||||
|         if (options.links.sslLink) { | ||||
|             controls.secureMode = new Mibew.Models.SecureModeControl({ | ||||
|                 weight: 120, | ||||
|                 link: options.links.sslLink | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.secureMode); | ||||
|         } | ||||
| 
 | ||||
|         // Create close button
 | ||||
|         controls.close = new Mibew.Models.CloseControl({ | ||||
|             weight: 100 | ||||
|         }); | ||||
|         ctrlsCollection.add(controls.close); | ||||
| 
 | ||||
|         objs.Collections.controls = ctrlsCollection; | ||||
| 
 | ||||
|         // Display controls
 | ||||
|         layout.controlsRegion.show(new Mibew.Views.ControlsCollection({ | ||||
|             collection: ctrlsCollection | ||||
|         })); | ||||
| 
 | ||||
| 
 | ||||
|         // Iniitialize status bar
 | ||||
|         // Create status message model
 | ||||
|         status.message = new Mibew.Models.StatusMessage({hideTimeout: 5000}); | ||||
| 
 | ||||
|         // Create typing status model
 | ||||
|         status.typing = new Mibew.Models.StatusTyping({hideTimeout: 5000}); | ||||
| 
 | ||||
|         // Create status collection
 | ||||
|         objs.Collections.status = new Mibew.Collections.Status([ | ||||
|             status.message, | ||||
|             status.typing | ||||
|         ]); | ||||
| 
 | ||||
|         // Display status bar
 | ||||
|         layout.statusRegion.show(new Mibew.Views.StatusCollection({ | ||||
|             collection: objs.Collections.status | ||||
|         })); | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize avatar only for user
 | ||||
|         if (! models.user.get('isAgent')) { | ||||
|             models.avatar = new Mibew.Models.Avatar(); | ||||
|             layout.avatarRegion.show(new Mibew.Views.Avatar({ | ||||
|                 model: models.avatar | ||||
|             })); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize chat window
 | ||||
|         // Create messages collection and store it
 | ||||
|         objs.Collections.messages = new Mibew.Collections.Messages(); | ||||
| 
 | ||||
|         // Create message processor model
 | ||||
|         models.messageForm = new Mibew.Models.MessageForm( | ||||
|             options.messageForm | ||||
|         ); | ||||
| 
 | ||||
|         // Display message processor
 | ||||
|         layout.messageFormRegion.show(new Mibew.Views.MessageForm({ | ||||
|             model: models.messageForm | ||||
|         })); | ||||
| 
 | ||||
|         // Display messages
 | ||||
|         layout.messagesRegion.show(new Mibew.Views.MessagesCollection({ | ||||
|             collection: objs.Collections.messages | ||||
|         })); | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize sounds
 | ||||
|         models.sound = new Mibew.Models.Sound(); | ||||
|         layout.soundRegion.show(new Mibew.Views.Sound({ | ||||
|             model: models.sound | ||||
|         })); | ||||
| 
 | ||||
|         // TODO: May be move it somewhere else
 | ||||
|         // Periodically call update function at the server side
 | ||||
|         objs.server.callFunctionsPeriodically( | ||||
|             function() { | ||||
|                 // Get thread and user objects
 | ||||
|                 var thread = Mibew.Objects.Models.thread; | ||||
|                 var user = Mibew.Objects.Models.user; | ||||
| 
 | ||||
|                 // Build functions list
 | ||||
|                 return [ | ||||
|                     { | ||||
|                         "function": "update", | ||||
|                         "arguments": { | ||||
|                             "return": { | ||||
|                                 'typing': 'typing', | ||||
|                                 'canPost': 'canPost' | ||||
|                             }, | ||||
|                             "references": {}, | ||||
|                             "threadId": thread.get('id'), | ||||
|                             "token": thread.get('token'), | ||||
|                             "lastId": thread.get('lastId'), | ||||
|                             "typed": user.get('typing'), | ||||
|                             "user": (! user.get('isAgent')) | ||||
|                         } | ||||
|                     } | ||||
|                 ] | ||||
|             }, | ||||
|             function(args) { | ||||
|                 // Check if there was an error
 | ||||
|                 if (args.errorCode) { | ||||
|                     Mibew.Objects.Models.Status.message.setMessage( | ||||
|                         args.errorMessage || 'refresh failed' | ||||
|                     ); | ||||
|                     return; | ||||
|                 } | ||||
|                 // Update typing status
 | ||||
|                 if (args.typing) { | ||||
|                     Mibew.Objects.Models.Status.typing.show(); | ||||
|                 } | ||||
|                 // Update user
 | ||||
|                 Mibew.Objects.Models.user.set({ | ||||
|                     canPost: args.canPost || false | ||||
|                 }); | ||||
|             } | ||||
|         ); | ||||
|         app.Chat.start(options); | ||||
|     }); | ||||
| 
 | ||||
|     App.on('start', function() { | ||||
|     app.on('start', function() { | ||||
|         // Run Server updater
 | ||||
|         Mibew.Objects.server.runUpdater(); | ||||
|     }); | ||||
|  | ||||
| @ -18,16 +18,6 @@ | ||||
|      */ | ||||
|     Mibew.Layouts = {}; | ||||
| 
 | ||||
|     /** | ||||
|      * @namespace Holds instances of control models | ||||
|      */ | ||||
|     Mibew.Objects.Models.Controls = {}; | ||||
| 
 | ||||
|     /** | ||||
|      * @namespace Holds instances of status models | ||||
|      */ | ||||
|     Mibew.Objects.Models.Status = {}; | ||||
| 
 | ||||
|     /** | ||||
|      * Create application instance. | ||||
|      * @type Backbone.Marionette.Application | ||||
|  | ||||
							
								
								
									
										225
									
								
								src/messenger/webim/js/source/chat/modules/chat.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										225
									
								
								src/messenger/webim/js/source/chat/modules/chat.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,225 @@ | ||||
| /** | ||||
|  * @preserve This file is part of Mibew Messenger project. | ||||
|  * http://mibew.org
 | ||||
|  *  | ||||
|  * Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  * License: http://mibew.org/license.php
 | ||||
|  */ | ||||
| 
 | ||||
| (function(Mibew){ | ||||
| 
 | ||||
|     /** | ||||
|      * @namespace Holds instances of control models | ||||
|      */ | ||||
|     Mibew.Objects.Models.Controls = {}; | ||||
| 
 | ||||
|     /** | ||||
|      * @namespace Holds instances of status models | ||||
|      */ | ||||
|     Mibew.Objects.Models.Status = {}; | ||||
| 
 | ||||
| 
 | ||||
|     // Create shortcut for Application object
 | ||||
|     var app = Mibew.Application; | ||||
| 
 | ||||
|     // Create Chat module
 | ||||
|     var chat = app.module('Chat', {startWithParent: false}); | ||||
| 
 | ||||
|     // Add module initializer
 | ||||
|     chat.addInitializer(function(options) { | ||||
|         // Create some shortcuts
 | ||||
|         var objs = Mibew.Objects; | ||||
|         var models = Mibew.Objects.Models; | ||||
|         var controls = Mibew.Objects.Models.Controls; | ||||
|         var status = Mibew.Objects.Models.Status; | ||||
| 
 | ||||
|         // Create instance of the chat layout
 | ||||
|         // Use undocumented feature of layouts: passing model to layout
 | ||||
|         var layout = new Mibew.Layouts.Chat({ | ||||
|             model: new Backbone.Model(options.layoutsData.chat || {}) | ||||
|         }); | ||||
|         Mibew.Objects.chatLayout = layout; | ||||
| 
 | ||||
|         // Show layout at page
 | ||||
|         app.mainRegion.show(layout); | ||||
| 
 | ||||
|         // Initialize Thread and User
 | ||||
|         models.thread = new Mibew.Models.Thread(options.thread); | ||||
|         models.user = new Mibew.Models.ChatUser(options.user); | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize Page
 | ||||
|         models.page = new Mibew.Models.Page(options.page); | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize controls
 | ||||
|         // Create controls collection
 | ||||
|         var ctrlsCollection = new Mibew.Collections.Controls(); | ||||
| 
 | ||||
|         // Create controls only for user
 | ||||
|         if (! models.user.get('isAgent')) { | ||||
|             // Create user name control
 | ||||
|             controls.userName = new Mibew.Models.UserNameControl({ | ||||
|                 weight: 220 | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.userName); | ||||
| 
 | ||||
|             // Create mail control
 | ||||
|             controls.sendMail = new Mibew.Models.SendMailControl({ | ||||
|                 weight: 200, | ||||
|                 link: options.links.mailLink | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.sendMail); | ||||
|         } | ||||
| 
 | ||||
|         // Create controls only for agent
 | ||||
|         if (models.user.get('isAgent')) { | ||||
|             controls.redirect = new Mibew.Models.RedirectControl({ | ||||
|                 weight: 200, | ||||
|                 link: options.links.redirectLink | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.redirect); | ||||
| 
 | ||||
|             controls.history = new Mibew.Models.HistoryControl({ | ||||
|                 weight: 180, | ||||
|                 link: options.links.historyLink | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.history); | ||||
|         } | ||||
| 
 | ||||
|         // Create toggle sound button
 | ||||
|         controls.sound = new Mibew.Models.SoundControl({ | ||||
|             weight: 160 | ||||
|         }); | ||||
|         ctrlsCollection.add(controls.sound); | ||||
| 
 | ||||
|         // Create refresh button
 | ||||
|         controls.refresh = new Mibew.Models.RefreshControl({ | ||||
|             weight: 140 | ||||
|         }); | ||||
|         ctrlsCollection.add(controls.refresh); | ||||
| 
 | ||||
|         if (options.links.sslLink) { | ||||
|             controls.secureMode = new Mibew.Models.SecureModeControl({ | ||||
|                 weight: 120, | ||||
|                 link: options.links.sslLink | ||||
|             }); | ||||
|             ctrlsCollection.add(controls.secureMode); | ||||
|         } | ||||
| 
 | ||||
|         // Create close button
 | ||||
|         controls.close = new Mibew.Models.CloseControl({ | ||||
|             weight: 100 | ||||
|         }); | ||||
|         ctrlsCollection.add(controls.close); | ||||
| 
 | ||||
|         objs.Collections.controls = ctrlsCollection; | ||||
| 
 | ||||
|         // Display controls
 | ||||
|         layout.controlsRegion.show(new Mibew.Views.ControlsCollection({ | ||||
|             collection: ctrlsCollection | ||||
|         })); | ||||
| 
 | ||||
| 
 | ||||
|         // Iniitialize status bar
 | ||||
|         // Create status message model
 | ||||
|         status.message = new Mibew.Models.StatusMessage({hideTimeout: 5000}); | ||||
| 
 | ||||
|         // Create typing status model
 | ||||
|         status.typing = new Mibew.Models.StatusTyping({hideTimeout: 5000}); | ||||
| 
 | ||||
|         // Create status collection
 | ||||
|         objs.Collections.status = new Mibew.Collections.Status([ | ||||
|             status.message, | ||||
|             status.typing | ||||
|         ]); | ||||
| 
 | ||||
|         // Display status bar
 | ||||
|         layout.statusRegion.show(new Mibew.Views.StatusCollection({ | ||||
|             collection: objs.Collections.status | ||||
|         })); | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize avatar only for user
 | ||||
|         if (! models.user.get('isAgent')) { | ||||
|             models.avatar = new Mibew.Models.Avatar(); | ||||
|             layout.avatarRegion.show(new Mibew.Views.Avatar({ | ||||
|                 model: models.avatar | ||||
|             })); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize chat window
 | ||||
|         // Create messages collection and store it
 | ||||
|         objs.Collections.messages = new Mibew.Collections.Messages(); | ||||
| 
 | ||||
|         // Create message processor model
 | ||||
|         models.messageForm = new Mibew.Models.MessageForm( | ||||
|             options.messageForm | ||||
|         ); | ||||
| 
 | ||||
|         // Display message processor
 | ||||
|         layout.messageFormRegion.show(new Mibew.Views.MessageForm({ | ||||
|             model: models.messageForm | ||||
|         })); | ||||
| 
 | ||||
|         // Display messages
 | ||||
|         layout.messagesRegion.show(new Mibew.Views.MessagesCollection({ | ||||
|             collection: objs.Collections.messages | ||||
|         })); | ||||
| 
 | ||||
| 
 | ||||
|         // Initialize sounds
 | ||||
|         models.sound = new Mibew.Models.Sound(); | ||||
|         layout.soundRegion.show(new Mibew.Views.Sound({ | ||||
|             model: models.sound | ||||
|         })); | ||||
| 
 | ||||
|         // TODO: May be move it somewhere else
 | ||||
|         // Periodically call update function at the server side
 | ||||
|         objs.server.callFunctionsPeriodically( | ||||
|             function() { | ||||
|                 // Get thread and user objects
 | ||||
|                 var thread = Mibew.Objects.Models.thread; | ||||
|                 var user = Mibew.Objects.Models.user; | ||||
| 
 | ||||
|                 // Build functions list
 | ||||
|                 return [ | ||||
|                     { | ||||
|                         "function": "update", | ||||
|                         "arguments": { | ||||
|                             "return": { | ||||
|                                 'typing': 'typing', | ||||
|                                 'canPost': 'canPost' | ||||
|                             }, | ||||
|                             "references": {}, | ||||
|                             "threadId": thread.get('id'), | ||||
|                             "token": thread.get('token'), | ||||
|                             "lastId": thread.get('lastId'), | ||||
|                             "typed": user.get('typing'), | ||||
|                             "user": (! user.get('isAgent')) | ||||
|                         } | ||||
|                     } | ||||
|                 ] | ||||
|             }, | ||||
|             function(args) { | ||||
|                 // Check if there was an error
 | ||||
|                 if (args.errorCode) { | ||||
|                     Mibew.Objects.Models.Status.message.setMessage( | ||||
|                         args.errorMessage || 'refresh failed' | ||||
|                     ); | ||||
|                     return; | ||||
|                 } | ||||
|                 // Update typing status
 | ||||
|                 if (args.typing) { | ||||
|                     Mibew.Objects.Models.Status.typing.show(); | ||||
|                 } | ||||
|                 // Update user
 | ||||
|                 Mibew.Objects.Models.user.set({ | ||||
|                     canPost: args.canPost || false | ||||
|                 }); | ||||
|             } | ||||
|         ); | ||||
|     }); | ||||
| 
 | ||||
| })(Mibew); | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user