Roberto Sánchez
2014-01-13 225dc136c1c6fba26b2e4f8b763cbd3fc4d596e3
securis/src/main/resources/static/js/catalogs.js
....@@ -134,6 +134,33 @@
134134 this.query = function() {
135135 return this.getResource().query({}, _success, _fail);
136136 }
137
+ this.refreshRef = function(refs, res, preloadedData) {
138
+ // We check if there is some field for the resource passed as parameter
139
+ var field = (function() {
140
+ for (var i = _current.fields.length - 1; i >= 0; i--) {
141
+ if (_current.fields[i].resource === res)
142
+ return _current.fields[i];
143
+ }
144
+ return null;
145
+ })();
146
+
147
+ // If field for that resource is not found there is nothing to refresh
148
+ if (!field) return;
149
+ var resource = this.getResource(res);
150
+ var data = preloadedData || resource.query({}, _success, _fail);
151
+ var that = this;
152
+ data.$promise.then(function(responseData) {
153
+ var pk = that.getPk(that.getMetadata(field.resource))
154
+ var comboData = []
155
+ responseData.forEach(function(row) {
156
+ comboData.push({
157
+ id: row[pk],
158
+ label: row.label || row.name || row.code || row.first_name + ' ' + row.last_name
159
+ });
160
+ })
161
+ refs[field.name] = comboData;
162
+ })
163
+ }
137164 this.loadRefs = function(refs) {
138165 if (!_current) throw new Error('There is no current catalog selected');
139166 var refsFields = [];