.controller('PrintConfigCtrl',
['$scope','egCore',
function($scope , egCore) {
- console.log('PrintConfigCtrl');
-
- $scope.actionPending = false;
- $scope.isTestView = false;
+ $scope.printConfig = {};
$scope.setContext = function(ctx) {
$scope.context = ctx;
$scope.isTestView = false;
- $scope.actionPending = false;
}
$scope.setContext('default');
return printer;
}
- $scope.currentPrinter = function() {
- if ($scope.printConfig && $scope.printConfig[$scope.context]) {
- return $scope.getPrinterByAttr(
- 'name', $scope.printConfig[$scope.context].printer
- );
- }
- }
-
// fetch info on all remote printers
egCore.hatch.getPrinters()
.then(function(printers) {
$scope.defaultPrinter = def;
loadPrinterOptions(def.name);
}
- })
- .then(function() {
- $scope.printConfig = {};
-
- // apply the default printer to every context which has
- // no printer configured.
+ }).then(function() {
angular.forEach(
['default','receipt','label','mail','offline'],
function(ctx) {
egCore.hatch.getPrintConfig(ctx).then(function(conf) {
- if (!conf) {
- conf = {
- context : ctx,
- printer : $scope.defaultPrinter.name,
- autoMargins : true,
- allPages : true,
- pageRanges : []
- };
+ if (conf) {
+ $scope.printConfig[ctx] = conf;
+ } else {
+ $scope.resetPrinterSettings(ctx);
}
- $scope.printConfig[ctx] = conf;
});
}
);
});
+ $scope.resetPrinterSettings = function(context) {
+ $scope.printConfig[context] = {
+ context : context,
+ printer : $scope.defaultPrinter ? $scope.defaultPrinter.name : null,
+ autoMargins : true,
+ allPages : true,
+ pageRanges : []
+ };
+ }
- $scope.usingManualMargins = function(ctx) {
- var conf = $scope.printConfig[ctx];
- return conf && conf.marginType;
+ $scope.savePrinterSettings = function(context) {
+ return egCore.hatch.setPrintConfig(
+ context, $scope.printConfig[context]);
}
$scope.printerConfString = function() {
$scope.printConfig[$scope.context], undefined, 2);
}
- $scope.resetConfig = function() {
- $scope.actionPending = true;
- $scope.printConfigError = null;
- $scope.printConfig[$scope.context] = {
- context : $scope.context
- }
-
- if ($scope.defaultPrinter) {
- $scope.printConfig[$scope.context].printer =
- $scope.defaultPrinter.name;
- }
-
- egCore.hatch.setPrintConfig($scope.printConfig)
- .finally(function() {$scope.actionPending = false});
- }
-
function loadPrinterOptions(name) {
egCore.hatch.getPrinterOptions(name).then(
function(options) {$scope.printerOptions = options});