Author: echatellier Date: 2013-02-06 17:17:15 +0100 (Wed, 06 Feb 2013) New Revision: 83 Url: http://forge.codelutin.com/projects/cantharella/repository/revisions/83 Log: Correction des droits pour editer les provenances d'une mol?\195?\169cule, mais pas la mol?\195?\169cule elle m?\195?\170me Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html 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.java Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java 2013-02-06 14:19:19 UTC (rev 82) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java 2013-02-06 16:17:15 UTC (rev 83) @@ -142,12 +142,7 @@ // pas de lien d'édition si l'utilisateur n'a pas les droits @Override public void populateItem(Item<ICellPopulator<Molecule>> item, String componentId, IModel<Molecule> model) { - if (moleculeService.updateOrdeleteMoleculeEnabled(model.getObject(), getSession().getUtilisateur())) { - item.add(new LinkableImagePanel(item, componentId, model)); - } else { - // label vide - item.add(new Label(componentId)); - } + item.add(new LinkableImagePanel(item, componentId, model)); } @Override Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html 2013-02-06 14:19:19 UTC (rev 82) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html 2013-02-06 16:17:15 UTC (rev 83) @@ -39,8 +39,8 @@ </div> <div class="property"> - <label for="Molecule.formuleDevMol"><wicket:message key="Molecule.formuleDevMol" /></label> - <input type="hidden" id="Molecule.formuleDevMol" wicket:id="Molecule.formuleDevMol" /> + <label><wicket:message key="Molecule.formuleDevMol" /></label> + <input type="hidden" wicket:id="Molecule.formuleDevMol" /> </div> <div class="property"> 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-06 14:19:19 UTC (rev 82) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java 2013-02-06 16:17:15 UTC (rev 83) @@ -48,6 +48,7 @@ import nc.ird.cantharella.web.utils.CallerPage; import nc.ird.cantharella.web.utils.behaviors.JSConfirmationBehavior; import nc.ird.cantharella.web.utils.behaviors.MoleculeEditorBehavior; +import nc.ird.cantharella.web.utils.behaviors.MoleculeViewBehavior; import nc.ird.cantharella.web.utils.behaviors.ReplaceEmptyLabelBehavior; import nc.ird.cantharella.web.utils.forms.AutoCompleteTextFieldString; import nc.ird.cantharella.web.utils.forms.SubmittableButton; @@ -182,16 +183,31 @@ final Form<Void> formView = new Form<Void>("Form"); initProvenanceFields(formView, currentPage); + + // page can be accessed by anyone for editing provenance + // but molecule fields can be edited only by administrators or + // molecule creator + Utilisateur utilisateur = getSession().getUtilisateur(); + boolean editEnabled = createMode || moleculeService.updateOrdeleteMoleculeEnabled(moleculeModel.getObject(), utilisateur); + + formView.add(new TextField<String>("Molecule.nomCommun", new PropertyModel<String>(moleculeModel, "nomCommun")).setEnabled(editEnabled)); + formView.add(new TextField<String>("Molecule.familleChimique", new PropertyModel<String>(moleculeModel, "familleChimique")).setEnabled(editEnabled)); + + if (editEnabled) { + formView.add(new HiddenField<String>("Molecule.formuleDevMol", new PropertyModel<String>(moleculeModel, "formuleDevMol")) + .add(new MoleculeEditorBehavior(new PropertyModel<String>(moleculeModel, "formuleDevMol")))); + } else { + 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))); + } + + formView.add(new TextField<String>("Molecule.nomIupca", new PropertyModel<String>(moleculeModel, "nomIupca")).setEnabled(editEnabled)); + formView.add(new TextField<String>("Molecule.formuleBrute", new PropertyModel<String>(moleculeModel, "formuleBrute")).setEnabled(editEnabled)); - formView.add(new TextField<String>("Molecule.nomCommun", new PropertyModel<String>(moleculeModel, "nomCommun"))); - formView.add(new TextField<String>("Molecule.familleChimique", new PropertyModel<String>(moleculeModel, "familleChimique"))); - formView.add(new HiddenField<String>("Molecule.formuleDevMol", new PropertyModel<String>(moleculeModel, "formuleDevMol")) - .add(new MoleculeEditorBehavior(new PropertyModel<String>(moleculeModel, "formuleDevMol")))); //moleculeModel.getObject().getFormuleDevMol()))); - formView.add(new TextField<String>("Molecule.nomIupca", new PropertyModel<String>(moleculeModel, "nomIupca"))); - formView.add(new TextField<String>("Molecule.formuleBrute", new PropertyModel<String>(moleculeModel, "formuleBrute"))); - TextField<String> masseMolaireField = new TextField<String>("Molecule.masseMolaire", new PropertyModel<String>(moleculeModel, "masseMolaire")); masseMolaireField.setRequired(true); + masseMolaireField.setEnabled(editEnabled); formView.add(masseMolaireField); @@ -211,15 +227,16 @@ protected boolean wantOnSelectionChangedNotifications() { return true; } - }); + }.setEnabled(editEnabled)); AutoCompleteTextFieldString identifieeParInput = new AutoCompleteTextFieldString("Molecule.identifieePar", new PropertyModel<String>(moleculeModel, "identifieePar"), organismes, ComparisonMode.CONTAINS); + identifieeParInput.setEnabled(editEnabled); nouvMoleculRefresh.add(identifieeParInput); DropDownChoice<Campagne> campagnesInput = new DropDownChoice<Campagne>("Molecule.campagne", new PropertyModel<Campagne>(moleculeModel, "campagne"), campagnes); - //campagnesInput.setNullValid(false); + campagnesInput.setEnabled(editEnabled); nouvMoleculRefresh.add(campagnesInput); // Action : création d'une nouvelle campagne @@ -235,11 +252,13 @@ protected void onError(AjaxRequestTarget target, Form<?> form) { setResponsePage(new ManageCampagnePage(currentPage, false)); } - }); + }.setVisibilityAllowed(editEnabled)); - nouvMoleculRefresh.add(new TextArea<String>("Molecule.publiOrigine", new PropertyModel<String>(moleculeModel, "publiOrigine"))); + nouvMoleculRefresh.add(new TextArea<String>("Molecule.publiOrigine", new PropertyModel<String>(moleculeModel, "publiOrigine")) + .setEnabled(editEnabled)); - formView.add(new TextArea<String>("Molecule.complement", new PropertyModel<String>(moleculeModel, "complement"))); + formView.add(new TextArea<String>("Molecule.complement", new PropertyModel<String>(moleculeModel, "complement")) + .setEnabled(editEnabled)); // Créateur en lecture seule formView.add(new TextField<String>("Molecule.createur", new PropertyModel<String>(moleculeModel, "createur")) 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-06 14:19:19 UTC (rev 82) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-06 16:17:15 UTC (rev 83) @@ -142,8 +142,6 @@ setResponsePage(new ManageMoleculePage(getModelObject().getIdMolecule(), currentPage)); } }; - updateLink.setVisibilityAllowed(moleculeService.updateOrdeleteMoleculeEnabled(moleculeModel.getObject(), getSession() - .getUtilisateur())); formView.add(updateLink); // Action : suppression