Commit 38416eb8 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the logic to launch the "edit and insert" wizard from the harvester report.

parent ce564484
......@@ -121,9 +121,13 @@ def edit_insert():
# authors
check.format_authors(record, format_author_fr)
my_authors = tool._my_author_list(record)
check.my_authors(record, reference=my_authors, cmpFct=family_name_fr)
try:
check.my_authors(record, reference=my_authors, cmpFct=family_name_fr)
except CheckException:
record.my_authors = ''
pass
values['PublicationsFirst_author'] = record.first_author()
values['PublicationsAuthors'] = record.authors()
......@@ -179,13 +183,12 @@ def edit_insert():
values['PublicationsDefense'] = record.defense()
except (CdsException, Marc12Exception, ToolException), e:
return T(str(e))
return INLINE_ALERT % (T('Error'), T(str(e)))
except BaseException, e:
msg = '<br><br><hr/>'
msg += CODE(traceback.format_exc()).xml()
msg += '<hr/>'
return msg
# for debug when web2py is in debug mode
print traceback.format_exc()
return INLINE_ALERT % (T('Error'), T(str(e)))
return dict(cfg=cfg, values=values)
......
......@@ -164,6 +164,7 @@
'Duplicate': 'Doublon',
'E-mail': 'E-mail',
'edit and insert': 'éditer et insérer',
'Edit and insert': 'Editer et insérer',
'Edit current record': 'Edit current record',
'Email sent': 'Email sent',
'Email verification': 'Email verification',
......
......@@ -1868,7 +1868,7 @@ class Record(dict):
regex = re.compile(pattern)
# single author in the author list
if isinstance(self["700"], dict):
if "700" in self and isinstance(self["700"], dict):
if 'u' not in self["700"]:
return None
......@@ -1882,7 +1882,7 @@ class Record(dict):
return None
# list of authors
elif isinstance(self["700"], list):
elif "700" in self and isinstance(self["700"], list):
authors = []
for di in self["700"]:
if 'u' not in di:
......
{{
#--------------------------------------------------------------------------
#
# The python controller return the form configuration, cfg, and
# the values to be loaded, values
# The python controller return:
# - cfg, the form configuration
# - values, the values to be loaded in the form
#
#--------------------------------------------------------------------------
import json
......
......@@ -118,11 +118,11 @@
#
# the DIV blocks, one for each grid
#
divstat = id(cfg_statStore)
divlogs = id(cfg_logsStore)
divstat = "grid-%s" % id(cfg_statStore)
divlogs = "grid-%s" % id(cfg_logsStore)
response.write(DIV(_id="grid-%s" % divstat))
response.write(DIV(_id="grid-%s" % divlogs))
response.write(DIV(_id=divstat))
response.write(DIV(_id=divlogs))
#
# the footer, processing time of the request
......@@ -142,9 +142,16 @@
#
jsvars = ["cfgStatStore = %s" % cfg_statStore,
"cfgLogsStore = %s" % cfg_logsStore,
"divstat = '%s'" % divstat,
"divlogs = '%s'" % divlogs,
"gridStat",
"gridLog",
"harvester = %s" % json.dumps(harvester.as_dict()),
"menu",
"trAction = '%s'" % T('Action'),
"trAdded = '%s'" % T('Added'),
"trCollection = '%s'" % T('Collection'),
"trEditAndInsert = '%s'" % T('Edit and insert'),
"trError = '%s'" % T('Error'),
"trExisting = '%s'" % T('Existing'),
"trFound = '%s'" % T('Found'),
......@@ -162,7 +169,66 @@
<script type="text/javascript">
/**
* Renderer functions
* Launch the Edit and Insert wizard
*/
function onEditAndInsert() {
"use strict";
var host = this.harvester.host,
li,
mask,
record = this.gridLog.getSelectionModel().getSelection()[0],
record_id;
// mask the main ViewPort during the data transfer
//
// NOTE 141112:
// the loadMask option of the component should do the job
// but I never succeed with Ext JS 4.2.1. Therefore it is done by hand
//
mask = Ext.create('Ext.LoadMask', {
msg: 'Loading data from ' + host + '...',
target: Ext.ComponentQuery.query('xviewport')[0]
});
mask.show();
// extract the record identifier from the publication URL
// e.g "http://cds.cern.ch/record/1692474"
li = record.get('url').split("/");
record_id = li[li.length - 1];
// launch the EditAndInsert wizard using a loader
// NOTE 141112: the success function is used to remove the mask
//
Ext.create('Ext.Component', {
loader: {
url: 'harvest/edit_insert',
params: {
Edit_insert_selectorId_teams: this.harvester.id_teams,
Edit_insert_selectorId_projects: this.harvester.id_projects,
Edit_insert_selectorHost: host,
Edit_insert_selectorRecord_id: record_id,
Edit_insert_selectorController: this.harvester.controller,
Edit_insert_selectorId_categories: this.harvester.id_categories
},
autoLoad: true,
failure: function () {
Ext.Msg.alert('Status', 'Data transfer from '+ host +' failed');
},
loadMask: false,
scripts: true,
success: function () {
mask.hide();
},
timeout: 60000
},
renderTo: Ext.getBody()
});
}
/**
* Renderer the publication title as an URL
*
* @param {Object} value
* @param {Object} metadata
......@@ -189,6 +255,18 @@
return rep;
}
/**
* Renderer the total label
*
* @param {Object} value
* @param {Object} metadata
* @param {Ext.data.Model} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Ext.data.Store} store
* @param {Ext.view.view} view
*
*/
function rTotal() {
return 'Total';
}
......@@ -196,7 +274,7 @@
//
// instantiate the grid for the STAT
//
var gridStat = Ext.create('Ext.grid.Panel', {
gridStat = Ext.create('Ext.grid.Panel', {
title: trStatistics,
store: Ext.create('Ext.data.ArrayStore', cfgStatStore),
columns: [
......@@ -220,7 +298,7 @@
features: [{ftype:'summary'}],
forceFit: true,
padding: "0 40 20 30",
renderTo: 'grid-{{=divstat}}'
renderTo: divstat
});
//
......@@ -229,7 +307,7 @@
// Each title is rendered as an URL pointing to the publication
// in the harvester repository
//
var gridLog = Ext.create('Ext.grid.Panel', {
gridLog = Ext.create('Ext.grid.Panel', {
store: Ext.create('Ext.data.ArrayStore', cfgLogsStore),
columns: [
{xtype: 'rownumberer'},
......@@ -243,7 +321,34 @@
],
forceFit: true,
padding: "10 40 20 30",
renderTo: 'grid-{{=divlogs}}'
renderTo: divlogs
});
//
// instantiate the context menu to launch the "Edit and Insert" wizard
//
menu = Ext.create('Ext.menu.Menu', {
items : [{
text: trEditAndInsert,
iconCls: 'xaction-create',
handler: onEditAndInsert,
scope: this
}]
});
gridLog.on('itemcontextmenu', function(view, record, item, index, event) {
event.stopEvent();
menu.showAt(event.getXY());
});
// inhibit context menu on the grid header
gridLog.on("headercontextmenu", function(ct, column, event){
event.stopEvent();
});
// inhibit context menu on the rest of the panel
gridLog.body.up('.x-panel-body').on('contextmenu', function(event) {
event.stopEvent();
});
</script>
\ No newline at end of file
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