[Z3lab-checkins] r2654 - cpsskins/branches/jmo-perspectives/ui/framework
Author: jmorliaguet Date: Sat Mar 18 16:31:40 2006 New Revision: 2654 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Log: - fixes: MVC components should only be instanciated once otherwise there is no way to store permanent information in the instances. 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 Sat Mar 18 16:31:40 2006 @@ -272,22 +272,27 @@ switch(classid) { case controller: { - var controller_type = def.type || command; - var factory = this.Controllers[controller_type]; - if (factory) { -var controller = factory(node, def); -controller.setup(); -this._controllers[id] = controller; -CPSSkins.notify(registered controller, - {'publisher': controller, 'scope': id} -); + var controller = this.getControllerById(id); + if (!controller) { +var controller_type = def.type || command; +var factory = this.Controllers[controller_type]; +if (factory) { + controller = factory(node, def); + this._controllers[id] = controller; +} } + CPSSkins.notify(registered controller, +{'publisher': controller, 'scope': id} + ); break; } case model: { - var model = new CPSSkins.Model(node, def); - this._models[id] = model; + var model = this.getModelById(id); + if (!model) { +model = new CPSSkins.Model(node, def); +this._models[id] = model; + } CPSSkins.notify(registered model, {'publisher': model, 'scope': id} ); @@ -295,7 +300,6 @@ } case view: { - var view; var widget_type; var template = def.widget.template; @@ -322,9 +326,12 @@ } } - factory = this.Widgets[widget_type]; - view = factory(def); - this._views[id] = view; + var view = this.getViewById(id); + if (!view) { +factory = this.Widgets[widget_type]; +view = factory(def); +this._views[id] = view; + } /* create the view */ if (view) { @@ -424,6 +431,7 @@ this.node = node; this.def = def; this.views = new CPSSkins.Set(); +this.setup(); }, hash: function() { @@ -1899,7 +1907,7 @@ var parts = url.split('?'); if (parts.length == 2) { -var url = parts[0]; +url = parts[0]; options.parameters = parts[1]; } new Ajax.Updater(widget, url, options); -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins
[Z3lab-checkins] r2655 - cpsskins/branches/jmo-perspectives/ui/framework
Author: jmorliaguet Date: Sat Mar 18 16:51:08 2006 New Revision: 2655 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Log: - Perspective controllers now remember the current perspective (the initial perspective is used if there is no current perspective) - added an 'update(view)' function to make it possible for a controller to update the view. 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 Sat Mar 18 16:51:08 2006 @@ -448,6 +448,10 @@ unregister: function(view) { /* to override */ + }, + + update: function(view) { +/* to override */ } } @@ -857,14 +861,14 @@ setup: function() { this._visible_views = {}; +this._current = null; CPSSkins.registerEventHandler(parsed, this, function(event) { - var initial = this.def.initial; - if (initial) { -this.switchTo(initial); + var perspective = this._current || this.def.initial; + if (perspective) { +this.switchTo(perspective); } }.bind(this)); CPSSkins.subscribe(parsed, {subscriber: this, publisher: this.node}); -this._current = null; }, register: function(view) { @@ -875,15 +879,19 @@ if (!(p in visible)) { visible[p] = []; } - if (!(view_id in visible[p])) { + if (visible[p].indexOf(view_id) 0) { visible[p].push(view_id); } - if (p == current_perspective) { -CPSSkins.getViewById(view_id).show(); - } }); }, + update: function(view) { +var current_perspective = this._current; +if ($A(view.def.perspectives).indexOf(current_perspective) = 0) { + view.show(); +} + }, + switchTo: function(perspective) { this._current = perspective; var to_show = this._visible_views[perspective] || []; @@ -1657,6 +1665,7 @@ controller.views.add(this.hash()); controller.unregister(this); controller.register(this); +controller.update(this); }, observe: function(model) { -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins
[Z3lab-checkins] r2657 - cookbook/trunk
Author: tziade Date: Sun Mar 19 00:30:11 2006 New Revision: 2657 Modified: cookbook/trunk/recipe57.fr.tex Log: french version Modified: cookbook/trunk/recipe57.fr.tex == --- cookbook/trunk/recipe57.fr.tex (original) +++ cookbook/trunk/recipe57.fr.tex Sun Mar 19 00:30:11 2006 @@ -9,11 +9,235 @@ \chapter*{Organiser le code dans un paquet} \begin{problem} -Pas encore traduit de l'anglais. +Un paquet est compos� de fichiers Python et ZCML, parfois de Page Templates +et de resources, que ce soit des fichiers CSS, Javascript, ou des images. + +Cette recette explique comment organiser tout ces �l�ments, pour rendre +le paquet facile � maintenir. \end{problem} \begin{solution} -Pas encore traduit de l'anglais. + +\section*{Comprendre ce qu'est un paquet} + +La d�finition d'un paquet en Python est: un r�pertoire contenant des modules +et des sous-r�pertoire, le tout composant un espace de nom ajout� au chemin +de l'interpr�teur. Chaque r�pertoire composant le paquet doit contenir un +fichier \code{\_\_init\_\_.py} pour �tre pris en compte. + +Zope utilise les paquets pour d�finir son code d'extension. Ces paquets +s'appelaient des \textit{Produits} sous Zope 2, puis ont repris le nom plus +pythonique de \textit{paquet} sous Zope 3. Comme l'initialisation d'une +extension se fait par la lecture des directives ZCML, Zope agit comme Python +mais en recherchant pour sa part le fichier \code{configure.zcml} du paquet. + +Aux yeux de Zope, le code peut donc �tre organis� de n'importe quelle mani�re +dans le paquet, du moment qu'il est li� dans le fichier ZCML. Mais pour +faciliter la maintenance et l'�volution, un minimum de structuration est +n�cessaire, bas� sur quelques conventions. + +\section*{D�finir une structure minimum} + +Le plus petit paquet possible est compos� d'un fichier \code{\_\_init\_\_.py} +vide, et d'un fichier \code{configure.zcml} contenant au minimum une directive +\code{configure} vide. + +\codetitle{Le plus petit fichier configure.zcml possible:} +\begin{verbatim} +configure\ +\end{verbatim} + +Ces deux fichiers sont r�unis dans un dossier, qui est d�clar� dans un fichier +de configuration plac� dans le dossier \textit{INSTANCE/etc/package-includes}. +Zope parcourt au d�marrage \textit{package-includes} pour conna�tre la liste +des paquets � initialiser. Les fichiers de ce dossier doivent avoir un nom +avec un suffixe \textit{-configure.zcml}, et utilisent en g�n�ral le nom +du paquet. Le paquet \textit{dummypackage} aura donc comme fichier de +d�claration \textit{dummypackage-configure.zcml}. + +\codetitle{Le fichier dummypackage-configure.zcml:} +\begin{verbatim} +include package=dummypackage/ +\end{verbatim} + +Au d�marrage, Zope int�grera le premier paquet nomm� \code{dummypackage} +trouv� dans son chemin. La meilleure place pour conserver les paquets est +\code{INSTANCE/lib/python}. + +\section*{D�finir une structure plus avanc�e} + +Le paquet \code{dummypackage} va maintenant impl�menter une fonctionnalit� +simple, qui se base sur une structure typique: un nouveau type d'objet +qui conserve en interne le nombre de fois qu'il a �t� appel� par une vue. +Le paquet a donc besoin de d�finir: + +\begin{itemize} +\item Une d�claration d'interface; +\item une classe de contenu. +\item une classe de vue; +\end{itemize} + +\subsection*{D�claration d'interface} + +Toutes les d�clarations d'interface d'un paquet sont r�unies dans un fichier +unique nomm� {interfaces.py}. Cette convention offre: + +\begin{itemize} +\item Une mani�re unique de faire r�f�rence � des interfaces. Par exemple, +l'attribut \code{for} d'une directive \code{browser:view} est toujours de la +forme : \textit{package.interfaces.IMyInterface}. +\item Des facilit�s pour organiser l'h�ritage entre les interfaces. +\end{itemize} + +L'interface de l'exemple se nomme \code{IDummyCounter} et est ajout�e au +fichier \code{interfaces.py}. + +\codetitle{interfaces.py:} +\begin{verbatim} +from zope.interface import Interface + +class IDummyCounter(Interface): + +def count(): + returns the counter value +after it has been inc'ed + +\end{verbatim} + +\subsection*{Classe de contenu} + +La classe de contenu g�re le compteur, et d�rive d'une classe persistante de +base, qui permet son stockage dans la ZODB. Cette classe est sauvegard�e dans +un fichier portant le m�me nom. + +\codetitle{dummycounter.py:} +\begin{verbatim} +import persistent +from zope.interface import implements +from interfaces import IDummyCounter + +class DummyCounter(persistent.Persistent): + +implements(IDummyCounter) + +def __init__(self, initial=0): +self._count = initial + +def count(self): +self._count += 1 +return self._count + +\end{verbatim} + +\code{DummyCounter} est d�j� fonctionnel. + +\codetitle{Tests de DummyCounter dans un prompt:} +\begin{verbatim} + from dummypackage.dummycounter import DummyCounter +
[Z3lab-checkins] r2658 - cookbook/trunk
Author: tziade Date: Sun Mar 19 00:31:14 2006 New Revision: 2658 Modified: cookbook/trunk/recipe57.en.tex Log: tipos Modified: cookbook/trunk/recipe57.en.tex == --- cookbook/trunk/recipe57.en.tex (original) +++ cookbook/trunk/recipe57.en.tex Sun Mar 19 00:31:14 2006 @@ -46,7 +46,7 @@ \end{verbatim} These two files are gathered in a folder, which is declared in a configuration -file in the \code{INSTANCE/etc/package-includes} folder. The configuration file +file in the \textit{INSTANCE/etc/package-includes} folder. The configuration file has to be named with a \textit{-configure.zcml} suffix, and conventionally uses the package folder name to complete its name. So a package called \textit{dummypackage} will have a \textit{dummypackage-configure.zcml} file, @@ -62,14 +62,14 @@ \section*{Setting up a real-world structure} -The \code{dummy} package will now implement a simple feature to demonstrate -a typical structure: a new kind of object that keep a track of the number -of times it has been accessed through a view. The package therefore needs: +The \code{dummypackage} package will now implement a simple feature to +demonstrate a typical structure: a new kind of object that keep a track of the +number of times it has been accessed through a view. The package therefore needs: \begin{itemize} \item An interface declaration; -\item a view class; \item a content class. +\item a view class; \end{itemize} \subsection*{Interface declaration} @@ -227,8 +227,9 @@ This structure is a module-based structure, and fits well for our simple example. When the package gets bigger, it's better to use a folder-based organization, by making \code{interfaces} and \code{browser} become -subfolders. The \code{browser} folder can then hold its own -\code{configure.zcml}, included in the main ZCML file, and so forth. +subfolders. The \code{browser} folder define modules for view and holds its +own \code{configure.zcml}, included in the main ZCML file, and so forth. +The \code{interfaces} folder holds modules for interfaces. \end{solution} \end{document} -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins