Author: jmorliaguet Date: Mon Feb 27 16:39:10 2006 New Revision: 2492 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Log:
- simplifications: perspectives are now managed via the "perspective selector" Controller instead of being managed globally. sub-perspectives are no longer needed. 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 Mon Feb 27 16:39:10 2006 @@ -45,9 +45,6 @@ _models: $H({}), _controllers: $H({}), _handlers: $H({}), - _perspectives: $H({}), - _currentPerspective: "", - _previousPerspective: "", init: function() { CPSSkins._parse(document); @@ -305,86 +302,12 @@ el.parentNode.insertBefore(view.widget, el); } - /* registers views per perspective */ - var perspectives = def.perspectives || []; - perspectives.each(function(p) { - if (!p) return; - if (!(p in CPSSkins._perspectives)) { - CPSSkins._perspectives[p] = []; - } - CPSSkins._perspectives[p].push(view); - }); //CPSSkins.notify("registered view " + def.id, view); } break; } } - }, - - _resolvePerspective: function(perspective) { - var path = CPSSkins._currentPerspective.split("/"); - var base = perspective; - var ext = ""; - - if (perspective == '..') { - if (path.length > 0) { - base = path.slice(0, path.length-1).join("/"); - } - } - - if (perspective.substr(0,2) == "./") { - base = CPSSkins._currentPerspective; - if (base) { - base += "/"; - } - ext = perspective.substr(2); - } - - var up = perspective.match(new RegExp(/\.\.\//g)); - if (up && (up.length <= path.length)) { - base = path.slice(0, path.length - up.length).join("/"); - if (base) { - base += "/"; - } - ext = perspective.substr(up.length*3); - } - - if (perspective == '-') { - base = CPSSkins._previousPerspective; - } - - return base + ext; - }, - - switchPerspective: function(perspective) { - var to_show = []; - var to_hide = []; - - perspective = CPSSkins._resolvePerspective(perspective); - CPSSkins._perspectives.each(function(s) { - var elements = s.value; - var path = perspective.split("/"); - path.each(function(p, index) { - var subpath = path.slice(0,index+1).join("/"); - if (s.key == subpath) { - elements.each(function(el) { to_show.push(el) } ); - } else { - elements.each(function(el) { to_hide.push(el) } ); - } - }); - }); - - // Do not hide objects to be shown - to_hide = to_hide.select(function(el) { - return to_show.indexOf(el) < 0; - }); - - to_hide.each(function(el) { el.hide(); }); - to_show.each(function(el) { el.show(); }); - - CPSSkins._previousPerspective = CPSSkins._currentPerspective; - CPSSkins._currentPerspective = perspective; } } @@ -620,17 +543,27 @@ new CPSSkins.Controller(), { setup: function() { - this._perspectives = {}; + this._visible_views = {}; }, register: function(view) { - var perspectives = this._perspectives; + var visible = this._visible_views; $A(view.def.perspectives).each(function(p) { - if (!(p in perspectives)) { - perspectives[p] = []; + if (!(p in visible)) { + visible[p] = []; } - perspectives[p].push(view); + visible[p].push(view); }); + }, + + switchTo: function(perspective) { + var to_show = this._visible_views[perspective]; + var to_hide = this.views.select(function(el) { + return to_show.indexOf(el) < 0; + }); + + to_hide.each(function(el) { el.hide(); }); + to_show.each(function(el) { el.show(); }); } }); -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins