--- /dev/null
+<div class="container-fluid" style="text-align:center">
+ <div class="alert alert-info alert-less-pad strong-text-2">
+ <span>[% l('EDI Attribute Sets') %]</span>
+ </div>
+</div>
+
+<div class="row">
+ <div class="col-md-4">
+ <div class="input-group">
+ <div class="input-group-btn" uib-dropdown>
+ <button type="button" class="btn btn-default" uib-dropdown-toggle>
+ [% l('Attribute Sets') %]
+ <span class="caret"></span>
+ </button>
+ <ul uib-dropdown-menu>
+ <li>
+ <a href='' ng-click="new_set()">
+ [% l('New Attribute Set...') %]</a>
+ </li>
+ <li class="divider"></li>
+ <li ng-repeat="set in attr_sets">
+ <a href='' ng-click="select_set(set)">{{set.label()}}</a>
+ </li>
+ </ul>
+ </div><!-- /btn-group -->
+ <input type="text" ng-if="!cur_attr_set"
+ class="form-control" disabled="disabled"
+ value="[% l('No Attribute Set Selected') %]"/>
+ <input type="text" ng-if="cur_attr_set"
+ class="form-control"
+ placeholder="[% l('Attribute Set Name...') %]"
+ ng-model-options="{ getterSetter: true }"
+ ng-model="cur_attr_set.label"/>
+ </div>
+ </div>
+ <div class="col-md-4">
+ <span class="pad-right">
+ <button class="btn btn-success"
+ ng-disabled="save_in_progress"
+ ng-click="apply()">[% l('Apply Changes') %]</button>
+ </span>
+ <span class="pad-right">
+ <button class="btn btn-warning"
+ ng-disabled="cur_attr_set_uses || save_in_progress"
+ ng-click="remove()">[% l('Delete Attribute Set') %]</button>
+ </span>
+ <span class="pad-right" style="font-style:italic">
+ [% l('Currently used by [_1] EDI account(s).', '{{cur_attr_set_uses}}') %]
+ </span>
+ </div>
+</div>
+
+<div class="pad-vert">
+ <div class="row" ng-repeat="attr in attrs | orderBy:'key()'"
+ ng-class="cur_attr_set._local_map[attr.key()] ? 'selected-row' : ''">
+ <div class="col-md-3">
+ <span class="pad-right-min">
+ <input type="checkbox"
+ ng-model="cur_attr_set._local_map[attr.key()]"/>
+ </span>
+ <span>{{attr.key()}}</span>
+ </div>
+ <div class="col-md-9">{{attr.label()}}</div>
+ </div>
+</div>
+
+
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/);
var resolver = {delay : function(egStartup) {return egStartup.go()}};
+ $routeProvider.when('/admin/acq/edi_attr_set', {
+ templateUrl: './admin/acq/t_edi_attr_set',
+ controller: 'EDIAttrSet',
+ resolve : resolver
+ });
+
var eframe_template =
'<eg-embed-frame allow-escape="true" min-height="min_height" url="acq_admin_url" handlers="funcs"></eg-embed-frame>';
}])
+.controller('EDIAttrSet',
+ ['$scope','$q','egCore','ngToast','egConfirmDialog',
+function($scope , $q , egCore , ngToast , egConfirmDialog) {
+
+ $scope.cur_attr_set = null;
+
+ // fetch all the data needed to render the page.
+ function load_data() {
+
+ return egCore.pcrud.retrieveAll('aea', {},
+ {atomic : true, authoritative : true})
+ .then(
+ function(attrs) {
+ $scope.attrs = attrs
+ return egCore.pcrud.retrieveAll('aeas',
+ {flesh : 1, flesh_fields : {'aeas' : ['attr_maps']}},
+ {atomic : true, authoritative : true}
+ )
+ }
+
+ ).then(function(sets) {
+ $scope.attr_sets = sets.sort(function(a, b) {
+ return a.label() < b.label() ? -1 : 1;
+ });
+
+ // create a simple true/false attr_set => attr mapping
+ var select_me;
+ angular.forEach(sets, function(set) {
+ set._local_map = {};
+ angular.forEach(set.attr_maps(), function(map) {
+ set._local_map[map.attr()] = true;
+ })
+
+ if ($scope.cur_attr_set && set.id()
+ == $scope.cur_attr_set.id()) {
+ select_me = set;
+ }
+ });
+
+ $scope.select_set(select_me || $scope.attr_sets[0]);
+ });
+ }
+
+ function create_sets() {
+ var new_sets = $scope.attr_sets.filter(function(set) {
+ if (set.isnew() && set.label()) {
+ console.debug('creating new set: ' + set.label());
+ return true;
+ }
+ return false;
+ });
+
+ if (new_sets.length == 0) return $q.when();
+
+ // create the new attrs sets and collect the newly generated
+ // ID in the local data store.
+ return egCore.pcrud.apply(new_sets).then(
+ null,
+ function() {
+ $scope.attr_sets = $scope.attr_sets.filter(
+ function(set) { return (set.label() && !set.isnew()) });
+ return $q.reject();
+ },
+ function(new_set) {
+ var old_set = new_sets.filter(function(s) {
+ return (s.isnew() && s.label() == new_set.label()) })[0];
+ old_set.id(new_set.id());
+ old_set.isnew(false);
+ }
+ );
+ }
+
+ function modify_maps() {
+ var update_maps = [];
+
+ angular.forEach($scope.attr_sets, function(set) {
+ console.debug('inspecting attr set ' + set.label());
+
+ // find maps that need deleting
+ angular.forEach(set.attr_maps(), function(oldmap) {
+ if (!set._local_map[oldmap.attr()]) {
+ console.debug('\tdeleting map for ' + oldmap.attr());
+ oldmap.isdeleted(true);
+ update_maps.push(oldmap);
+ }
+ });
+
+ // find maps that need creating
+ angular.forEach(set._local_map, function(value, key) {
+ if (!value) return;
+
+ var existing = set.attr_maps().filter(
+ function(emap) { return emap.attr() == key })[0];
+
+ if (existing) return;
+
+ console.debug('\tcreating map for ' + key);
+
+ var newmap = new egCore.idl.aeasm();
+ newmap.isnew(true);
+ newmap.attr(key);
+ newmap.attr_set(set.id());
+ update_maps.push(newmap);
+ });
+ });
+
+ return egCore.pcrud.apply(update_maps);
+ }
+
+ // mark the currently selected attr set as the main display set.
+ $scope.select_set = function(set) {
+ $scope.cur_attr_set_uses = 0; // how many edi accounts use this set
+ if (set.isnew()) {
+ $scope.cur_attr_set = set;
+ } else {
+ egCore.pcrud.search('acqedi', {attr_set : set.id()}, {},
+ {idlist : true, atomic : true}
+ ).then(function(accts) {
+ $scope.cur_attr_set_uses = accts.length;
+ $scope.cur_attr_set = set;
+ });
+ }
+ }
+
+ $scope.new_set = function() {
+ var set = new egCore.idl.aeas();
+ set.isnew(true);
+ set.attr_maps([]);
+ set._local_map = {};
+ $scope.select_set(set);
+ $scope.attr_sets.push(set);
+ }
+
+ $scope.apply = function() {
+ $scope.save_in_progress = true;
+ create_sets()
+ .then(modify_maps)
+ .then(
+ function() {
+ ngToast.create(egCore.strings.ATTR_SET_SUCCESS)
+ },
+ function() {
+ ngToast.warning(egCore.strings.ATTR_SET_ERROR);
+ return $q.reject();
+ })
+ .then(load_data)
+ .finally(
+ function() { $scope.save_in_progress = false; }
+ );
+ }
+
+ // Delete the currently selected attr set.
+ // Attr set maps will cascade delete.
+ $scope.remove = function() {
+ egConfirmDialog.open(
+ egCore.strings.ATTR_SET_DELETE_CONFIRM,
+ $scope.cur_attr_set.label()
+ ).result.then(function() {
+ $scope.save_in_progress = true;
+ ( // remove from server if necessary
+ $scope.cur_attr_set.isnew() ?
+ $q.when() :
+ egCore.pcrud.remove($scope.cur_attr_set)
+ ).then(
+ // remove from the local att_sets list
+ function() {
+ ngToast.create(egCore.strings.ATTR_SET_SUCCESS);
+ $scope.attr_sets = $scope.attr_sets.filter(
+ function(set) {
+ return set.id() != $scope.cur_attr_set.id()
+ }
+ );
+ $scope.cur_attr_set = $scope.attr_sets[0];
+ },
+ function() { ngToast.warning(egCore.strings.ATTR_SET_ERROR) }
+
+ ).finally(
+ function() { $scope.save_in_progress = false; }
+ );
+ });
+ }
+
+ load_data();
+}])
+
+
this.session.disconnect();
};
- this.retrieve = function(fm_class, pkey, pcrud_ops) {
+ this.retrieve = function(fm_class, pkey, pcrud_ops, req_ops) {
+ req_ops = req_ops || {};
+ this.authoritative = req_ops.authoritative;
return this._dispatch(
'open-ils.pcrud.retrieve.' + fm_class,
[egAuth.token(), pkey, pcrud_ops]
this.search = function (fm_class, search, pcrud_ops, req_ops) {
req_ops = req_ops || {};
+ this.authoritative = req_ops.authoritative;
var return_type = req_ops.idlist ? 'id_list' : 'search';
var method = 'open-ils.pcrud.' + return_type + '.' + fm_class;
},
// main body error handler
- function() {},
+ function() {deferred.reject()},
// main body notify() handler
function(data) {deferred.notify(data)}
self.cud_last = data;
self.cud_deferred.notify(data);
self._CUD_next_request();
- }
+ },
+ self.cud_deferred.reject
);
};