back route and isReturn

This commit is contained in:
yuri
2015-09-02 11:20:00 +03:00
parent 759ad1a8d3
commit 80334d59ff
2 changed files with 38 additions and 0 deletions
@@ -64,6 +64,9 @@ Espo.define('controllers/record', 'controller', function (Dep) {
list: function (options) {
var isReturn = options.isReturn;
if (this.getRouter().backProcessed) {
isReturn = true;
}
var key = this.name + 'List';
+35
View File
@@ -41,10 +41,45 @@ Espo.define('router', [], function () {
confirmLeaveOut: false,
backProcessed: false,
confirmLeaveOutMessage: 'Are you sure?',
initialize: function () {
this.history = [];
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function () {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
if (onBack) {
onBack();
}
} else {
hashHistory.push(hash);
if (onForward) {
onForward();
}
}
} else {
hashHistory.push(hash);
historyLength = length;
}
}
};
window.addEventListener('hashchange', detectBackOrForward(function () {
this.backProcessed = true;
setTimeout(function () {
this.backProcessed = false;
}.bind(this), 50);
}.bind(this)));
this.on('route', function () {
this.history.push(Backbone.history.fragment);
});