Added sprintf.

Rotation tooltips updated in realtime with current rotation degree.
This commit is contained in:
Gunther Brunner
2014-05-20 18:28:51 +09:00
parent 3143101ab5
commit e405ca1577
6 changed files with 97 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
var _ = require('lodash')
module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService, $location) {
module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService, $location, $timeout, gettext, $filter) {
$scope.showScreen = true
@@ -43,4 +43,62 @@ module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService,
$scope.controlDevice = function (device) {
$location.path('/control/' + device.serial)
}
function isPortrait(value) {
if (typeof value === 'undefined' && $scope.device) {
value = $scope.device.display.orientation
}
return (value === 0 || value === 180)
}
function isLandscape(value) {
if (typeof value === 'undefined' && $scope.device) {
value = $scope.device.display.orientation
}
return (value === 90 || value === 270)
}
$scope.tryToRotate = function (rotation) {
if (rotation === 'portrait') {
$scope.control.rotate(0)
$timeout(function () {
if (isLandscape()) {
$scope.currentRotation = 'landscape'
}
}, 400)
} else if (rotation === 'landscape') {
$scope.control.rotate(90)
$timeout(function () {
if (isPortrait()) {
$scope.currentRotation = 'portrait'
}
}, 400)
}
}
$scope.currentRotation = 'portrait'
$scope.$watch('device.display.orientation', function (newValue, oldValue) {
if (isPortrait(newValue)) {
$scope.currentRotation = 'portrait'
} else if (isLandscape(newValue)) {
$scope.currentRotation = 'landscape'
}
})
$scope.tooltipPortrait = function () {
var angle = 0
if (isPortrait()) {
angle = $scope.device.display.orientation
}
return gettext($filter('sprintf')('Portrait (%s°)', angle))
}
$scope.tooltipLandscape = function () {
var angle = 90
if (isLandscape()) {
angle = $scope.device.display.orientation
}
return gettext($filter('sprintf')('Landscape (%s°)', angle))
}
}