Sha256: aa990f1910280757ad1f0ef2ead41bdb415fc3b8bd1e8c684c1b3429b9ad27bf
Contents?: true
Size: 1.64 KB
Versions: 2
Compression:
Stored size: 1.64 KB
Contents
pw.component.register('mutable', function (view, config) { this.mutation = function (mutation) { // no socket, just submit the form if (!window.socket) { view.node.submit(); return; } var datum = pw.util.dup(mutation); delete datum.__nested; delete datum.scope; delete datum.id; var message = { action: 'call-route' }; if (view.node.tagName === 'FORM') { if (view.node.querySelector('input[type="file"]')) { // file uploads over websocket are not supported view.node.submit(); return; } var method; var $methodOverride = view.node.querySelector('input[name="_method"]'); if ($methodOverride) { method = $methodOverride.value; } else { method = view.node.getAttribute('method'); } message.method = method; message.uri = view.node.getAttribute('action'); message.input = pw.node.serialize(view.node); } else { //TODO deduce uri / method var input = {}; input[mutation.scope] = datum; message.input = input; } var self = this; window.socket.send(message, function (res) { if (res.status === 302 && res.headers.Location !== window.location.pathname) { var dest = res.headers.Location; //TODO trigger a response:redirect instead and let navigator subscribe history.pushState({ uri: dest }, dest, dest); return; } else if (res.status === 400) { // bad request } else { self.state.rollback(); } pw.component.broadcast('response:received', { response: res }); self.revert(); }); } });
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pakyow-0.10.1 | lib/generators/pakyow/app/templates/public/scripts/ring/components/mutable.js |
pakyow-0.10.0 | lib/generators/pakyow/app/templates/public/scripts/ring/components/mutable.js |