webstaff: implement import/export of copy templates
authorGalen Charlton <gmc@esilibrary.com>
Mon, 25 Jan 2016 23:34:54 +0000 (18:34 -0500)
committerKathy Lussier <klussier@masslnc.org>
Tue, 2 Feb 2016 19:58:53 +0000 (14:58 -0500)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 9753d53..09e87d2 100644 (file)
                 </div>
                 <div class="col-md-8">
                     <div class="btn-group pull-right">
-                        <label class="btn btn-default" ng-click="importTemplates()">[% l('Import') %]</label>
-                        <label class="btn btn-default" ng-click="exportTemplates()">[% l('Export') %]</label>
+                        <span class="btn btn-default btn-file">
+                            [% l('Import') %]
+                            <input type="file" eg-file-reader container="imported_templates.data">
+                        </span>
+                        <label class="btn btn-default"
+                            eg-json-exporter container="templates"
+                            default-file-name="'[% l('exported_copy_templates.json') %]'">
+                            [% l('Export') %]
+                        </label>
                     </div>
                 </div>
             </div>
index 9bdec0b..cfd974a 100644 (file)
@@ -1624,9 +1624,24 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                 }
             
                 $scope.templates = {};
+                $scope.imported_templates = { data : '' };
                 $scope.template_name = '';
                 $scope.template_name_list = [];
-            
+
+                $scope.$watch('imported_templates.data', function(newVal, oldVal) {
+                    if (newVal && newVal != oldVal) {
+                        try {
+                            var newTemplates = JSON.parse(newVal);
+                            if (!Object.keys(newTemplates).length) return;
+                            $scope.templates = newTemplates;
+                            $scope.template_name_list = Object.keys(newTemplates);
+                            $scope.template_name = '';
+                        } catch (E) {
+                            console.log('tried to import an invalid copy template file');
+                        }
+                    }
+                });
+
                 $scope.tracker = function (x,f) { if (x) return x[f]() };
                 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
                 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };