--- /dev/null
+/*****************************************************************************
+ * Copyright Igor Barma, Eric Brun, Alexandre Desoubeaux, Christian Martel,
+ * (2 décembre 2008)
+ *
+ * Ce logiciel est un programme informatique servant à l'évaluation des
+ * compétences.
+ *
+ * Ce logiciel est régi par la licence CeCILL soumise au droit français et
+ * respectant les principes de diffusion des logiciels libres. Vous pouvez
+ * utiliser, modifier et/ou redistribuer ce programme sous les conditions
+ * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
+ * sur le site "http://www.cecill.info".
+ *
+ * En contrepartie de l'accessibilité au code source et des droits de copie,
+ * de modification et de redistribution accordés par cette licence, il n'est
+ * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
+ * seule une responsabilité restreinte pèse sur l'auteur du programme, le
+ * titulaire des droits patrimoniaux et les concédants successifs.
+ *
+ * A cet égard l'attention de l'utilisateur est attirée sur les risques
+ * associés au chargement, à l'utilisation, à la modification et/ou au
+ * développement et à la reproduction du logiciel par l'utilisateur étant
+ * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
+ * manipuler et qui le réserve donc à des développeurs et des professionnels
+ * avertis possédant des connaissances informatiques approfondies. Les
+ * utilisateurs sont donc invités à charger et tester l'adéquation du
+ * logiciel à leurs besoins dans des conditions permettant d'assurer la
+ * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
+ * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
+ *
+ * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
+ * pris connaissance de la licence CeCILL, et que vous en avez accepté les
+ * termes.
+ *******************************************************************************/
+package com.pentila.evalcomp.client.palette;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.gwtext.client.core.EventCallback;
+import com.gwtext.client.core.EventObject;
+import com.gwtext.client.core.Ext;
+import com.gwtext.client.core.Function;
+import com.gwtext.client.core.Position;
+import com.gwtext.client.core.SortDir;
+import com.gwtext.client.data.ArrayReader;
+import com.gwtext.client.data.BooleanFieldDef;
+import com.gwtext.client.data.FieldDef;
+import com.gwtext.client.data.GroupingStore;
+import com.gwtext.client.data.IntegerFieldDef;
+import com.gwtext.client.data.MemoryProxy;
+import com.gwtext.client.data.ObjectFieldDef;
+import com.gwtext.client.data.Record;
+import com.gwtext.client.data.RecordDef;
+import com.gwtext.client.data.SortState;
+import com.gwtext.client.data.Store;
+import com.gwtext.client.data.StoreTraversalCallback;
+import com.gwtext.client.data.StringFieldDef;
+import com.gwtext.client.util.DelayedTask;
+import com.gwtext.client.util.Format;
+import com.gwtext.client.widgets.Button;
+import com.gwtext.client.widgets.Component;
+import com.gwtext.client.widgets.Panel;
+import com.gwtext.client.widgets.Tool;
+import com.gwtext.client.widgets.ToolTip;
+import com.gwtext.client.widgets.Toolbar;
+import com.gwtext.client.widgets.ToolbarButton;
+import com.gwtext.client.widgets.Window;
+import com.gwtext.client.widgets.event.ButtonListenerAdapter;
+import com.gwtext.client.widgets.event.PanelListenerAdapter;
+import com.gwtext.client.widgets.event.WindowListenerAdapter;
+import com.gwtext.client.widgets.form.FormPanel;
+import com.gwtext.client.widgets.form.TextField;
+import com.gwtext.client.widgets.grid.CellMetadata;
+import com.gwtext.client.widgets.grid.ColumnConfig;
+import com.gwtext.client.widgets.grid.ColumnModel;
+import com.gwtext.client.widgets.grid.GridPanel;
+import com.gwtext.client.widgets.grid.GroupingView;
+import com.gwtext.client.widgets.grid.Renderer;
+import com.gwtext.client.widgets.grid.event.GridListenerAdapter;
+import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
+import com.gwtext.client.widgets.layout.AnchorLayoutData;
+import com.gwtext.client.widgets.layout.FitLayout;
+import com.gwtext.client.widgets.menu.BaseItem;
+import com.gwtext.client.widgets.menu.Item;
+import com.gwtext.client.widgets.menu.Menu;
+import com.gwtext.client.widgets.menu.event.BaseItemListenerAdapter;
+import com.pentila.evalcomp.client.ConnexionServer;
+import com.pentila.evalcomp.client.examen.GridGenerator;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.utilities.GridPanelDropable;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.client.utilities.UserTools;
+import com.pentila.evalcomp.client.widget.ExtWindow;
+import com.pentila.evalcomp.domain.EObject;
+import com.pentila.evalcomp.domain.examen.Examen;
+import com.pentila.evalcomp.domain.plan.Plan;
+import com.pentila.evalcomp.domain.plan.PlanRef;
+import com.pentila.evalcomp.domain.transit.TExamen;
+import com.pentila.evalcomp.domain.transit.TListEObject;
+import com.smartgwt.client.util.BooleanCallback;
+import com.smartgwt.client.util.SC;
+
+
+/**
+ * The Class ScenarioPalettePanel.
+ */
+public class ExamenPalettePanel extends AbstractPalettePanel {
+
+ /** The cfg column model scenario. */
+ private ColumnModel cfgColumnModel;
+
+ /** The cfg columns scenario. */
+ private ColumnConfig[] cfgColumns;
+
+ /** the planFilter. */
+ private Plan planFilter;
+
+ private ToolbarButton addButton;
+
+
+ /** The render scenario. */
+ private Renderer render = new Renderer() {
+ public String render(Object value, CellMetadata cellMetadata,
+ Record record, int rowIndex, int colNum, Store store) {
+
+ String scName = record.getAsString("name");
+
+ if (scName == null){
+ scName = "Examen sans nom";
+ }
+
+ if (scName.length() > 20) {
+ cellMetadata.setHtmlAttribute("ext:qtip=\"" + scName + "\"");
+ }
+
+ String iconName = "examen16.png";
+
+ /*if (record.getAsString("type").equals(
+ ScenarioDefinitionValidation.VALIDATION)) {
+ iconName = "scenarioValidation16.png";
+ }
+ if (record.getAsString("type").equals(
+ ScenarioDefCert.CERTIFICATION)) {
+ iconName = "scenarioCertification16.png";
+ }*/
+
+ if (record.getAsBoolean("markRecord")) {
+ return Format
+ .format(
+ "<img src=\"" + Tools.getBaseURL()
+ + "images/{1}\"><span style=\"color:green;\"> {0}</span>", new String[] { scName, iconName });
+ } else {
+ return Format
+ .format(
+ "<img src=\"" + Tools.getBaseURL()
+ + "images/{1}\"> {0}", new String[] { scName, iconName });
+ }
+
+ }
+ };
+
+
+ /** The scenario grid. */
+ public GridPanelDropable grid;
+
+ /** The scenario palette initialized. */
+ private boolean paletteInitialized = false;
+
+ /** The store scenario. */
+ private GroupingStore store;
+
+
+ /** The obj list. */
+ Object[][] objList;
+
+ /** The data proxy. */
+ MemoryProxy dataProxy;
+
+ /** The record def. */
+ RecordDef recordDef = new RecordDef(new FieldDef[] {
+ new StringFieldDef("ident"),
+ new StringFieldDef("name"),
+ new ObjectFieldDef("object"),
+ new StringFieldDef("category"),
+ new BooleanFieldDef("markRecord") });
+
+ private Menu menuGrid;
+
+ private Menu menuRow;
+
+
+ /**
+ * Instantiates a new scenario palette panel.
+ */
+ public ExamenPalettePanel() {
+ super();
+
+ this.setTitle(Messages.getString("Examens"));
+
+ this.setIconCls("iconExamen16");
+
+ ColumnConfig cc = new ColumnConfig("category", "category", 1, false);
+
+ cfgColumns = new ColumnConfig[] {
+ new ColumnConfig(Messages.getString("Nom"),
+ "name", 195, true, render,
+ "name"), cc
+
+ };
+ cfgColumnModel = new ColumnModel(cfgColumns);
+
+ this.addTool(new Tool(Tool.REFRESH, new Function() {
+ public void execute() {
+ updateGrid(null);
+ }
+ }, Messages.getString("Rafraichir")));
+
+
+ this.addListener(new PanelListenerAdapter() {
+ @Override
+ public boolean doBeforeExpand(Panel panel, boolean animate) {
+ if (paletteInitialized == false) {
+ paletteInitialized = true;
+ updateGrid(null);
+ }
+ return true;
+ }
+ });
+ }
+
+ /**
+ * Initialize palette.
+ */
+ public void initializePalette() {
+
+ setBorder(false);
+ setLayout(new FitLayout());
+
+ objList = new Object[][] {};
+ dataProxy = new MemoryProxy(objList);
+
+ ArrayReader reader = new ArrayReader(recordDef);
+
+ store = new GroupingStore(dataProxy, reader);
+ store.setSortInfo(new SortState("name",
+ SortDir.ASC));
+ store.setGroupField("category");
+
+ store.load();
+
+ grid = new GridPanelDropable(){
+ public boolean isTrashable(Object ...objects){
+
+ Record[] records = grid.getSelectionModel().getSelections();
+
+ for (Record record : records){
+
+ TExamen texamen = (TExamen) record.getAsObject("object");
+
+ Examen examen = texamen.getExamen();
+
+ if (examen.getOwner() == null || !examen.getOwner().getId().equals(UserTools.getUser().getId())){
+
+ return false;
+
+ }
+
+ }
+
+ return true;
+
+ }
+
+ public void trashedElements(Object ...objects){
+ final Record[] records = grid.getSelectionModel().getSelections();
+
+
+ if (records != null && records.length > 0){
+
+
+ SC.confirm(Messages.getString("confirm_suppression"), new BooleanCallback() {
+ public void execute(Boolean value) {
+ if (value != null && value) {
+ Set<Long> eIds = new HashSet<Long>();
+
+ for (Record record : records){
+ TExamen texamen = (TExamen) record.getAsObject("object");
+ Examen examen = texamen.getExamen();
+
+ eIds.add(examen.getId());
+
+ }
+
+ Function callback = new Function(){
+
+ public void execute() {
+ for (Record record : records){
+ grid.getStore().remove(record);
+
+ if (itManager != null){
+ Examen examen = null;
+ if (grid.getStore().getCount() !=0){
+
+ TExamen te = (TExamen)grid.getStore().getRecordAt(0).getAsObject("object");
+
+ examen = te.getExamen();
+
+ }
+
+ itManager.showExamen(examen);
+ }
+ }
+ }
+
+ };
+
+ deleteExamen(eIds, callback);
+ }
+ }
+ });
+
+
+ }
+
+ }};
+ grid.setBorder(false);
+ grid.setStore(store);
+ grid.setColumnModel(cfgColumnModel);
+
+ GroupingView gridView = new GroupingView();
+ gridView.setForceFit(true);
+
+ //gridView.setGroupTextTpl("{text}");
+ gridView.setGroupTextTpl("{[values.rs[0].data[\"category\"]]}");
+ gridView.setHideGroupedColumn(true);
+ grid.setView(gridView);
+ grid.setFrame(false);
+
+ grid.setId(Ext.generateId("examenGridPalette"));
+ grid.setEnableDragDrop(true);
+
+ grid.setDdGroup("evalCompDDGroup");
+ grid.setEnableColumnHide(false);
+ grid.setEnableColumnMove(false);
+ grid.setEnableColumnResize(false);
+ grid.setEnableHdMenu(false);
+ grid.addGridRowListener(new GridRowListenerAdapter() {
+
+ @Override
+ public void onRowContextMenu(GridPanel grid, int rowIndex,
+ EventObject e) {
+ e.stopEvent();
+ showRowEvalContextMenu(rowIndex, e);
+ }
+
+ @Override
+ public void onRowDblClick(GridPanel grid, int rowIndex,
+ EventObject e) {
+ TExamen texamen = (TExamen) grid
+ .getStore().getRecordAt(rowIndex).getAsObject(
+ "object");
+ Examen examen = texamen.getExamen();
+
+ ClickOn(examen);
+
+ }
+
+ });
+
+ grid.addGridListener(new GridListenerAdapter() {
+ @Override
+ public void onContextMenu(EventObject e) {
+ e.stopEvent();
+ showGridEvalContextMenu(e);
+ }
+ });
+
+ Toolbar toolbar = new Toolbar();
+
+ addButton = new ToolbarButton();
+ addButton.setIcon( Tools.getBaseURL() + "images/examen16-add.png" );
+ addButton.setTooltip( Messages.getString("Ajouter_un_examen") );
+ addButton.addListener(new ButtonListenerAdapter() {
+ @Override
+ public void onClick(Button button, EventObject e) {
+ createExamen();
+ }
+ });
+
+ toolbar.addButton(addButton);
+
+
+ grid.setEnableColumnResize(true);
+
+
+ final TextField searchTF = new TextField();
+
+ final DelayedTask dt = new DelayedTask();
+ final Function doit = new Function(){
+ public void execute() {
+
+ grid.getStore().filter("name",
+ searchTF.getValueAsString());
+ }
+
+ };
+
+ ToolTip tp = new ToolTip();
+ tp.setHtml(Messages.getString("Rechercher_dans_la_liste"));
+ tp.applyTo(searchTF);
+
+ searchTF.addKeyPressListener(new EventCallback() {
+
+ public void execute(EventObject e) {
+
+ dt.cancel();
+ dt.delay(100, doit);
+ }
+ });
+
+ toolbar.addField(searchTF);
+
+ grid.setTopToolbar(toolbar);
+
+
+ grid.setDragDropText(Messages
+ .getString("x_examenx_selectionnex"));
+
+
+
+ add(grid);
+ }
+
+ protected void createExamen() {
+<<<<<<< .working
+ final ExtWindow window = new ExtWindow();
+ window.setTitle(Messages.getString("Ajouter_un_examen"));
+ window.setClosable(true);
+ window.setWidth(500);
+ window.setHeight(250);
+ window.setPlain(true);
+ window.setLayout(new FitLayout());
+ window.setPaddings(5);
+ window.setButtonAlign(Position.CENTER);
+ window.setCloseAction(Window.HIDE);
+
+ final TextField examenTitle = new TextField(Messages.getString("Title"), "title");
+ examenTitle.setAllowBlank(false);
+
+ window.addListener(new WindowListenerAdapter() {
+ @Override
+ public void onActivate(Window source) {
+ examenTitle.focus();
+ }
+ });
+
+ Button addButton = new Button(Messages.getString("Ajouter"));
+ Button cancelButton = new Button(Messages.getString("Annuler"));
+ window.addButton(addButton);
+ window.addButton(cancelButton);
+ addButton.addListener(new ButtonListenerAdapter() {
+ @Override
+ public void onClick(Button button, EventObject e) {
+ if (examenTitle.isValid() ){
+ Examen newe = new Examen();
+
+ newe.setNom_examen(examenTitle.getValueAsString());
+ newe.setAuteur(UserTools.getUser().getLastname() + " " + UserTools.getUser().getFirstname());
+ newe.setAuteur_mail(UserTools.getUser().getEmail());
+ newe.setOwner(UserTools.getUser());
+ newe.setCorrection(false);
+ newe.setAffiche_chrono(true);
+ newe.setOrdre_q("fixe");
+ newe.setOrdre_r("fixe");
+ newe.setShared(false);
+
+ newe.setTs_datecreation(new Date());
+
+ window.close();
+ saveExamen(newe);
+
+
+ }else{
+
+
+ examenTitle.validate();
+
+ }
+
+ }
+
+ });
+ cancelButton.addListener(new ButtonListenerAdapter() {
+ @Override
+ public void onClick(Button button, EventObject e) {
+ window.hide();
+ }
+ });
+
+ final FormPanel form = new FormPanel();
+ form.setFrame(true);
+ form.setWidth(580);
+ form.setHeight(340);
+
+
+ form.add(examenTitle, new AnchorLayoutData("50%"));
+
+ window.add(form);
+ window.show();
+=======
+
+ itManager.showExamen(null);
+
+
+
+
+>>>>>>> .merge-right.r18984
+
+ }
+
+ /**
+ * Sets the plan filter.
+ *
+ * @param plan
+ * the new plan filter
+ */
+ public void setPlanFilter(Plan plan) {
+ this.planFilter = plan;
+ if (paletteInitialized) {
+ updatePlanFilter();
+ }
+ }
+
+ /**
+ * Update plan filter.
+ */
+ public void updatePlanFilter() {
+ StoreTraversalCallback cbShow = new StoreTraversalCallback() {
+
+ public boolean execute(Record record) {
+ if (planFilter == null || !planFilter.getPlanRefLock()) {
+ return true;
+ } else {
+ TExamen texamen = (TExamen)record.getAsObject("object");
+
+ for (PlanRef pr : planFilter.getPlanRefs()){
+
+ if (texamen.getRelatedRefIds().contains(pr.getReferentiel().getId())){
+
+ return true;
+ }
+
+ }
+ }
+ return false;
+ }
+ };
+
+ StoreTraversalCallback cbMark = new StoreTraversalCallback() {
+
+ public boolean execute(Record record) {
+
+ if (planFilter == null || planFilter.getPlanRefLock()) {
+
+ record.beginEdit();
+ record.set("markRecord", false);
+ record.endEdit();
+ return true;
+ } else {
+
+
+ TExamen texamen = (TExamen)record.getAsObject("object");
+
+ for (PlanRef pr : planFilter.getPlanRefs()){
+
+ if (texamen.getRelatedRefIds().contains(pr.getReferentiel().getId())){
+ record.beginEdit();
+ record.set("markRecord", true);
+ record.endEdit();
+ return true;
+ }
+
+ }
+
+
+ }
+ return true;
+ }
+ };
+ // on met update le grid
+
+ store.filterBy(cbShow);
+ store.each(cbMark);
+
+ }
+
+ /**
+ * Update scenario grid.
+ *
+ * @param scenarioId
+ * the scenario id
+ */
+ public void updateGrid(final Long scenarioId) {
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable caught) {
+ // do some UI stuff to show failure
+ System.out
+ .println("Probleme dans la recup de la liste des examens");
+ Tools.hideLoadingRegion(getId());
+ }
+
+ public void onSuccess(Object result) {
+
+ TListEObject T = (TListEObject) result;
+
+ int totalCount = T.getTotal();
+
+ objList = new Object[totalCount][];
+
+ int i = 0;
+
+ for (EObject eo : T.getListOfEObjects()) {
+
+ TExamen texamen = (TExamen)eo;
+
+ Examen examen = texamen.getExamen();
+
+ String name = examen.getNom_examen();
+
+ String cat = Messages.getString("mes_examens");
+
+ if (examen.getOwner() == null || !examen.getOwner().getId().equals(UserTools.getUser().getId())){
+
+ cat = Messages.getString("examens_partages");
+
+ }
+
+ Object[] monObjet = new Object[] { examen.getId().toString(), name, texamen, cat.toUpperCase(), false };
+ objList[i] = monObjet;
+ i++;
+
+ }
+
+ dataProxy = new MemoryProxy(objList);
+
+ store.setDataProxy(dataProxy);
+
+ store.reload();
+
+
+ paletteInitialized = true;
+ updatePlanFilter();
+
+ Tools.hideLoadingRegion(getId());
+ }
+ };
+
+ Tools
+ .showLoadingRegion(
+ getId(),
+ Messages.getString("MAJ"), Messages.getString("Chargement"));
+ RequestBuilder rb = ConnexionServer.examenService.getOwnAndSharedTExamens(UserTools.getUser().getId(), 0, 10000, callback);
+ rb.setHeader("code", "A271");
+ ConnexionServer.doSend(rb);
+ }
+
+ public void ClickOn(Examen examen) {
+
+ itManager.showExamen(examen);
+ }
+
+ public void saveExamen(Examen newe) {
+
+
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable arg0) {
+
+ }
+
+ public void onSuccess(Object result) {
+
+ Examen exam = (Examen) result;
+ String name = exam.getNom_examen();
+
+ String cat = Messages.getString("mes_examens");
+
+ if (exam.getOwner() == null || !exam.getOwner().getId().equals(UserTools.getUser().getId())){
+
+ cat = Messages.getString("examens_partages");
+
+ }
+
+ TExamen texamen = new TExamen(exam);
+
+
+ Record r = recordDef.createRecord(new Object[]{exam.getId().toString(), name, texamen, cat.toUpperCase(), false });
+
+ grid.getStore().addSorted(r);
+
+ ClickOn(exam);
+ }
+
+ };
+
+ ConnexionServer.examenService.saveExamen(newe, callback);
+ }
+
+ protected void deleteExamen(Set<Long> qIds, final Function callbackFunction) {
+ AsyncCallback callback = new AsyncCallback(){
+
+ public void onFailure(Throwable arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onSuccess(Object arg0) {
+
+ if (callbackFunction != null){
+ callbackFunction.execute();
+ }
+ }
+
+ };
+
+
+ ConnexionServer.examenService.deleteExamens(qIds, callback);
+
+ }
+
+ private void showGridEvalContextMenu(EventObject e) {
+
+ menuGrid = new Menu();
+ Item addItem = new Item(Messages
+ .getString("Ajouter_un_examen"),
+ new BaseItemListenerAdapter() {
+ @Override
+ public void onClick(BaseItem item, EventObject e) {
+ createExamen();
+ }
+ });
+ addItem.setIconCls("menu-add-examen");
+ menuGrid.addItem(addItem);
+
+ menuGrid.showAt(e.getXY());
+ }
+
+ /**
+ * Show row eval context menu.
+ *
+ * @param rowIndex
+ * the row index
+ * @param e
+ * the e
+ */
+ private void showRowEvalContextMenu(int rowIndex, EventObject e) {
+
+ menuRow = new Menu();
+ Item addItem = new Item(Messages
+ .getString("Ajouter_un_examen"),
+ new BaseItemListenerAdapter() {
+ @Override
+ public void onClick(BaseItem item, EventObject e) {
+ createExamen();
+ }
+ });
+ addItem.setIconCls("menu-add-examen");
+ menuRow.addItem(addItem);
+
+
+ final Record[] selection = grid.getSelectionModel().getSelections();
+
+ if (selection != null && selection.length == 1){
+
+ TExamen texamen = (TExamen)selection[0].getAsObject("object");
+
+ Examen examen = texamen.getExamen();
+
+ Item copyItem = new Item(Messages
+ .getString("Copier_cet_examen"),
+ new BaseItemListenerAdapter() {
+ @Override
+ public void onClick(BaseItem item, EventObject e) {
+ copyExamen();
+ }
+ });
+ copyItem.setIconCls("menu-copy-examen");
+ menuRow.addItem(copyItem);
+
+
+ }
+
+
+
+
+ if (selection != null && selection.length > 0){
+
+
+ final Set<Long> eIds = new HashSet<Long>();
+ for (Record record : selection){
+ TExamen texamen = (TExamen)record.getAsObject("object");
+ Examen examen = texamen.getExamen();
+ if (!(examen.getOwner() == null || examen.getOwner().getId().equals(UserTools.getUser().getId()) || examen.getShared())){
+ eIds.clear();
+ break;
+ }else{
+ eIds.add(examen.getId());
+ }
+ }
+ if (eIds != null && !eIds.isEmpty()){
+ Item deleteItem = new Item(Messages.getString("Supprimer_examen"), new BaseItemListenerAdapter() {
+
+ public void onClick(BaseItem item, EventObject e) {
+
+ Function callback = new Function(){
+
+ public void execute() {
+ for (Record record : selection){
+ grid.getStore().remove(record);
+ if (itManager != null){
+ Examen examen = null;
+ if (grid.getStore().getCount() !=0){
+
+ TExamen te = (TExamen)grid.getStore().getRecordAt(0).getAsObject("object");
+
+ examen = te.getExamen();
+
+ }
+
+ itManager.showExamen(examen);
+ }
+ }
+ }
+
+ };
+
+ deleteExamen(eIds, callback);
+ }
+ });
+ deleteItem.setIconCls("menu-delete");
+ menuRow.addItem(deleteItem);
+ }
+
+ }
+
+
+ menuRow.showAt(e.getXY());
+ }
+
+ protected void copyExamen() {
+ Record row = grid.getSelectionModel().getSelected();
+
+ TExamen texamen = (TExamen)row.getAsObject("object");
+ Examen examen = texamen.getExamen();
+
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable caught) {
+ System.out.println("Probleme copy examen");
+ Tools.hideLoadingRegion(getId());
+ }
+
+ public void onSuccess(Object result) {
+
+ TExamen te = (TExamen)result;
+
+ String cat = Messages.getString("mes_examens");
+
+ Record r = recordDef.createRecord(new Object[]{te.getExamen().getId().toString(), te.getExamen().getNom_examen(), te, cat.toUpperCase(), false });
+
+ grid.getStore().addSorted(r);
+
+ ClickOn(te.getExamen());
+
+
+ Tools.hideLoadingRegion(getId());
+
+ }
+ };
+ Tools.showLoadingRegion(getId(), Messages.getString("MAJ"), Messages
+ .getString("Chargement"));
+ ConnexionServer.examenService.copyExamen(examen.getId(),
+ callback);
+
+ }
+
+ public void saveOrUpdateExam(Examen examen) {
+
+ if (examen == null || examen.getId() == null){
+ return;
+ }
+
+ int index = grid.getStore().find("ident", examen.getId().toString(), 0, true, true);
+
+ if (index != -1){
+ // update examen record
+ Record r = grid.getStore().getRecordAt(index);
+ r.set("name", examen.getTitle());
+ //r.set("object", examen);
+ r.set("category", examen.getShared());
+ r.commit();
+ }else{
+ // save new Examen
+ String cat = Messages.getString("mes_examens");
+
+ TExamen te = new TExamen();
+ te.setExamen(examen);
+ te.setRelatedRefIds(new HashSet<Long>());
+
+ Record r = recordDef.createRecord(new Object[]{examen.getId().toString(),examen.getNom_examen(), te, cat.toUpperCase(), false });
+ grid.getStore().addSorted(r);
+ }
+
+ }
+
+
+}
\ No newline at end of file