r137 - in trunk/cantharella.web/src/main: java/nc/ird/cantharella/web/pages/domain/molecule java/nc/ird/cantharella/web/utils/behaviors resources webapp/js
Author: echatellier Date: 2013-02-20 15:35:29 +0100 (Wed, 20 Feb 2013) New Revision: 137 Url: http://forge.codelutin.com/projects/cantharella/repository/revisions/137 Log: Fix linkable canvas to download image and add download mol file link Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.html trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/behaviors/MoleculeViewBehavior.java trunk/cantharella.web/src/main/resources/web_en.properties trunk/cantharella.web/src/main/resources/web_fr.properties trunk/cantharella.web/src/main/webapp/js/molviewer.js Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java 2013-02-20 06:06:04 UTC (rev 136) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java 2013-02-20 14:35:29 UTC (rev 137) @@ -223,9 +223,7 @@ formView .add(new HiddenField<String>("Molecule.formuleDevMol", new PropertyModel<String>(moleculeModel, "formuleDevMol")).setEnabled(false) // important otherwise, loose data - .add( - new MoleculeViewBehavior(new PropertyModel<String>(moleculeModel, "formuleDevMol"), - 500, 300))); + .add(new MoleculeViewBehavior(new PropertyModel<String>(moleculeModel, "formuleDevMol"), true))); } formView.add(new TextField<String>("Molecule.nomIupca", new PropertyModel<String>(moleculeModel, "nomIupca")) Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.html =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.html 2013-02-20 06:06:04 UTC (rev 136) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.html 2013-02-20 14:35:29 UTC (rev 137) @@ -42,7 +42,8 @@ <div class="property"> <span class="label"><wicket:message key="Molecule.formuleDevMol" /></span> - <span class="value" wicket:id="Molecule.formuleDevMol"></span> + <div><span class="value" wicket:id="Molecule.formuleDevMol"></span><br /> + <a wicket:id="DownloadMolFile"><wicket:message key="Molecule.downloadMolFile" /></a></div> </div> <div class="property"> Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-20 06:06:04 UTC (rev 136) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-20 14:35:29 UTC (rev 137) @@ -79,6 +79,7 @@ import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.markup.html.link.ResourceLink; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.markup.repeater.Item; @@ -87,6 +88,7 @@ import org.apache.wicket.model.Model; import org.apache.wicket.model.PropertyModel; import org.apache.wicket.request.http.WebResponse; +import org.apache.wicket.request.resource.ByteArrayResource; import org.apache.wicket.spring.injection.annot.SpringBean; /** @@ -134,7 +136,9 @@ .add(new ReplaceEmptyLabelBehavior())); add(new Label("Molecule.formuleDevMol", new PropertyModel<String>(moleculeModel, "formuleDevMol")).add( new ReplaceEmptyLabelBehavior()).add( - new MoleculeViewBehavior(new PropertyModel<String>(moleculeModel, "formuleDevMol"), 500, 300))); + new MoleculeViewBehavior(new PropertyModel<String>(moleculeModel, "formuleDevMol"), true))); + add(new ResourceLink<Molecule>("DownloadMolFile", new ByteArrayResource("chemical/x-mdl-molfile", + moleculeModel.getObject().getFormuleDevMol().getBytes(), "molecule.mol"))); add(new Label("Molecule.nomIupca", new PropertyModel<String>(moleculeModel, "nomIupca")) .add(new ReplaceEmptyLabelBehavior())); add(new Label("Molecule.formuleBrute", new PropertyModel<String>(moleculeModel, "formuleBrute")) @@ -170,8 +174,7 @@ final Form<Void> formView = new Form<Void>("Form"); // Action : mise à jour (redirection vers le formulaire) - Link<Molecule> updateLink = new Link<Molecule>(getResource() + ".Molecule.Update", new Model<Molecule>( - moleculeModel.getObject())) { + Link<Molecule> updateLink = new Link<Molecule>(getResource() + ".Molecule.Update", moleculeModel) { @Override public void onClick() { setResponsePage(new ManageMoleculePage(getModelObject().getIdMolecule(), currentPage)); Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/behaviors/MoleculeViewBehavior.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/behaviors/MoleculeViewBehavior.java 2013-02-20 06:06:04 UTC (rev 136) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/behaviors/MoleculeViewBehavior.java 2013-02-20 14:35:29 UTC (rev 137) @@ -43,32 +43,27 @@ */ public class MoleculeViewBehavior extends AttributeModifier { - /** Canvas width. */ - protected int width; + /** Full view, with cliquable canvas and mol download support. */ + protected boolean fullView; - /** Canvas height. */ - protected int height; - /** * Constructor with default canvas size. * * @param replaceModel replace model */ public MoleculeViewBehavior(IModel<?> replaceModel) { - this(replaceModel, 100, 100); + this(replaceModel, false); } /** * Constructor. * * @param replaceModel replace model - * @param width canvas width - * @param height canvas height + * @param fullView full view, with cliquable canvas and mol download support */ - public MoleculeViewBehavior(IModel<?> replaceModel, int width, int height) { + public MoleculeViewBehavior(IModel<?> replaceModel, boolean fullView) { super("formula", replaceModel); - this.width = width; - this.height = height; + this.fullView = fullView; } /** {@inheritDoc} */ @@ -108,8 +103,11 @@ String id = component.getMarkupId(); response.write(JavaScriptUtils.SCRIPT_OPEN_TAG); - - response.write("addViewerMolecule('" + id + "', " + width + "," + height + ");"); + if (fullView) { + response.write("addFullViewerMolecule('" + id + "');"); + } else { + response.write("addViewerMolecule('" + id + "');"); + } response.write(JavaScriptUtils.SCRIPT_CLOSE_TAG); } Modified: trunk/cantharella.web/src/main/resources/web_en.properties =================================================================== --- trunk/cantharella.web/src/main/resources/web_en.properties 2013-02-20 06:06:04 UTC (rev 136) +++ trunk/cantharella.web/src/main/resources/web_en.properties 2013-02-20 14:35:29 UTC (rev 137) @@ -383,6 +383,7 @@ Molecule.provenanceNotAccessibles=Some related products are not displayed because you don't have the required rights Molecule.masseMolaire.Required=Molar mass - can’t be null Molecule.masseMolaire.IConverter.BigDecimal=Molar mass - must be a decimal number +Molecule.downloadMolFile=Download .mol file TestBio.date.IConverter.Date=The date is incorrectly formatted (DD/MM/YY) TestBio.concMasseDefaut.IConverter.BigDecimal=Default Conc./Mass - must be a decimal number Modified: trunk/cantharella.web/src/main/resources/web_fr.properties =================================================================== --- trunk/cantharella.web/src/main/resources/web_fr.properties 2013-02-20 06:06:04 UTC (rev 136) +++ trunk/cantharella.web/src/main/resources/web_fr.properties 2013-02-20 14:35:29 UTC (rev 137) @@ -381,6 +381,7 @@ Molecule.provenanceNotAccessibles=Certains produits associés ne sont pas affichés car vous n'avez pas les droits nécéssaires Molecule.masseMolaire.Required=Masse molaire - ne peut être nul Molecule.masseMolaire.IConverter.BigDecimal=Masse molaire - doit être un nombre décimal +Molecule.downloadMolFile=Télécharger au format mol TestBio.date.IConverter.Date=La date est mal formatée (JJ/MM/AA) TestBio.concMasseDefaut.IConverter.BigDecimal=Conc./Masse par défaut - doit être un nombre décimal Modified: trunk/cantharella.web/src/main/webapp/js/molviewer.js =================================================================== --- trunk/cantharella.web/src/main/webapp/js/molviewer.js 2013-02-20 06:06:04 UTC (rev 136) +++ trunk/cantharella.web/src/main/webapp/js/molviewer.js 2013-02-20 14:35:29 UTC (rev 137) @@ -1,8 +1,8 @@ /* * #%L * Cantharella :: Web - * $Id:$ - * $HeadURL:$ + * $Id$ + * $HeadURL$ * %% * Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) * %% @@ -20,7 +20,27 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -function addViewerMolecule(tagId, width, height) { +function addChemCanvas(id, formulaString, width, heigth) { + //initialize component and set visual specifications + var viewerCanvas = new ChemDoodle.ViewerCanvas(id, width, heigth); + viewerCanvas.specs.bonds_width_2D = .6; + viewerCanvas.specs.bonds_saturationWidth_2D = .18; + viewerCanvas.specs.bonds_hashSpacing_2D = 2.5; + viewerCanvas.specs.atoms_font_size_2D = 10; + viewerCanvas.specs.atoms_font_families_2D = ["Helvetica", "Arial", "sans-serif"]; + viewerCanvas.specs.atoms_displayTerminalCarbonLabels_2D = true; + + var formula = ChemDoodle.readMOL(formulaString); + + // function to scale molecul to canvas + var size = formula.getDimension(); + var scale = Math.min(viewerCanvas.width/size.x, viewerCanvas.height/size.y); + viewerCanvas.loadMolecule(formula); + viewerCanvas.specs.scale = scale*.8; + viewerCanvas.repaint(); +} + +function addViewerMolecule(tagId) { if (tagId) { tagId = '#' + tagId.replace( /(:|\.)/g, "\\$1" ); } else { @@ -34,23 +54,28 @@ var id = $(formulaTag).attr('id'); $(formulaTag).replaceWith("<canvas id='"+id+"'/>"); - //initialize component and set visual specifications - var viewerCanvas = new ChemDoodle.ViewerCanvas(id, width, height); - viewerCanvas.specs.bonds_width_2D = .6; - viewerCanvas.specs.bonds_saturationWidth_2D = .18; - viewerCanvas.specs.bonds_hashSpacing_2D = 2.5; - viewerCanvas.specs.atoms_font_size_2D = 10; - viewerCanvas.specs.atoms_font_families_2D = ["Helvetica", "Arial", "sans-serif"]; - viewerCanvas.specs.atoms_displayTerminalCarbonLabels_2D = true; + addChemCanvas(id, formulaString, 100, 100); + }); +} - var formula = ChemDoodle.readMOL(formulaString); +function addFullViewerMolecule(tagId) { + if (tagId) { + tagId = '#' + tagId.replace( /(:|\.)/g, "\\$1" ); + } else { + tagId = '[formula]'; + } - // function to scale molecul to canvas - var size = formula.getDimension(); - var scale = Math.min(viewerCanvas.width/size.x, viewerCanvas.height/size.y); - viewerCanvas.loadMolecule(formula); - viewerCanvas.specs.scale = scale*.8; - viewerCanvas.repaint(); + $(tagId).each(function(i, formulaTag) { + // il faut faire un substring de 1 car on a ajoute un caractere pour + // forcer l'existance du tag' + var formulaString = $(formulaTag).attr('formula').substring(1); + var id = $(formulaTag).attr('id'); + $(formulaTag).replaceWith("<a download='molecule'><canvas id='"+id+"'/></a>"); + + addChemCanvas(id, formulaString, 500, 300); + + // add download link + var dataUrl = document.getElementById(id).toDataURL("image/png"); + $('#' + id).parent().attr('href', dataUrl); }); - } Property changes on: trunk/cantharella.web/src/main/webapp/js/molviewer.js ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL
participants (1)
-
echatellier@users.forge.codelutin.com