Skip to content

Commit

Permalink
UI-1219: Added the prepend feature for numbers as a common control
Browse files Browse the repository at this point in the history
Conflicts:
	apps/common/app.js
	apps/common/i18n/en-US.json
  • Loading branch information
mroux committed Feb 24, 2015
1 parent f4d9546 commit 2d73b30
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apps/common/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define(function(require){
var app = {
name: 'common',

subModules: ['accountBrowser', 'buyNumbers', 'callerId', 'e911', 'failover', 'numbers', 'port', 'chooseModel', 'servicePlanDetails', 'ringingDurationControl'],
subModules: ['accountBrowser', 'buyNumbers', 'callerId', 'e911', 'failover', 'numbers', 'port', 'chooseModel', 'servicePlanDetails', 'ringingDurationControl', 'numberPrepend'],

css: [ 'app' ],

Expand Down
16 changes: 15 additions & 1 deletion apps/common/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@
"questionPartThree": "?",
"button": "move number(s)"
}
}
},

"__comment": "UI-1219: Adding the prepend feature to numbers",
"__version": "v3.20_s1",
"prependIconHelp": "This icon means that this number will show up with a custom prepended text on your phone"
},

"callerId": {
Expand Down Expand Up @@ -362,5 +366,15 @@
"distribute": "Distribute",
"maxDurationTooltip": "Click this box to change the maximum duration for your ring group. You must enter a number between 30 and 999.",
"doNotRing": "Do not ring"
},

"__comment": "UI-1219: Adding the prepend feature to numbers",
"__version": "v3.20_s1",
"numberPrepend": {
"dialogTitle": "Number Prepend Setup",
"title": "Text to prepend",
"label": "Prepend",
"help": "This text will appear before your number when receiving a call. This can be used to better identify which number was called when you use more than one.",
"successUpdate": "You successfully updated the prepended text for {{phoneNumber}}"
}
}
1 change: 1 addition & 0 deletions apps/common/style/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@import url('../submodules/chooseModel/chooseModel.css');
@import url('../submodules/servicePlanDetails/servicePlanDetails.css');
@import url('../submodules/ringingDurationControl/ringingDurationControl.css');
@import url('../submodules/numberPrepend/numberPrepend.css');

