Commit a92a65f2 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Do not clear the page if not needed

parent c169c45e
......@@ -18,7 +18,6 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_global.js" ></script>
<script src="erp5_launcher_nojqm.js"></script>
</head>
......
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.57378.47936.47257</string> </value>
<value> <string>952.64761.25287.18397</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1469799227.55</float>
<float>1475507009.62</float>
<string>UTC</string>
</tuple>
</state>
......
/*globals window, document, RSVP, rJS,
loopEventListener, URI, location, XMLHttpRequest, console*/
URI, location, XMLHttpRequest, console*/
/*jslint indent: 2, maxlen: 80*/
(function (window, document, RSVP, rJS, loopEventListener,
(function (window, document, RSVP, rJS,
XMLHttpRequest, location, console) {
"use strict";
......@@ -131,9 +131,6 @@
// Display it to the user for now,
// and allow user to go back to the frontpage
var error_text = "";
if (error instanceof RSVP.CancellationError) {
return;
}
if (error.target instanceof XMLHttpRequest) {
error_text = error.target.toString() + " " +
......@@ -159,17 +156,15 @@
}
function displayError(gadget, error) {
return new RSVP.Queue()
.push(function () {
return displayErrorContent(gadget, error);
})
.push(function () {
return gadget.dropGadget(MAIN_SCOPE)
.push(undefined, function () {
// Do not crash the app if the pg gadget in not defined
// ie, keep the original error on screen
return;
});
if (error instanceof RSVP.CancellationError) {
return;
}
displayErrorContent(gadget, error);
return gadget.dropGadget(MAIN_SCOPE)
.push(undefined, function () {
// Do not crash the app if the pg gadget in not defined
// ie, keep the original error on screen
return;
});
}
......@@ -449,13 +444,63 @@
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition("renderApplication", function (param_list) {
return this.renderXXX.apply(this, param_list);
return this.render.apply(this, param_list);
})
.declareMethod('updateDOM', function (modification_dict) {
var gadget = this,
route_result = gadget.state;
if (modification_dict.hasOwnProperty('url')) {
return new RSVP.Queue()
.push(function () {
return renderMainGadget(
gadget,
route_result.url,
route_result.options
);
})
.push(function (main_gadget) {
// Append loaded gadget in the page
if (main_gadget !== undefined) {
return main_gadget.getElement()
.push(function (fragment) {
var element = gadget.props.content_element,
content_container = document.createElement("div");
content_container.className = "ui-content " +
(gadget.props.sub_header_class || "");
// reset subheader indicator
delete gadget.props.sub_header_class;
// go to the top of the page
window.scrollTo(0, 0);
// Clear first to DOM, append after to reduce flickering/manip
while (element.firstChild) {
element.removeChild(element.firstChild);
}
content_container.appendChild(fragment);
element.appendChild(content_container);
return updateHeader(gadget);
// XXX Drop notification
// return header_gadget.notifyLoaded();
});
}
});
}
// Same subgadget
return gadget.getDeclaredGadget(MAIN_SCOPE)
.push(function (page_gadget) {
return page_gadget.render(gadget.state.options);
})
.push(function () {
return updateHeader(gadget);
});
})
// Render the page
.declareMethod('renderXXX', function (options) {
.declareMethod('render', function (route_result) {
var gadget = this;
gadget.props.options = options;
// Reinitialize the loading counter
gadget.props.loading_counter = 0;
// By default, init the header options to be empty
......@@ -478,45 +523,8 @@
return editor_panel.close();
})
.push(function () {
return gadget.getDeclaredGadget('router');
})
.push(function (router_gadget) {
return router_gadget.route(options);
})
.push(function (route_result) {
return renderMainGadget(
gadget,
route_result.url,
route_result.options
);
})
.push(function (main_gadget) {
// Append loaded gadget in the page
if (main_gadget !== undefined) {
return main_gadget.getElement()
.push(function (fragment) {
var element = gadget.props.content_element,
content_container = document.createElement("div");
content_container.className = "ui-content " +
(gadget.props.sub_header_class || "");
// reset subheader indicator
delete gadget.props.sub_header_class;
// go to the top of the page
window.scrollTo(0, 0);
// Clear first to DOM, append after to reduce flickering/manip
while (element.firstChild) {
element.removeChild(element.firstChild);
}
content_container.appendChild(fragment);
element.appendChild(content_container);
return updateHeader(gadget);
// XXX Drop notification
// return header_gadget.notifyLoaded();
});
}
return gadget.changeState({url: route_result.url,
options: route_result.options});
})
.push(function () {
return decreaseLoadingCounter(gadget);
......@@ -525,9 +533,6 @@
.push(function () {
throw error;
});
})
.push(undefined, function (error) {
return displayError(gadget, error);
});
})
......@@ -540,28 +545,13 @@
// don't fail in case of dropped subgadget (like previous page)
return;
}
return displayError(this, param_list[0]);
})
.declareService(function () {
////////////////////////////////////
// Form submit listening. Prevent browser to automatically
// handle the form submit in case of a bug
////////////////////////////////////
var gadget = this;
function catchFormSubmit() {
return displayError(gadget, new Error("Unexpected form submit"));
}
// Listen to form submit
return loopEventListener(
gadget.props.element,
'submit',
false,
catchFormSubmit
);
.onEvent('submit', function () {
return displayError(this, new Error("Unexpected form submit"));
});
}(window, document, RSVP, rJS, loopEventListener,
}(window, document, RSVP, rJS,
XMLHttpRequest, location, console));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.40892.47649.37836</string> </value>
<value> <string>954.23080.38606.35464</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1472730123.87</float>
<float>1475507095.45</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -8,7 +8,7 @@
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="gadget_global.js" type="text/javascript"></script>
<script src="gadget_erp5_router.js" type="text/javascript"></script>
</head>
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>951.59695.16580.9642</string> </value>
<value> <string>952.64761.25287.18397</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1467045550.43</float>
<float>1475507751.57</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -27,7 +27,6 @@
COMMAND_SELECTION_NEXT = "selection_next",
COMMAND_HISTORY_PREVIOUS = "history_previous",
COMMAND_PUSH_HISTORY = "push_history",
REDIRECT_TIMEOUT = 5055,
VALID_URL_COMMAND_DICT = {};
VALID_URL_COMMAND_DICT[COMMAND_DISPLAY_STATE] = null;
VALID_URL_COMMAND_DICT[COMMAND_DISPLAY_STORED_STATE] = null;
......@@ -55,26 +54,8 @@
return window.location.replace(hash);
}
function timeoutUrlChange(from_hash, to_hash) {
// prevent returning unexpected response
// wait for the hash change to occur
// fail if nothing happens
return new RSVP.Queue()
.push(function () {
return RSVP.timeout(REDIRECT_TIMEOUT);
})
.push(undefined, function (error) {
if (error === 'Timed out after ' + REDIRECT_TIMEOUT + ' ms') {
throw new Error('URL handling timeout. From: "' + from_hash + '" to: "' + to_hash + '" and current: "' + window.location.hash + '"');
}
throw error;
});
}
function synchronousChangeState(hash) {
var from_hash = window.location.hash;
changeState(hash);
return timeoutUrlChange(from_hash, hash);
return changeState(hash);
}
//////////////////////////////////////////////////////////////////
......@@ -309,7 +290,6 @@
queue = new RSVP.Queue();
}
return queue
.push(function () {
return synchronousChangeState(
......@@ -732,15 +712,25 @@
}
}
return gadget.renderApplication({
return gadget.route({
method: command[0],
path: command.substr(1),
args: args
});
}
function catchError(evt) {
return new RSVP.Queue()
.push(function () {
return extractHashAndDispatch(evt);
})
.push(undefined, function (error) {
return gadget.renderError(error);
});
}
var result = loopEventListener(window, 'hashchange', false,
extractHashAndDispatch),
catchError),
event = document.createEvent("Event");
event.initEvent('hashchange', true, true);
event.newURL = window.location.toString();
......@@ -839,9 +829,7 @@
delete options.form_content;
return this.getCommandUrlFor(options)
.push(function (hash) {
var from_hash = window.location.hash;
window.location.replace(hash);
return timeoutUrlChange(from_hash, hash);
return synchronousChangeState(hash);
});
})
......@@ -850,18 +838,28 @@
})
.declareMethod('route', function (command_options) {
var gadget = this;
var gadget = this,
result;
if (command_options.method === PREFIX_DISPLAY) {
return routeDisplay(gadget, command_options);
}
if (command_options.method === PREFIX_COMMAND) {
return routeCommand(gadget, command_options);
}
if (command_options.method) {
throw new Error('Unsupported hash method: ' + command_options.method);
result = routeDisplay(gadget, command_options);
} else if (command_options.method === PREFIX_COMMAND) {
result = routeCommand(gadget, command_options);
} else {
if (command_options.method) {
throw new Error('Unsupported hash method: ' + command_options.method);
}
result = routeMethodLess(gadget);
}
return routeMethodLess(gadget);
return new RSVP.Queue()
.push(function () {
return result;
})
.push(function (route_result) {
if ((route_result !== undefined) && (route_result.url !== undefined)) {
return gadget.renderApplication(route_result);
}
});
})
.declareMethod('start', function () {
......@@ -873,6 +871,7 @@
.declareAcquiredMethod('jio_getAttachment', 'jio_getAttachment')
.declareAcquiredMethod('setSetting', 'setSetting')
.declareAcquiredMethod('getSetting', 'getSetting')
.declareAcquiredMethod('renderError', 'reportServiceError')
.declareService(function () {
var gadget = this;
......@@ -881,7 +880,6 @@
return gadget.props.start_deferred.promise;
})
.push(function () {
// console.info('router service: listen to hash change');
return listenHashChange(gadget);
});
});
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.11450.4967.32904</string> </value>
<value> <string>954.23085.57259.2628</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1467212877.23</float>
<float>1475507467.96</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment