PageSourceSearch

https://revma.com/static/wrappers/api-plugins/v2/messaging.js?

js revma.com collected 2026-10-02 14:44:12 UTC 3,969 bytes, 132 lines download raw bytes

1/**
2 * Copyright (C) Radiojar S.A. - All Rights Reserved
3 **
4 * Licensed under the MIT license
5 * https://opensource.org/licenses/MIT
6 */
7
8!function ($) {
9
10    RJ.views.MessagingView = Backbone.View.extend({
11
12        tagName: "span",
13
14        events: {
15            "click #btnCreateThread": "newThread"
16        },
17
18        newThread: function(){
19            if ($('#newmessage').val().trim() != "") {
20                var recipients = [];
21                if(this.options.settings.recipients.models) {
22                    _.each(this.options.settings.recipients.models, function(recipient){
23                        recipients.push(recipient.get('id'));
24                    });
25                } else {
26                    recipients.push(this.options.settings.recipients.get('id'));
27                }
28
29                if (recipients.length > 0) {
30                    var newThread = new RJ.models.Thread({
31                        recipients: recipients,
32                        content: nl2br($('#newmessage').val().trim()),
33                    });
34                    newThread.save();
35                }
36
37                $('#newmessage').val('');
38            }
39        },
40
41        initialize: function(){
42            this.template = _.template(RJ.tpl.get('messaging-plugin-container'));
43            this.template_button = _.template(RJ.tpl.get('messaging-plugin-container-button'));
44        },
45
46        render: function(eventName){
47            var that =this;
48            $(this.el).html(this.template_button({
49                btnCaption:this.options.settings.btncaption,
50                btnClasses:this.options.settings.btnclasses
51            }));
52            $(this.el).append(this.template({
53                caption:this.options.settings.caption,
54                btnCaption:this.options.settings.btncaption,
55            }))
56            $('#btnCreateThread').click(function(){ //add a click handler through jquery because the template of the modal is added to the body and not the $(this.el)
57                that.newThread();
58            })
59            return this;
60        }
61
62    });
63
64
65    //Register 'destroyed' event
66    var oldClean = $.cleanData;
67    $.cleanData = function( elems ) {
68            for ( var i = 0, elem;
69            (elem = elems[i]) !== undefined; i++ ) {
70                    $(elem).triggerHandler("destroyed");
71            }
72            oldClean(elems);
73    };
74
75
76    RJP.messaging = function($,$object,options) {
77        var settings;
78        var obj;
79        var defaults = {
80            recipients: 'all',
81            sender: 'me',
82            btncaption: 'Send message to all',
83            btnclasses: 'btn-small'
84        };
85
86        settings = $.extend({}, defaults, options);
87
88
89        var opts = $.meta ? $.extend({}, settings, $object.data()) : settings;
90        for(var attrName in defaults) {
91            var inline_attr = $object.attr('data-'+attrName);
92            if(inline_attr) {
93                opts[attrName] = inline_attr;
94            }
95        }
96
97
98
99        obj = $object;
100
101        var messagingView = null;
102
103        RJ.tpl.loadTemplates(['messaging'], function(el){
104            var token = authToken;
105            $.ajaxPrefilter(function(options, originalOptions, jqXHR){
106                if ( !options.crossDomain ) {
107                    jqXHR.setRequestHeader('X-Auth-Token', token);
108                }
109            });
110
111            require(['models/thread'],function(modelThread){
112                messagingView = new RJ.views.MessagingView({
113                    settings: opts
114                });
115                obj.html(messagingView.render().el);
116            });
117        });
118
119        $object.bind("destroyed", function(){
120            if (messagingView) {
121              messagingView.remove();
122            }
123        })
124
125        return $object.each(function() {
126
127
128        });
129    };
130
131
132}(rjq);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.