Commit bf08912d authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '70-status-ok' into 'master'

Resolve "Change the logic for status OK"

Closes #70

See merge request !88
parents 16208cc7 68f0c65b
......@@ -3,7 +3,9 @@
"""
import json
from plugin_dbui import CALLBACK_ERRORS
from plugin_dbui import CALLBACK_ERRORS, UNDEF_ID
SQL_UNLOCK = "UPDATE publications SET id_status=%i WHERE id=%s"
def read():
......@@ -17,6 +19,15 @@ def read():
return json.dumps(dict(success=True, data=row.as_dict()))
def unlock_status():
"""Unlock the status OK bypassing the protection.
The publication identified by its id.
"""
# build a raw query to bypass protection (callback)
db.executesql(SQL_UNLOCK % (UNDEF_ID, request.vars.id))
def update():
"""Update a publication record identified by its id.
Design to update record from a basic Ext.form.Panel.
......
docs/user/images/menu-contextuel.png

8.05 KB | W: | H:

docs/user/images/menu-contextuel.png

13.4 KB | W: | H:

docs/user/images/menu-contextuel.png
docs/user/images/menu-contextuel.png
docs/user/images/menu-contextuel.png
docs/user/images/menu-contextuel.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -34,8 +34,11 @@ Il est organisé en six onglets qui regroupent les champs par spécificité :
la base de données, ...
.. attention::
Quand le status d'une publication est ``OK``,
elle ne peut plus être modifiée ou détruite.
Quand le status est ``OK`` la publication est
verrouillée. Elle ne peut plus être modifiée ou détruite.
Cependant is est possible de la déverroullier en cliquant
sur ``Déverrouiller le status`` dans le menu contextuel.
Une confirmation sera alors demandée à l'utilisateur.
Les champs obligatoires
^^^^^^^^^^^^^^^^^^^^^^^
......
......@@ -330,6 +330,7 @@ class CoreUI(object):
mdf.configure(plugins=["pGridPaging",
"pMathJax",
"pGridRowEditorUnlockStatusOk",
{"ptype": "pGridRowEditorConfirmDelete",
"resetFields": ["PublicationsId_status",
"PublicationsOrigin"]}])
......
......@@ -9,24 +9,25 @@ if (Dbui.debug) {
disableCaching: false,
enabled: true,
paths: {
'Dbui': '/' + Dbui.name + '/static/plugin_dbui/src',
'Ext': '/' + Dbui.name + '/static/plugin_extjs/src',
'Limbra': '/' + Dbui.name + '/static/limbra/src'
"Dbui": "/" + Dbui.name + "/static/plugin_dbui/src",
"Ext": "/" + Dbui.name + "/static/plugin_extjs/src",
"Limbra": "/" + Dbui.name + "/static/limbra/src"
}
});
}
Ext.require('Dbui.container.Viewport');
Ext.require('Dbui.grid.plugin.RowEditorAddWizard');
Ext.require('Dbui.plugin.MathJax');
Ext.require("Dbui.container.Viewport");
Ext.require("Dbui.grid.plugin.RowEditorAddWizard");
Ext.require("Dbui.plugin.MathJax");
Ext.require('Ext.direct.Manager');
Ext.require('Ext.direct.RemotingProvider');
Ext.require('Ext.EventManager');
Ext.require('Ext.tip.QuickTipManager');
Ext.require("Ext.direct.Manager");
Ext.require("Ext.direct.RemotingProvider");
Ext.require("Ext.EventManager");
Ext.require("Ext.tip.QuickTipManager");
Ext.require('Limbra.grid.plugin.AffiliationKeysContextMenu');
Ext.require('Limbra.wizard.Harvester');
Ext.require("Limbra.grid.plugin.AffiliationKeysContextMenu");
Ext.require("Limbra.grid.plugin.RowEditorUnlockStatusOk");
Ext.require("Limbra.wizard.Harvester");
Ext.onReady(function(){
......@@ -50,8 +51,8 @@ Ext.onReady(function(){
// NOTE: It should work when the browser is closed to.
// Not working with FireFox 17.0.8, web2py 2.4.5 and Ext JS 3.4.0.
// nor with Firefox 38, web2py 2.14.6, Ext JS 6.0.1
Ext.getWin().on('beforeunload', Dbui.closeUserSession);
Ext.getWin().on("beforeunload", Dbui.closeUserSession);
// Instantiate the application
app = Ext.create('Dbui.container.Viewport', Dbui.config.viewport);
app = Ext.create("Dbui.container.Viewport", Dbui.config.viewport);
});
\ No newline at end of file
......@@ -12,6 +12,34 @@ Ext.define('Limbra.local.fr.grid.plugin.AffiliationKeysContextMenu', {
});
Ext.define("Limbra.local.fr.grid.plugin.RowEditorUnlockStatusOk", {
override: 'Limbra.grid.plugin.RowEditorUnlockStatusOk',
textConfirmation: "Confirmation demandée",
textError: "Erreur",
textErrorServer: "Erreur coté serveur dans la procédure de " +
"changement de status.",
textFail: "La valeur demandée est fausse.<br>" +
"Essayer à nouveau.",
textInformation: "Information",
textMsgConfirmation: "La publication est verrouillée.<br>" +
"Elle est donc protégée contre les modifications " +
"ou la destruction.<br><br>" +
"Entrez <font color='red'>XYZ</font> " +
"pour déverrouiller la publication.<br>" +
"Il sera alors possible de la modifier, de la détruire " +
"ou de la verrouiller à nouveau.",
textMsgInformation: "La publication n'est pas verrouillée.<br> " +
"Il est donc possible de la modifier ou de la " +
"détruire à tous moments.",
textSucess: "La publication est déverrouillée.",
textUnlock: "Déverrouiller le status",
});
Ext.define('Limbra.local.fr.wizard.AffiliationFromInstituteDb', {
override: 'Limbra.wizard.AffiliationFromInstituteDb',
......
/**
* Add the entry 'Unlock status' in the RowEditor context menu.
*
* The new entry allows to unlock publication marked OK by resetting
* the status to undefined. A confirmation by the user is required.
*
* @since 0.9.6.5
*
*/
Ext.define("Limbra.grid.plugin.RowEditorUnlockStatusOk", {
extend: "Ext.AbstractPlugin",
alias: "plugin.pGridRowEditorUnlockStatusOk",
/**
* @cfg {Number}
* Identifier of the status OK defined in the database.
*
*/
idStatusOk: 3,
/**
* @cfg {String}
* URL to the controller which will change the status.
* The joker APP will be replace by the name of the application
* The parameter id is the publications identifier in the database.
*
*/
controller: "/APP/publications/unlock_status?id=",
// shotcuts
rowEditor: null,
// private properties for internationalization
textConfirmation: "Confirmation required",
textError: "Error",
textErrorServer: "Error on the server changing the status.",
textFail: "Confirmation value is wrong.<br>" +
"Try again.",
textInformation: "Information",
textMsgConfirmation: "The publication is locked.<br>" +
"It is, therefore, protected against modification " +
"or removal.<br><br>" +
"Please type <font color='red'>XYZ</font> " +
"to unlock the publication.<br>" +
"Latter on, you can modify it, delete it " +
"or lock it again.",
textMsgInformation: "The publication is not locked.<br> " +
"Therefore, you can modify or delete it at any time.",
textSucess: "The publication is unlocked.",
textUnlock: "Unlock status",
/**
* Initialize the plugin.
*
* @param {Dbui.grid.Panel} grid
*/
init: function (grid) {
"use strict";
var me = this,
rowEditor = grid.getPlugin("rowEditor"),
contextMenu, newItems;
me.setCmp(grid);
// protection
if (!rowEditor) {
throw new Error("no grid plugin RowEditor !!!");
}
contextMenu = grid.findPlugin("pGridRowEditorContextMenu");
if (!contextMenu) {
throw new Error("no grid plugin RowEditorContextMenu !!!");
}
// the new item
newItems = ["-", {
text: me.textUnlock,
handler: me.onUnlock,
scope: me
}];
contextMenu.menu.insert(-1, newItems);
me.rowEditor = rowEditor;
},
/**
* Handler to unlock the publication.
* A confirmation is required to unlock the publication.
*
*/
onUnlock: function () {
"use strict";
var me = this,
record = me.rowEditor.getSelected(),
ask, iAuth, idStatus, msg, myAuthors;
if (!record) {
return;
}
idStatus = record.get("PublicationsId_status");
// inform the user that there is nothing to do
if (idStatus !== me.idStatusOk) {
Ext.Msg.alert(me.textInformation, me.textMsgInformation);
return;
}
// build the confirmation key. It is the family name of my authors
// selected randoly
myAuthors = record.get("PublicationsAuthors_institute").split(",");
iAuth = Math.floor(Math.random() * (myAuthors.length - 1));
ask = myAuthors[iAuth].split(" ");
ask = ask[ask.length - 1];
msg = me.textMsgConfirmation.replace("XYZ", ask);
// confirmation process
// modify the status when the entered value is equal to ask
// the process is complex since the protection on the status
// have to be bypassed. They are implemented at the database level
// using callback.
Ext.Msg.prompt(me.textConfirmation, msg, function(buttonId, value) {
if (buttonId !== "ok") {
return;
}
if (value !== ask) {
Ext.Msg.alert(me.textError, me.textFail);
return;
}
Ext.Ajax.request({
// go back to server to bypass protection on the status
url: me.controller.replace("APP", Dbui.name) +
record.get("PublicationsId"),
// something went wrong on the server side, inform the user
failure: function() {
Ext.Msg.alert(me.textError, me.textErrorServer);
},
// refresh the store when the transaction is successful
success: function() {
me.getCmp().getStore().reload();
}
});
});
}
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment