Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions app/common/tmDetailFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,38 @@ function BaseDetail(
return deferred.promise;
};

this.stateCache = "";
// $state.stateCache = "";

this.close = function () {
var self = this;
// var self = this;
this.canILeave().then(function (canILeave) {

if (canILeave) {
let backState = self.$state.back.fromState.name;
self.docSvc.clearDocument();

let goListView = () => {
// we are going back to the list so clear out the $state.data for next circular issue
$state.data = null;
self.$state.go(self.constructorArgs.listView);
}

let goBack = () => {
$state.stateCache = self.$state.current.name;
self.$state.go(backState, $state.back.fromParams);
}

// !($state.data === backState) handle circlular issue with back button
// the back state and the to state are the same
if (backState && backState != "" && !($state.data === backState)) {
self.$state.go(backState, $state.back.fromParams);
if(backState == $state.stateCache) {
goListView();
} else {
goBack();
}
} else {
// we are going back to the list so clear out the $state.data for next circular issue
$state.data = null;
self.$state.go(self.constructorArgs.listView);
goListView();
}
}
});
Expand Down
12 changes: 11 additions & 1 deletion app/common/tmListFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ function BaseList(
var self = this;
let dfd = new Promise((resolve, reject) => {
self.setLoading(true);
self.Model.query(queryString, flush).then(function (items) {
self.Model.query(queryString, flush).then((items) => {
// console.log("items", items);
self.setLoading(false);
self.items = items;
self.afterLoad();
resolve(items);
}, (e) => {
console.log("err: ", e);
if(!e.success) {
if(e.hasOwnProperty("message")) {
self.tmNotifier.error(e.message);
} else {
self.tmNotifier.error("Failed to get data");
}
}
});
});
return dfd; //returns a promise, so we can work with the data.
Expand Down
4 changes: 4 additions & 0 deletions app/common/widgets/lookups.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ var Controller = ['$dataSource', '$attrs', '$injector', '$scope', '$timeout', fu
self.updateList();
}, 0);
}
}, (msg) => {
//i don't think this ever catches an error...
console.log("err: ", msg);
// throw(msg);
});


Expand Down
28 changes: 23 additions & 5 deletions dataNinja/cachedResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,36 @@ export default class CachedResource {
}

query(queryString, flush) {
// console.log("cachedResource query called")
var deferred = this.$q.defer();
queryString = queryString || {};
var self = this;
if (flush) {
self.List = null;
}
if (!self.List) {
self.Resource.query(queryString, function (data) {
var json = JSON.stringify(data.data);
var jsonParsed = JSON.parse(json, jsonReviver);
self.List = jsonParsed;
deferred.resolve(self.List);

self.Resource.query(queryString, (data) => {

let run = () => {
var json = JSON.stringify(data.data);
var jsonParsed = JSON.parse(json, jsonReviver);
self.List = jsonParsed;
deferred.resolve(self.List);
}

// console.log("data: ", data);
if(data.hasOwnProperty("success")) {
if(!data.success) {
deferred.reject(data);
} else {
run();
}
} else {
run();
}
});

}
else {
deferred.resolve(self.List);
Expand Down Expand Up @@ -99,6 +116,7 @@ export default class CachedResource {
if (response.noData) {
deferred.reject(response.noData);
}
// console.log("cachedResource: ", response.data);
var json = JSON.stringify(response.data);
var parsedJson = JSON.parse(json, jsonReviver);
var itemIndex = self.List.map(function (i) {
Expand Down