From 526d5ad4aee0dfd8f13cdba04d1b1dae32836ef9 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 4 Feb 2013 10:12:03 +0000 Subject: [PATCH] Move message kinds from message view to message model --- .../chat/model_views/messages/message.js | 4 +- .../compiled/chat/models/messages/message.js | 2 +- src/messenger/webim/js/compiled/chat_app.js | 6 +-- .../chat/model_views/messages/message.js | 47 ++++--------------- .../js/source/chat/models/messages/message.js | 31 +++++++++++- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/messenger/webim/js/compiled/chat/model_views/messages/message.js b/src/messenger/webim/js/compiled/chat/model_views/messages/message.js index 8c4c63e8..905a0d28 100644 --- a/src/messenger/webim/js/compiled/chat/model_views/messages/message.js +++ b/src/messenger/webim/js/compiled/chat/model_views/messages/message.js @@ -5,5 +5,5 @@ Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -(function(c,d,e){var f={"<":"<",">":">","&":"&",'"':""","'":"'","`":"`"},g=/[&<>'"`]/g;c.Views.Message=d.Marionette.ItemView.extend({template:e.templates.message,className:"message",modelEvents:{change:"render"},serializeData:function(){var a=this.model.toJSON(),b=this.model.get("kind");a.allowFormatting=b!=this.KIND_USER&&b!=this.KIND_AGENT;a.kindName=this.kindToString(b);a.message=this.escapeString(a.message);return a},kindToString:function(a){return a==this.KIND_USER?"user": -a==this.KIND_AGENT?"agent":a==this.KIND_FOR_AGENT?"hidden":a==this.KIND_INFO?"inf":a==this.KIND_CONN?"conn":a==this.KIND_EVENTS?"event":""},escapeString:function(a){return a.replace(g,function(a){return f[a]||"&"})},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew,Backbone,Handlebars); +(function(c,d,e){var f={"<":"<",">":">","&":"&",'"':""","'":"'","`":"`"},g=/[&<>'"`]/g;c.Views.Message=d.Marionette.ItemView.extend({template:e.templates.message,className:"message",modelEvents:{change:"render"},serializeData:function(){var a=this.model.toJSON(),b=this.model.get("kind");a.allowFormatting=b!=this.model.KIND_USER&&b!=this.model.KIND_AGENT;a.kindName=this.kindToString(b);a.message=this.escapeString(a.message);return a},kindToString:function(a){return a==this.model.KIND_USER? +"user":a==this.model.KIND_AGENT?"agent":a==this.model.KIND_FOR_AGENT?"hidden":a==this.model.KIND_INFO?"inf":a==this.model.KIND_CONN?"conn":a==this.model.KIND_EVENTS?"event":""},escapeString:function(a){return a.replace(g,function(a){return f[a]||"&"})}})})(Mibew,Backbone,Handlebars); diff --git a/src/messenger/webim/js/compiled/chat/models/messages/message.js b/src/messenger/webim/js/compiled/chat/models/messages/message.js index e30787e4..703ada14 100644 --- a/src/messenger/webim/js/compiled/chat/models/messages/message.js +++ b/src/messenger/webim/js/compiled/chat/models/messages/message.js @@ -5,4 +5,4 @@ Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""}})})(Mibew); +(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew); diff --git a/src/messenger/webim/js/compiled/chat_app.js b/src/messenger/webim/js/compiled/chat_app.js index bcbbdb76..6c6c0419 100644 --- a/src/messenger/webim/js/compiled/chat_app.js +++ b/src/messenger/webim/js/compiled/chat_app.js @@ -18,7 +18,7 @@ MibewAPIChatInteraction=function(){this.obligatoryArguments={"*":{threadId:null, (function(a,b){a.Models.SendMailControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"SendMailControl"}})})(Mibew,_); (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(b){b.Models.UserNameControl=b.Models.Control.extend({getModelType:function(){return"UserNameControl"},changeName:function(a){var c=b.Objects.Models.user,d=b.Objects.Models.thread,e=c.get("name");a&&e!=a&&(b.Objects.server.callFunctions([{"function":"rename",arguments:{references:{},"return":{},threadId:d.get("id"),token:d.get("token"),name:a}}],function(a){a.errorCode&&(b.Objects.Models.Status.message.setMessage(a.errorMessage||"Cannot rename"),c.set({name:e}))},!0),c.set({name:a}))}})})(Mibew); -(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""}})})(Mibew); +(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew); (function(a){a.Models.MessageForm=a.Models.Base.extend({defaults:{predefinedAnswers:[],ignoreCtrl:!1},postMessage:function(e){var b=a.Objects.Models.thread,c=a.Objects.Models.user;if(c.get("canPost")){this.trigger("before:post",this);var d=this;a.Objects.server.callFunctions([{"function":"post",arguments:{references:{},"return":{},message:e,threadId:b.get("id"),token:b.get("token"),user:!c.get("isAgent")}}],function(){d.trigger("after:post",d)},!0)}}})})(Mibew); (function(a,b){a.Models.StatusMessage=a.Models.Status.extend({defaults:b.extend({},a.Models.Status.prototype.defaults,{message:"",visible:!1}),getModelType:function(){return"StatusMessage"},setMessage:function(a){this.set({message:a,visible:!0});this.autoHide()}})})(Mibew,_); (function(a,b){a.Models.StatusTyping=a.Models.Status.extend({defaults:b.extend({},a.Models.Status.prototype.defaults,{visible:!1,hideTimeout:2E3}),getModelType:function(){return"StatusTyping"},show:function(){this.set({visible:!0});this.autoHide()}})})(Mibew,_); @@ -38,8 +38,8 @@ window.location.href=b.replace(/\&\;/g,"&")+(c?"&style="+c:"")}}})})(Mibew,Ha (function(a,b,c){a.Views.SoundControl=a.Views.Control.extend({template:b.templates.sound_control,events:c.extend({},a.Views.Control.prototype.events,{click:"toggle"}),toggle:function(){this.model.set({enabled:!this.model.get("enabled")})}})})(Mibew,Handlebars,_); (function(b,c,d){b.Views.UserNameControl=b.Views.Control.extend({template:c.templates.user_name_control,events:d.extend({},b.Views.Control.prototype.events,{"click .user-name-control-set":"changeName","click .user-name-control-change":"showNameInput","keydown #user-name-control-input":"inputKeyDown"}),ui:{nameInput:"#user-name-control-input"},initialize:function(){b.Objects.Models.user.on("change:name",this.hideNameInput,this);this.nameInput=b.Objects.Models.user.get("defaultName")},serializeData:function(){var a= this.model.toJSON();a.user=b.Objects.Models.user.toJSON();a.nameInput=this.nameInput;return a},inputKeyDown:function(a){a=a.which;(13==a||10==a)&&this.changeName()},hideNameInput:function(){this.nameInput=!1;this.render()},showNameInput:function(){this.nameInput=!0;this.render()},changeName:function(){var a=this.ui.nameInput.val();this.model.changeName(a)}})})(Mibew,Handlebars,_); -(function(c,d,e){var f={"<":"<",">":">","&":"&",'"':""","'":"'","`":"`"},g=/[&<>'"`]/g;c.Views.Message=d.Marionette.ItemView.extend({template:e.templates.message,className:"message",modelEvents:{change:"render"},serializeData:function(){var a=this.model.toJSON(),b=this.model.get("kind");a.allowFormatting=b!=this.KIND_USER&&b!=this.KIND_AGENT;a.kindName=this.kindToString(b);a.message=this.escapeString(a.message);return a},kindToString:function(a){return a==this.KIND_USER?"user": -a==this.KIND_AGENT?"agent":a==this.KIND_FOR_AGENT?"hidden":a==this.KIND_INFO?"inf":a==this.KIND_CONN?"conn":a==this.KIND_EVENTS?"event":""},escapeString:function(a){return a.replace(g,function(a){return f[a]||"&"})},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew,Backbone,Handlebars); +(function(c,d,e){var f={"<":"<",">":">","&":"&",'"':""","'":"'","`":"`"},g=/[&<>'"`]/g;c.Views.Message=d.Marionette.ItemView.extend({template:e.templates.message,className:"message",modelEvents:{change:"render"},serializeData:function(){var a=this.model.toJSON(),b=this.model.get("kind");a.allowFormatting=b!=this.model.KIND_USER&&b!=this.model.KIND_AGENT;a.kindName=this.kindToString(b);a.message=this.escapeString(a.message);return a},kindToString:function(a){return a==this.model.KIND_USER? +"user":a==this.model.KIND_AGENT?"agent":a==this.model.KIND_FOR_AGENT?"hidden":a==this.model.KIND_INFO?"inf":a==this.model.KIND_CONN?"conn":a==this.model.KIND_EVENTS?"event":""},escapeString:function(a){return a.replace(g,function(a){return f[a]||"&"})}})})(Mibew,Backbone,Handlebars); (function(b,d,e){b.Views.MessageForm=d.Marionette.ItemView.extend({template:e.templates.message_form,events:{"click #send-message":"postMessage","keydown #message-input":"messageKeyDown","keyup #message-input":"checkUserTyping","change #message-input":"checkUserTyping","change #predefined":"selectPredefinedAnswer","focus #message-input":"setFocus","blur #message-input":"dropFocus"},modelEvents:{change:"render"},ui:{message:"#message-input",send:"#send-message",predefinedAnswer:"#predefined"},initialize:function(){b.Objects.Models.user.on("change:canPost", this.render,this)},serializeData:function(){var a=this.model.toJSON();a.user=b.Objects.Models.user.toJSON();return a},postMessage:function(){var a=this.ui.message.val();""!=a&&(this.disableInput(),this.model.postMessage(a));b.Objects.Collections.messages.on("multiple:add",this.postMessageComplete,this)},messageKeyDown:function(a){var c=a.which;a=a.ctrlKey;(13==c&&(a||this.model.get("ignoreCtrl"))||10==c)&&this.postMessage()},enableInput:function(){this.ui.message.removeAttr("disabled")},disableInput:function(){this.ui.message.attr("disabled", "disabled")},clearInput:function(){this.ui.message.val("").change()},postMessageComplete:function(){this.clearInput();this.enableInput();this.focused&&this.ui.focus();b.Objects.Collections.messages.off("multiple:add",this.postMessageComplete,this)},selectPredefinedAnswer:function(){var a=this.ui.message,c=this.ui.predefinedAnswer,b=c.get(0).selectedIndex;b&&(a.val(this.model.get("predefinedAnswers")[b-1].full).change(),a.focus(),c.get(0).selectedIndex=0)},checkUserTyping:function(){var a=b.Objects.Models.user, diff --git a/src/messenger/webim/js/source/chat/model_views/messages/message.js b/src/messenger/webim/js/source/chat/model_views/messages/message.js index ab2c21bf..efd03978 100644 --- a/src/messenger/webim/js/source/chat/model_views/messages/message.js +++ b/src/messenger/webim/js/source/chat/model_views/messages/message.js @@ -65,8 +65,8 @@ var messageKind = this.model.get('kind'); // Add message fields - msg.allowFormatting = (messageKind != this.KIND_USER - && messageKind != this.KIND_AGENT); + msg.allowFormatting = (messageKind != this.model.KIND_USER + && messageKind != this.model.KIND_AGENT); msg.kindName = this.kindToString(messageKind); msg.message = this.escapeString(msg.message); @@ -79,22 +79,22 @@ * @returns {String} Kind name */ kindToString: function(kind) { - if (kind == this.KIND_USER) { + if (kind == this.model.KIND_USER) { return "user"; } - if (kind == this.KIND_AGENT) { + if (kind == this.model.KIND_AGENT) { return "agent"; } - if (kind == this.KIND_FOR_AGENT) { + if (kind == this.model.KIND_FOR_AGENT) { return "hidden"; } - if (kind == this.KIND_INFO) { + if (kind == this.model.KIND_INFO) { return "inf"; } - if (kind == this.KIND_CONN) { + if (kind == this.model.KIND_CONN) { return "conn"; } - if (kind == this.KIND_EVENTS) { + if (kind == this.model.KIND_EVENTS) { return "event"; } return ""; @@ -114,36 +114,7 @@ return badCharList[chr] || "&"; } ); - }, - - /** Message kind constants */ - - /** Message sent by user. */ - KIND_USER: 1, - - /** Message sent by operator */ - KIND_AGENT: 2, - - /** Hidden system message to operator */ - KIND_FOR_AGENT: 3, - - /** System messages for user and operator */ - KIND_INFO: 4, - - /** Message for user if operator have connection problems */ - KIND_CONN: 5, - - /** System message about some events (like rename). */ - KIND_EVENTS: 6, - - /** - * Message with operators avatar - * - * This kind of message leaved only for compatibility with core - */ - KIND_AVATAR: 7 - - /** End of message kind constants */ + } } ); diff --git a/src/messenger/webim/js/source/chat/models/messages/message.js b/src/messenger/webim/js/source/chat/models/messages/message.js index 9acc4ac0..6f42c423 100644 --- a/src/messenger/webim/js/source/chat/models/messages/message.js +++ b/src/messenger/webim/js/source/chat/models/messages/message.js @@ -23,7 +23,36 @@ * @type String */ message: '' - } + }, + + /** Message kind constants */ + + /** Message sent by user. */ + KIND_USER: 1, + + /** Message sent by operator */ + KIND_AGENT: 2, + + /** Hidden system message to operator */ + KIND_FOR_AGENT: 3, + + /** System messages for user and operator */ + KIND_INFO: 4, + + /** Message for user if operator have connection problems */ + KIND_CONN: 5, + + /** System message about some events (like rename). */ + KIND_EVENTS: 6, + + /** + * Message with operators avatar + * + * This kind of message leaved only for compatibility with core + */ + KIND_AVATAR: 7 + + /** End of message kind constants */ } );