mirror of
https://github.com/Mibew/tray.git
synced 2025-01-22 18:10:34 +03:00
Move message kinds from message view to message model
This commit is contained in:
parent
37de991028
commit
526d5ad4ae
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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 */
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -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 */
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user