/* Hack because of otpimization: can't have relative paths since the folder hierarchy changes after optimization */
.trunkstore_popup.cnam .left_image {
Expand Down
26 changes: 26 additions & 0 deletions apps/common/submodules/numberPrepend/numberPrepend.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* NUMBER-PREPEND POPUP */
.trunkstore_popup.number-prepend {
width: 510px;
}

.trunkstore_popup.number-prepend form,
.trunkstore_popup.number-prepend input {
margin: 0;
}

.trunkstore_popup.number-prepend .popup-content {
padding: 15px 25px;
}

.trunkstore_popup.number-prepend .popup-content:not(:first-child) {
border-top: 1px solid #ccc;
}

.trunkstore_popup.number-prepend .popup-content .popup-label {
margin: 0 10px 0 0;
display: inline-block;
}

.trunkstore_popup.number-prepend .help-box {
margin-top: 20px;
}
103 changes: 103 additions & 0 deletions apps/common/submodules/numberPrepend/numberPrepend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
define(function(require){
var $ = require('jquery'),
_ = require('underscore'),
monster = require('monster'),
toastr = require('toastr');

var numberPrepend = {

requests: {
},

subscribe: {
'common.numberPrepend.renderPopup': 'numberPrependEdit'
},

numberPrependEdit: function(args) {
var self = this;

self.numberPrependGetNumber(args.phoneNumber, function(dataNumber) {
self.numberPrependRender(dataNumber.data, args.callbacks);
});
},

numberPrependRender: function(dataNumber, callbacks) {
var self = this,
popup_html = $(monster.template(self, 'numberPrepend-layout', dataNumber.prepend || {})),
popup;

popup_html.find('.save').on('click', function(ev) {
ev.preventDefault();
var prependFormData = monster.ui.getFormData('number_prepend');
prependFormData.enabled = (prependFormData.name && prependFormData.name.length > 0) ? true : false;

_.extend(true, dataNumber, { prepend: prependFormData });

self.numberPrependUpdateNumber(dataNumber.id, dataNumber,
function(data) {
var phoneNumber = monster.util.formatPhoneNumber(data.data.id),
template = monster.template(self, '!' + self.i18n.active().numberPrepend.successUpdate, { phoneNumber: phoneNumber });

toastr.success(template);

popup.dialog('destroy').remove();

callbacks.success && callbacks.success(data);
},
function(data) {
callbacks.error && callbacks.error(data);
}
);

});

popup_html.find('.cancel-link').on('click', function(e) {
e.preventDefault();
popup.dialog('destroy').remove();
});

popup = monster.ui.dialog(popup_html, {
title: self.i18n.active().numberPrepend.dialogTitle
});
},

numberPrependGetNumber: function(phoneNumber, success, error) {
var self = this;

self.callApi({
resource: 'numbers.get',
data: {
accountId: self.accountId,
phoneNumber: encodeURIComponent(phoneNumber)
},
success: function(_data, status) {
success && success(_data);
},
error: function(_data, status) {
error && error(_data);
}
});
},

numberPrependUpdateNumber: function(phoneNumber, data, success, error) {
var self = this;

self.callApi({
resource: 'numbers.update',
data: {
accountId: self.accountId,
phoneNumber: encodeURIComponent(phoneNumber),
data: data
},
success: function(_data, status) {
success && success(_data);
},
error: function(_data, status) {
error && error(_data);
}
});
}
};

return numberPrepend;
});
57 changes: 40 additions & 17 deletions apps/common/submodules/numbers/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ define(function(require){
inbound_cnam: { icon: 'icon-green icon-user feature-inbound_cnam', help: self.i18n.active().numbers.cnamInboundIconHelp },
dash_e911: { icon: 'icon-red icon-ambulance feature-dash_e911', help: self.i18n.active().numbers.e911IconHelp },
local: { icon: 'icon-purple icon-rocket feature-local', help: self.i18n.active().numbers.localIconHelp },
port: { icon: 'icon-phone icon-yellow feature-port' }
port: { icon: 'icon-phone icon-yellow feature-port' },
prepend: { icon: 'icon-orange icon-file-text-alt feature-prepend', help: self.i18n.active().numbers.prependIconHelp }
};

if(callback) {
Expand Down Expand Up @@ -173,7 +174,7 @@ define(function(require){
var sortByDate = function(a,b) {
return a.updated > b.updated ? -1 : 1;
},
sortByName = function(a,b) {
sortByName = function(a,b) {
return a.phoneNumber > b.phoneNumber;
};

Expand Down Expand Up @@ -218,7 +219,7 @@ define(function(require){
self.numbersList(accountId, function(numbers) {
var spareNumbers = [],
usedNumbers = [],
sortByName = function(a,b) {
sortByName = function(a,b) {
return a.phoneNumber > b.phoneNumber;
};

Expand Down Expand Up @@ -786,6 +787,28 @@ define(function(require){
}
});

parent.on('click', '.prepend-number', function() {
var prependCell = $(this).parents('.number-box').first(),
phoneNumber = prependCell.data('phonenumber');

if(phoneNumber) {
var args = {
phoneNumber: phoneNumber,
callbacks: {
success: function(data) {
if('prepend' in data.data && data.data.prepend.enabled) {
prependCell.find('.features i.feature-prepend').addClass('active');
} else {
prependCell.find('.features i.feature-prepend').removeClass('active');
}
}
}
};

monster.pub('common.numberPrepend.renderPopup', args);
}
});

var searchListNumbers = function(searchString, parent) {
var viewList = parent;

Expand Down Expand Up @@ -976,26 +999,26 @@ define(function(require){
data.accountName = accountName;

var formattedData = self.numbersFormatDialogSpare(data),
spareTemplate = $(monster.template(self, 'numbers-dialogSpare', formattedData));
spareTemplate = $(monster.template(self, 'numbers-dialogSpare', formattedData));

spareTemplate.find('.empty-search-row').hide();
spareTemplate.find('.empty-search-row').hide();

spareTemplate.on('keyup', '.search-query', function() {
var rows = spareTemplate.find('.number-box'),
emptySearch = spareTemplate.find('.empty-search-row'),
currentRow;
var rows = spareTemplate.find('.number-box'),
emptySearch = spareTemplate.find('.empty-search-row'),
currentRow;

currentNumberSearch = $(this).val().toLowerCase();
currentNumberSearch = $(this).val().toLowerCase();

_.each(rows, function(row) {
currentRow = $(row);
currentRow.data('search').toLowerCase().indexOf(currentNumberSearch) < 0 ? currentRow.hide() : currentRow.show();
});
_.each(rows, function(row) {
currentRow = $(row);
currentRow.data('search').toLowerCase().indexOf(currentNumberSearch) < 0 ? currentRow.hide() : currentRow.show();
});

if(rows.size() > 0) {
rows.is(':visible') ? emptySearch.hide() : emptySearch.show();
}
});
if(rows.size() > 0) {
rows.is(':visible') ? emptySearch.hide() : emptySearch.show();
}
});

spareTemplate.find('#proceed').on('click', function() {
var selectedNumbersRow = spareTemplate.find('.number-box.selected'),
Expand Down
22 changes: 22 additions & 0 deletions apps/common/views/numberPrepend-layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="trunkstore_popup number-prepend clearfix">
<form id="number_prepend">
<div class="popup-content">
<label class="popup-label" for="number_prepend_value">{{ i18n.numberPrepend.title }}</label>
<input type="text" id="number_prepend_value" name="name" value="{{name}}"/>
<div class="help-box gray-box">
<div class="wrapper-icon">
&nbsp;<i class="icon-info-sign2"></i>&nbsp;
</div>
<div class="text-wrapper">
<p>{{ i18n.numberPrepend.help }}</p>
</div>
</div>
</div>
<div class="popup-content popup-actions clearfix">
<div class="pull-right">
<a class="cancel-link monster-link blue" href="javascript:void(0);">{{ i18n.cancel }}</a>
<button type="button" class="btn btn-success save">{{ i18n.saveChanges }}</button>
</div>
</div>
</form>
</div>
5 changes: 3 additions & 2 deletions apps/common/views/numbers-used.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,25 @@
<div class="numbers-wrapper">
{{#each usedNumbers}}
<div class="number-box disabled" data-phoneNumber="{{this.phoneNumber}}">
{{#unless isLocal}}
<div class="number-options">
<div class="navbar">
<ul class="nav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-cog"></i></a>
<ul class="dropdown-menu">
{{#unless isLocal}}
<li><a class="cnam-number" href="#"><i class="icon-user"></i>{{ ../../../i18n.callerId.label }}</a></li>
<li><a class="e911-number" href="#"><i class="icon-ambulance"></i>{{ ../../../i18n.e911.label }}</a></li>
{{#compare this.used_by "===" "trunkstore"}}
<li><a class="failover-number" href="#"><i class="icon-thumbs-down"></i>{{ ../../../../i18n.failover.label }}</a></li>
{{/compare}}
{{/unless}}
<li><a class="prepend-number" href="#"><i class="icon-file-text-alt"></i>{{ ../../i18n.numberPrepend.label }}</a></li>
</ul>
</li>
</ul>
</div>
</div>
{{/unless}}
<div class="phone-number">{{formatPhoneNumber this.phoneNumber}}</div>
<div class="locality">
{{#if this.isoCountry }}
Expand Down

0 comments on commit 2d73b30

Please sign in to comment.