Commit 1f991b65 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

A publication record can be edited and modified from the check and valide view.

parent 413ede70
""" Publications Controllers
"""
import json
def read():
"""Read a publication record identified by its id.
Design to load a record within a basic Ext.formPanel.
"""
id = request.vars.id
row = db.publications[id]
rep = dict(success=True,
data=row.as_dict())
return json.dumps(rep)
def update():
"""Update a publication record identified by its id.
Design to update record from a basic Ext.form.Panel.
"""
id = request.vars.id
del request.vars.id
db.publications[id] = request.vars
rep = dict(success=True,
msg="Record %s modified" % id)
return json.dumps(rep)
\ No newline at end of file
""" Wizards Controllers
"""
import json
import re
from check_tools import check_publication
from gluon.storage import Storage
from harvest_tools import DRY_RUN
from plugin_dbui import is_foreign_field, get_foreign_field, Selector
from plugin_dbui import (is_foreign_field,
get_foreign_field,
Selector,
to_fields)
DRY_RUN = T(DRY_RUN)
......@@ -73,6 +77,7 @@ def check_validate():
return dict(counters=counters,
logs=logs,
publications_fields=json.dumps(to_fields(db.publications)),
selector=selector)
......
......@@ -368,6 +368,7 @@
'Publishers is not defined': "La revue n'est pas définie",
'Query:': 'Query:',
'Ratio': 'Ratio',
'Record': 'Enregistrement',
'record id': 'record id',
'Record ID': 'Record ID',
'Record not link to a conference': 'Enregistrement sans lien à une conférence',
......@@ -503,6 +504,7 @@
'Universities': 'Universitiés',
'University': 'Université',
'unknown': 'inconnu',
'Update': 'Actualiser',
'Update:': 'Update:',
'Url': 'Url',
'url': 'url',
......
......@@ -9,14 +9,51 @@
#--------------------------------------------------------------------------
#
# prepare the data
# - create URL for id, ids and title
# - configure the Ext.data.Array for the statistics
# - configure the Ext.data.Array for the logs
# - build unique DIV identifier
# - Modify the encoding of the field name for the form
# - write the title
#
#--------------------------------------------------------------------------
import json
#
# create the URL to compare id and ids
# modified the content of the row.title
#
for row in logs:
for i in range(len(row.ids)):
url = URL('wizards',
'compare_publications',
vars=dict(id1=row.id, id2=row.ids[i]))
row.ids[i] = str(A(row.ids[i], _href=url, _target="_blank"))
pass
pass
#
# create the URL pointing to the record in the havest store
# modified the content of the row.ids
#
for row in logs:
origin = db.publications[row.id].origin
if origin:
row.title = str(A(row.title, _href=origin, _target="_blank"))
pass
pass
#
# create the URL to edit the id
# modified the content of the row.id
#
for row in logs:
script = "javascript:onGridLogClick(%i)" % row.id
row.id = str(A(row.id, _href=script))
pass
#
# configure the Ext.data.Array for the statistics
#
......@@ -29,6 +66,7 @@
{'name': 'error', 'type': 'int'}]
cfg['data'] = []
for project in counters:
counter = counters[project]
error = counter.found - counter.ok - counter.validated
......@@ -44,7 +82,7 @@
sorters=['txt', 'title'])
cfg['fields'] = [{'name': 'category', 'type': 'string'},
{'name': 'id', 'type': 'int'},
{'name': 'id', 'type': 'string'},
{'name': 'ids', 'type': 'string'},
{'name': 'project', 'type': 'string'},
{'name': 'title', 'type': 'string'},
......@@ -52,6 +90,7 @@
{'name': 'year', 'type': 'int'}]
cfg['data'] = []
for row in logs:
for txt in row.txt:
cfg['data'].append([row.category,
......@@ -72,6 +111,31 @@
divlogs = abs(hash(cfg_logsStore))
divstat = abs(hash(cfg_statStore))
#
# HACK
#
# simplify the encoding of the field name for the form (TableField → field)
# NOTE: for publication fields are organized in tabPanel
# FIXME: awfull piece of code. Have to solve it in plugin_dbbui
#
items = json.loads(publications_fields)
for tabPanel in items:
for tab in tabPanel['items']:
for field in tab['items']['items']:
if field['xtype'] == 'fieldcontainer':
for el in field['items']:
el['name'] = el['name'].replace("Publications", "").lower()
pass
else:
field['name'] = field['name'].replace("Publications", "").lower()
pass
pass
pass
pass
publications_fields = json.dumps(items)
#
# Write the Title on the HTML page
#
......@@ -117,7 +181,7 @@
<!--
Inline javascript to instantiate and render the Ext JS Grid
Inline javascript to instantiate and render the Ext JS Grids
-->
<script type="text/javascript">
......@@ -139,6 +203,7 @@
write("var cfgLogsStore = %s," % cfg_logsStore)
write(" cfgStatStore = %s," % cfg_statStore)
write(" fields = %s," % publications_fields)
write(" trCategory = '%s'," % T('Category'))
write(" trCollection = '%s'," % T('Collection'))
write(" trDuplicate = '%s'," % T('Duplicate'))
......@@ -146,14 +211,88 @@
write(" trId = '%s'," % T('Id'))
write(" trInvalid = '%s'," % T('Invalid'))
write(" trProject = '%s'," % T('Project'))
write(" trRecord = '%s'," % T('Record'))
write(" trRecords = '%s'," % T('Records'))
write(" trStatistics = '%s'," % T('Statistics'))
write(" trStatusOK = '%s'," % T('Status OK'))
write(" trTitle = '%s'," % T('Title'))
write(" trUpdate = '%s'," % T('Update'))
write(" trValidated = '%s'," % T('Validated'))
write(" trYear = '%s';" % T('Year'))
write(" trYear = '%s'," % T('Year'))
write(" urlRead = '%s'," % URL('publications', 'read'))
write(" urlUpdate = '%s';" % URL('publications', 'update'))
}}
var gridLog,
gridStat;
/**
* handler to instantiate the form allowing to modify a publication record.
*
* @param {Number} publicationId
*
*/
function onGridLogClick(publicationId) {
var actionLoad,
actionSubmit,
formPanel,
window;
//
// define actions
//
actionLoad = {
url: urlRead,
params: {
id: publicationId
}
};
actionSubmit = {
success: function () {
window.close();
},
failure: function (form, action) {
Ext.Msg.alert('Update failed', action.result.msg);
}
};
//
// instantiate the form
// load it with the selected record
//
formPanel = Ext.create('Ext.form.Panel', {
buttons: [{
formBind: true,
text: trUpdate,
handler: function () {
var btn = this;
btn.up('form').submit(actionSubmit);
}
}],
items: fields,
url: urlUpdate,
width: 420
});
formPanel.load(actionLoad);
//
// instantiate the window and show it
//
window = Ext.create('Ext.window.Window', {
closeAction: 'destroy',
items: formPanel,
layout: 'fit',
modal: true,
plain: true,
title: trRecord.concat(" ",publicationId.toString())
});
window.show();
}
/**
* Renderer functions
*
......@@ -166,57 +305,14 @@
* @param {Ext.view.view} view
*
*/
function rDuplicate(value, metadata, record) {
var i,
id1 = record.get("id"),
ids = value.split(","),
pattern = '<a href="/{0}/wizards/compare_publications?id1={1}&id2={2}" target="_blank">{2}</a>',
rep = [];
for (i = 0; i < ids.length; i += 1) {
rep.push(Ext.String.format(pattern, App.name, id1, ids[i]));
}
return rep.join(", ");
}
function rTotal() {
return 'Total';
}
function foo(view, record, item, index, event) {
var publicationId = record.get("id");
Dbui.getForm('publications', function (formCfg, provider) {
var formPanel,
window;
formPanel = Ext.create('App.form.Panel', formCfg);
console.log(publicationId);
console.log(formPanel.store.queryBy(function (record, id) {
console.log(id);
return false;
}));
window = Ext.create('Ext.window.Window', {
closeAction: 'destroy',
items: formPanel,
layout: 'fit',
modal: true,
plain: true
});
window.show();
});
}
//
// instantiate the grids for the Stat
// instantiate the grid showing the statistics
//
var gridStat = Ext.create('Ext.grid.Panel', {
gridStat = Ext.create('Ext.grid.Panel', {
title: trStatistics,
store: Ext.create('Ext.data.ArrayStore', cfgStatStore),
columns: [
......@@ -235,30 +331,28 @@
});
//
// instantiate the grids for the LOGs
// The row are group per error and sorted by title.
// instantiate the grid showing the log for each publication.
// the row are group per error and sorted by title.
// double click on a row display the form to modify the publication record.
//
var gridLog = Ext.create('Ext.grid.Panel', {
gridLog = Ext.create('Ext.grid.Panel', {
store: Ext.create('Ext.data.ArrayStore', cfgLogsStore),
columns: [
{xtype: 'rownumberer'},
{text: trTitle, dataIndex: 'title', flex: 3},
{text: trError, dataIndex: 'txt', flex: 1, hidden: true},
{text: trId, dataIndex: 'id', flex: 0.2},
{text: trDuplicate, dataIndex: 'ids', flex: 0.3, renderer: rDuplicate},
{text: trCategory, dataIndex: 'category', flex: 0.2, hidden: true},
{text: trProject, dataIndex: 'project', flex: 0.5, hidden: true},
{text: trYear, dataIndex: 'year', flex: 0.2, hidden: true}
{text: trDuplicate, dataIndex: 'ids', flex: 0.4},
{text: trCategory, dataIndex: 'category', flex: 0.2},
{text: trProject, dataIndex: 'project', flex: 0.5},
{text: trYear, dataIndex: 'year', flex: 0.2}
],
features: [
{ftype:'grouping', groupHeaderTpl: '{name}', startCollapsed: true}
],
forceFit: true,
padding: "10 40 20 30",
renderTo: 'grid-{{=divlogs}}',
listeners: {
itemdblclick: foo
}
renderTo: 'grid-{{=divlogs}}'
});
</script>
......
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