[Z3lab-checkins] r2659 - cpsskins/branches/jmo-perspectives/ui/framework
Author: jmorliaguet Date: Sun Mar 19 12:52:19 2006 New Revision: 2659 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Log: - added a Location Controller, which intercepts click events on links and make it possible to update the model without reloading the entire page. (useful to navigate inside a same panel, or to get data / perform an action on the server without changing the page's url) Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js == --- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar 19 12:52:19 2006 @@ -469,6 +469,10 @@ return new CPSSkins.FormController(node, def); }, + 'location': function(node, def) { +return new CPSSkins.LocationController(node, def); + }, + 'focus observer': function(node, def) { return new CPSSkins.FocusObserver(node, def); }, @@ -535,8 +539,7 @@ var handler_name = s.value; var handler = CPSSkins._handlers[handler_name]; selector.each(function(el) { -Event.observe(el, event_name, - handler.bindAsEventListener(info)); +Event.observe(el, event_name, handler.bindAsEventListener(info)); }); }) } @@ -581,6 +584,41 @@ }); +CPSSkins.LocationController = Class.create(); +CPSSkins.LocationController.prototype = Object.extend( + new CPSSkins.Controller(), { + + setup: function() { +this.clickEvent = this.clickEvent.bindAsEventListener(this); + }, + + register: function(view) { +Event.observe(view.widget, click, this.clickEvent); + }, + + unregister: function(view) { +Event.stopObserving(view.widget, click, this.clickEvent); + }, + + clickEvent: function(e) { +var target = Event.element(e); +if (target.tagName.toLowerCase() == 'a') { + var url = target.href; + + var views = this.views; + var location_field = this.def.location_field || 'url'; + views.each(function(v) { +var view = CPSSkins.getViewById(v); +var model = view.model; +if (model) model.setData({location_field: url}); + }); + + Event.stop(e); +} + } + +}); + CPSSkins.FocusObserver = Class.create(); CPSSkins.FocusObserver.prototype = Object.extend(new CPSSkins.Controller(), { @@ -1543,7 +1581,7 @@ } var parts = url.split('?'); if (parts.length == 2) { - var url = parts[0]; + url = parts[0]; options.parameters = parts[1]; } new Ajax.Request(url, options); -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins
[Z3lab-checkins] r2661 - cpsskins/branches/jmo-perspectives/ui/framework
Author: jmorliaguet Date: Sun Mar 19 15:38:31 2006 New Revision: 2661 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Log: - Location Controller: simpler usage, added support for response headers (attachments), Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js == --- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar 19 15:38:31 2006 @@ -603,15 +603,36 @@ clickEvent: function(e) { var target = Event.element(e); if (target.tagName.toLowerCase() == 'a') { - var url = target.href; - + var href = target.href; var views = this.views; - var location_field = this.def.location_field || 'url'; - views.each(function(v) { -var view = CPSSkins.getViewById(v); -var model = view.model; -if (model) model.setData({location_field: url}); - }); + + var options = { +onComplete: function(req) { + var resp = req.responseText; + var disp = req.getResponseHeader('content-disposition'); + if (disp disp.match(/^attachment/)) { +window.location = href; + } + if (resp) { +var data = JSON.parse(resp); + } + views.entries().each(function(v) { +var view = CPSSkins.getViewById(v); +if (data) { + view.model.setData(data); +} else { + view.refresh(); +} + }); +} + } + + var parts = href.split('?'); + if (parts.length == 2) { +url = parts[0]; +options.parameters = parts[1]; + } + new Ajax.Request(url, options); Event.stop(e); } -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins
[Z3lab-checkins] r2665 - cpsskins/branches/jmo-perspectives/ui/framework
Author: jmorliaguet Date: Sun Mar 19 18:21:55 2006 New Revision: 2665 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Log: - handle redirections Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js == --- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar 19 18:21:55 2006 @@ -1944,6 +1944,7 @@ var view = this; if (url) { var widget = this.widget; + var model = this.model; var options = { onComplete: function(req) { var disp = req.getResponseHeader('content-disposition'); @@ -1954,6 +1955,10 @@ CPSSkins._parse(widget); view.attachControllers(); } + var location = req.getResponseHeader('Location'); + if (location) { +model.setData({'url': location}) + } } }; -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins
[Z3lab-checkins] r2667 - in cpsskins/branches/jmo-perspectives/ui: framework screens/sitedesigner
Author: jmorliaguet Date: Sun Mar 19 19:07:50 2006 New Revision: 2667 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js cpsskins/branches/jmo-perspectives/ui/screens/sitedesigner/views.py Log: - added a View.requests(url) method to avoid having to handle redirections. panel.request(url) requests a url but the panel's url is unchanged unless the response explicitly overrides the 'url' variable. Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js == --- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar 19 19:07:50 2006 @@ -606,7 +606,7 @@ this.views.entries().each(function(v) { var view = CPSSkins.getViewById(v); -view.model.setData({'url': target.href}); +view.request(target.href); }) Event.stop(e); @@ -1684,6 +1684,10 @@ /* to override: tear down the widget after hiding it */ }, + request: function(url) { +/* to override: request an url */ + }, + /* Private API */ getControllers: function() { return this.def.controllers || [] @@ -1924,6 +1928,26 @@ return '[CPSSkins Panel]'; }, + request: function(url) { +var view = this; +var options = { + onComplete: function(req) { +var disp = req.getResponseHeader('content-disposition'); +if (disp disp.match(/^attachment/)) { + window.location = url; +} +view.refresh(); + } +}; +var parts = url.split('?'); +var method = url; +if (parts.length == 2) { + method = parts[0]; + options.parameters = parts[1]; +} +new Ajax.Request(method, options); + }, + render: function(data) { var url = data.url; if (!url) { @@ -1945,20 +1969,11 @@ if (url) { var widget = this.widget; var model = this.model; + var view = this; var options = { -onComplete: function(req) { - var disp = req.getResponseHeader('content-disposition'); - if (disp disp.match(/^attachment/)) { -window.location = url; - } else { -widget.innerHTML = req.responseText; -CPSSkins._parse(widget); -view.attachControllers(); - } - var location = req.getResponseHeader('Location'); - if (location) { -model.setData({'url': location}) - } +onComplete: function() { + CPSSkins._parse(widget); + view.attachControllers(); } }; @@ -1968,7 +1983,7 @@ method = parts[0]; options.parameters = parts[1]; } - new Ajax.Request(method, options); + new Ajax.Updater(widget, method, options); } }, Modified: cpsskins/branches/jmo-perspectives/ui/screens/sitedesigner/views.py == --- cpsskins/branches/jmo-perspectives/ui/screens/sitedesigner/views.py (original) +++ cpsskins/branches/jmo-perspectives/ui/screens/sitedesigner/views.py Sun Mar 19 19:07:50 2006 @@ -59,7 +59,6 @@ resources = getUtility(IResourceManager) resources.customize(name=name, context=self.context) -self.request.response.redirect('@@settings-section.html') def decustomizeSetting(self, name=u''): if not name: @@ -67,7 +66,6 @@ resources = getUtility(IResourceManager) resources.decustomize(name=name, context=self.context) -self.request.response.redirect('@@settings-section.html') def removeSetting(self, name=u''): if not name: @@ -75,7 +73,6 @@ resources = getUtility(IResourceManager) resources.unregister(name=name, context=self.context) -self.request.response.redirect('@@settings-section.html') def exportSetting(self, name=u''): Export the setting as an XML file. @@ -96,14 +93,12 @@ response.setHeader('content-type', 'text/xml') response.setHeader('Content-disposition', 'attachment; filename=%s' % setting_filename) -response.setHeader('Location', '@@settings-section.html') # export the resource exporter = getMultiAdapter((resource, request), IDataExporter) # remove the xml header used in the resource resource_xml = exporter().replace('?xml version=1.0?', '') - return setting_xml % { 'name': name, 'title': setting.title, @@ -114,4 +109,3 @@ Reload the setting from the file-system reloadSetting(name) -self.request.response.redirect('@@settings-section.html') -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins
[Z3lab-checkins] r2668 - cpsskins/branches/jmo-perspectives/ui/framework
Author: jmorliaguet Date: Sun Mar 19 19:32:20 2006 New Revision: 2668 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Log: - make sure we get a response with text/x-json as content type before parsing it. Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js == --- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar 19 19:32:20 2006 @@ -607,8 +607,7 @@ this.views.entries().each(function(v) { var view = CPSSkins.getViewById(v); view.request(target.href); - }) - + }); Event.stop(e); } } @@ -1571,8 +1570,11 @@ if (!url) return; var options = { onComplete: function(req) { -var data = JSON.parse(req.responseText); -storage.write(data); +var content_type = req.getResponseHeader('content-type'); +if (content_type.match(/^text\/x-json/)) { + var data = JSON.parse(req.responseText); + storage.write(data); +} } } var parts = url.split('?'); @@ -1936,6 +1938,11 @@ if (disp disp.match(/^attachment/)) { window.location = url; } +var content_type = req.getResponseHeader('content-type'); +if (content_type.match(/^text\/x-json/)) { + var data = JSON.parse(req.responseText); + view.model.writeData(data); +} view.refresh(); } }; -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins
[Z3lab-checkins] r2670 - in cpsskins/branches/jmo-perspectives/ui: framework framework/tests/zope3/functional/panels panels
Author: jmorliaguet Date: Sun Mar 19 21:21:34 2006 New Revision: 2670 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/cpsskins_panels.pt cpsskins/branches/jmo-perspectives/ui/panels/settings.pt Log: - renamed LocationController as RemoteScriptingController - some refactoring Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js == --- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar 19 21:21:34 2006 @@ -469,8 +469,8 @@ return new CPSSkins.FormController(node, def); }, - 'location': function(node, def) { -return new CPSSkins.LocationController(node, def); + 'remote scripting': function(node, def) { +return new CPSSkins.RemoteScriptingController(node, def); }, 'focus observer': function(node, def) { @@ -584,8 +584,8 @@ }); -CPSSkins.LocationController = Class.create(); -CPSSkins.LocationController.prototype = Object.extend( +CPSSkins.RemoteScriptingController = Class.create(); +CPSSkins.RemoteScriptingController.prototype = Object.extend( new CPSSkins.Controller(), { setup: function() { @@ -604,12 +604,38 @@ var target = Event.element(e); if (target.tagName.toLowerCase() == 'a') { + var _request = this._request; this.views.entries().each(function(v) { var view = CPSSkins.getViewById(v); -view.request(target.href); +_request(view, target.href); }); + Event.stop(e); } + }, + + _request: function(view, url) { +var options = { + onComplete: function(req) { +var disp = req.getResponseHeader('content-disposition'); +if (disp disp.match(/^attachment/)) { + window.location = url; +} +var content_type = req.getResponseHeader('content-type'); +if (content_type.match(/^text\/x-json/)) { + var data = JSON.parse(req.responseText); + view.model.writeData(data); +} +view.refresh(); + } +}; +var parts = url.split('?'); +var method = url; +if (parts.length == 2) { + method = parts[0]; + options.parameters = parts[1]; +} +new Ajax.Request(method, options); } }); @@ -1686,10 +1712,6 @@ /* to override: tear down the widget after hiding it */ }, - request: function(url) { -/* to override: request an url */ - }, - /* Private API */ getControllers: function() { return this.def.controllers || [] @@ -1930,31 +1952,6 @@ return '[CPSSkins Panel]'; }, - request: function(url) { -var view = this; -var options = { - onComplete: function(req) { -var disp = req.getResponseHeader('content-disposition'); -if (disp disp.match(/^attachment/)) { - window.location = url; -} -var content_type = req.getResponseHeader('content-type'); -if (content_type.match(/^text\/x-json/)) { - var data = JSON.parse(req.responseText); - view.model.writeData(data); -} -view.refresh(); - } -}; -var parts = url.split('?'); -var method = url; -if (parts.length == 2) { - method = parts[0]; - options.parameters = parts[1]; -} -new Ajax.Request(method, options); - }, - render: function(data) { var url = data.url; if (!url) { Modified: cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/cpsskins_panels.pt == --- cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/cpsskins_panels.pt (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/cpsskins_panels.pt Sun Mar 19 21:21:34 2006 @@ -28,7 +28,7 @@ /head body - h1CPSSkins Panels / IFrames/h1 + h1CPSSkins Panels / Remote scripting/h1 pThe panel shown below has a form controller attached to it. When the user clicks on the click me! button a remote call is done to the server which @@ -37,8 +37,8 @@ pThis makes it possible to perform a form submission with a redirection inside a given area of a page without reloading the entire page. /p - pThere is also a Location controller which make it possible - to follow the links, or get data from the server without reloading the page. + pThere is also a Remote Scripting Controller which converts HTML links + into ajax request to do remote server scripting without reloading the page. /p ins class=model @@ -72,7 +72,7 @@ {id: panel-view, model: panel, perspectives: [default], - controllers: [show-panel, form, location1], + controllers: [show-panel, form, request1], widget: { type: panel }, @@ -88,7 +88,7