Added speed dialing

This commit is contained in:
Martin Schröder 2015-05-26 11:42:54 +02:00 committed by Martin Schröder
parent 35c3fbfcea
commit 0d036c07fb
5 changed files with 97 additions and 7 deletions

View file

@ -485,7 +485,6 @@
UCIConfig.prototype.$deleteSection = function(section){
var self = this;
var deferred = $.Deferred();
console.log("Deleting section "+self[".name"]+"."+section[".name"]);
//self[".need_commit"] = true;
$rpc.uci.delete({
@ -493,6 +492,7 @@
"section": section[".name"]
}).done(function(){
_unlinkSection(self, section);
console.log("Deleted section "+self[".name"]+"."+section[".name"]);
self[".need_commit"] = true;
deferred.resolve();
}).fail(function(){

View file

@ -1,5 +1,9 @@
<luci-layout-with-sidebar>
<div ng-controller="PhoneNumbersPageCtrl">
This page is not done yet. Waiting for voice API.
<luci-config-section>
<luci-config-heading>{{ 'Phone Numbers' | translate }}</luci-config-heading>
<luci-config-info>{{ 'phone.speed_dialing.info' | translate }}</luci-config-info>
</luci-config-section>
</div>
</luci-layout-with-sidebar>

View file

@ -1,5 +1,27 @@
<luci-layout-with-sidebar>
<div ng-controller="PhoneSpeedDialingCtrl">
This page is not done yet. Waiting for voice API.
<luci-config-section>
<luci-config-heading>{{ 'Speed Dialing' | translate }}</luci-config-heading>
<luci-config-info>{{ 'phone.speed_dialing.info' | translate }}</luci-config-info>
<luci-config-lines>
<luci-config-line title="{{'Speed Dialing'|translate}}">
<switch ng-model="speed_dialing" class="green"/>
</luci-config-line>
</luci-config-lines>
<div class="row" ng-show="speed_dialing">
<div class="col-md-6" ng-repeat="dial in speed_dials">
<div class="col-md-3">#{{dial.tone}}</div>
<div class="col-md-9 form-group">
<input type="text" class="form-control" ng-model="dial.number"/>
</div>
</div>
</div>
<luci-config-lines ng-show="speed_dialing">
<luci-config-line title="{{'Remove all entries from speed dial list'|translate}}">
<button class="btn btn-lg btn-default" ng-click="onClearAll()" translate>Clear</button>
</luci-config-line>
</luci-config-lines>
</luci-config-section>
<luci-config-apply></luci-config-apply>
</div>
</luci-layout-with-sidebar>

View file

@ -20,7 +20,69 @@
* 02110-1301 USA
*/
$juci.module("phone")
.controller("PhoneSpeedDialingCtrl", function($scope){
JUCI.app
.controller("PhoneSpeedDialingCtrl", function($scope, $uci){
$scope.speed_dials = [];
$scope.speed_dialing = true;
$scope.$watch("speed_dials", function(){
var dials = {};
$scope.speed_dials.map(function(x){ if(x.number != "") dials[x.tone] = x; });
async.eachSeries(Object.keys(dials), function(k, next){
if(!dials[k].exists){
$uci.voice_client.create({".type": "speed_dial"}).done(function(section){
section.tone.value = dials[k].tone;
section.number.value = dials[k].number;
dials[k].exists = true;
}).always(function(){
next();
});
} else {
next();
}
}, function(){
Object.keys($scope.speed_dials).map(function(k){
var dial = $scope.speed_dials[k];
var section = $uci.voice_client["@speed_dial"].find(function(x){ return x.tone.value == dial.tone; });
if(section){
section.tone.value = dial.tone;
section.number.value = dial.number;
}
});
});
}, true);
function resync(){
$uci.sync("voice_client").done(function(){
var dials = {};
$uci.voice_client["@speed_dial"].map(function(x){
dials[x.tone.value] = {
tone: x.tone.value,
number: x.number.value,
exists: true
};
});
for(var c = 0; c < 10; c++){
if(!(dials[c])) dials[c] = {
tone: c,
number: ""
}
}
$scope.speed_dials = Object.keys(dials).map(function(x){ return dials[x]; });
$scope.$apply();
});
} resync();
$scope.onClearAll = function(){
var dials = $uci.voice_client["@speed_dial"].map(function(x){ return x; });
async.eachSeries(dials, function(dial, next){
dial.$delete().always(function(){ next(); });
}, function(){
console.log("Save!");
$uci.save().done(function(){
console.log("resync");
resync();
});
});
}
});

View file

@ -130,7 +130,8 @@
"setpin",
"pbc",
"showpin",
"stapin"
"stapin",
"status"
],
"router": [
"networks"
@ -161,7 +162,8 @@
"setpin",
"pbc",
"showpin",
"stapin"
"stapin",
"status"
]
},
"uci": [