Skip to content

Commit

Permalink
Add button to show tracked path of a visitor into operator's chat window
Browse files Browse the repository at this point in the history
  • Loading branch information
faf committed Jun 27, 2022
1 parent 3148db5 commit 691bcfa
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 4 deletions.
68 changes: 68 additions & 0 deletions src/mibew/js/source/chat/model_views/controls/tracked_path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*!
* This file is a part of Mibew Messenger.
*
* Copyright 2005-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

(function(Mibew, Handlebars, _) {
/**
* @class Represents Tracked path control view
*/
Mibew.Views.TrackedPathControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.TrackedPathControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates['chat/controls/tracked_path'],

/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click': 'showTrackedPath'
}
),

/**
* Display tracked path window
*/
showTrackedPath: function() {
var user = Mibew.Objects.Models.user;
var link = this.model.get('link');
if (user.get('isAgent') && link) {
var winParams = Mibew.Utils.buildWindowParams(this.model.get('windowParams'));

// TODO: Kill & at the server side
link = link.replace('&', '&', 'g');

var newWindow = window.open(link, 'UserTrackedPath', winParams);
if (newWindow !== null) {
newWindow.focus();
newWindow.opener=window;
}
}
}
}
);

})(Mibew, Handlebars, _);
63 changes: 63 additions & 0 deletions src/mibew/js/source/chat/models/controls/tracked_path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*!
* This file is a part of Mibew Messenger.
*
* Copyright 2005-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

(function(Mibew, _){

/**
* @class Tracked path control model
*/
Mibew.Models.TrackedPathControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.TrackedPathControl.prototype */
{
/**
* A list of default model values.
*
* The model inherits defaults from
* {@link Mibew.Models.Control.prototype.defaults}.
* @type Object
*/
defaults: _.extend(
{},
Mibew.Models.Control.prototype.defaults,
{
/**
* An URL of the tracked path page or false by default.
* @type String|Boolean
*/
link: false,

/**
* Params string for tracked path popup window
* @type String
*/
windowParams: ''
}
),

/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'TrackedPathControl';
}

}
);

})(Mibew, _);
9 changes: 9 additions & 0 deletions src/mibew/js/source/chat/modules/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@
windowParams: options.windowsParams.history
});
ctrlsCollection.add(controls.history);

if (options.links.tracked) {
controls.tracked_path = new Mibew.Models.TrackedPathControl({
weight: 170,
link: options.links.tracked,
windowParams: options.windowsParams.trackedPath
});
ctrlsCollection.add(controls.tracked_path);
}
}

// Create toggle sound button
Expand Down
12 changes: 8 additions & 4 deletions src/mibew/libs/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ function setup_chatview(Thread $thread)
$style_config = $page_style->getConfigurations();
$data['chat']['windowsParams']['history']
= $style_config['history']['window'];
$data['chat']['windowsParams']['trackedPath']
= $style_config['tracked']['visitor_window'];

$data['startFrom'] = 'chat';

Expand Down Expand Up @@ -517,10 +519,12 @@ function setup_chatview_for_operator(
// Set tracking params
if (Settings::get('enabletracking')) {
$visitor = track_get_visitor_by_thread_id($thread->id);
$data['chat']['links']['tracked'] = $url_generator->generate(
'history_user_track',
array('visitor' => $visitor['visitorid'])
);
if ($visitor) {
$data['chat']['links']['tracked'] = $url_generator->generate(
'history_user_track',
array('visitor' => $visitor['visitorid'])
);
}
}

// Check if agent can post messages
Expand Down
6 changes: 6 additions & 0 deletions src/mibew/styles/chats/dark/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ a:hover .image-close-window {
.active-history-control .tpl-image {
background-position: -112px 0;
}
.tracked-path-control .tpl-image {
background-position: -192px -16px;
}
.active-tracked-path-control .tpl-image {
background-position: -192px 0;
}
.sound-control .sound-control-on {
background-position: -48px -16px;
}
Expand Down
Binary file modified src/mibew/styles/chats/dark/images/buttons.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="tpl-image" title="{{l10n "Tracked path of visitor"}}"></div>
6 changes: 6 additions & 0 deletions src/mibew/styles/chats/default/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ a:hover .image-close-window {
.active-history-control .tpl-image {
background-position: -112px 0;
}
.tracked-path-control .tpl-image {
background-position: -192px -16px;
}
.active-tracked-path-control .tpl-image {
background-position: -192px 0;
}
.sound-control .sound-control-on {
background-position: -48px -16px;
}
Expand Down
Binary file modified src/mibew/styles/chats/default/images/buttons.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="tpl-image" title="{{l10n "Tracked path of visitor"}}"></div>

0 comments on commit 691bcfa

Please sign in to comment.