Commit 05b01a6b authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Focus management for composite Resume tables (Bug #1487294)"

parents d5b043df 0966ffa8
......@@ -716,13 +716,15 @@ class LeapImportResume extends LeapImportArtefactPlugin {
case PluginImport::DECISION_ADDNEW:
case PluginImport::DECISION_APPEND:
default:
$aid = ArtefactTypeResumeComposite::ensure_composite_value($values, $entry_request->entrytype, $USER->get('id'));
$result = ArtefactTypeResumeComposite::ensure_composite_value($values, $entry_request->entrytype, $USER->get('id'));
$aid = isset($result['error']) ? 0 : $result['artefactid'];
break;
}
if ($aid) {
$importer->add_artefactmapping($entry_request->entryid, $aid);
return $aid;
}
return $aid;
return null;
}
/**
......
......@@ -613,13 +613,16 @@ abstract class ArtefactTypeResumeComposite extends ArtefactTypeResume implements
*/
public static function process_compositeform(Pieform $form, $values) {
global $USER;
$error = self::ensure_composite_value($values, $values['compositetype'], $USER->get('id'));
if (is_array($error)) {
$form->reply(PIEFORM_ERR, array('message' => $error['message']));
if (isset($error['goto'])) {
redirect($error['goto']);
$result = self::ensure_composite_value($values, $values['compositetype'], $USER->get('id'));
if (isset($result['error'])) {
$form->reply(PIEFORM_ERR, array('message' => $result['error']));
if (isset($result['goto'])) {
redirect($result['goto']);
}
}
else {
return $result;
}
}
/**
......@@ -628,7 +631,8 @@ abstract class ArtefactTypeResumeComposite extends ArtefactTypeResume implements
* @param unknown_type $values
* @param unknown_type $compositetype
* @param unknown_type $owner
* @return int If successful, the ID of the composite artefact
* @return array If successful, an array contaning 'artefactid' and 'itemid'
* Otherwise, an array containing 'error' and optionally 'goto'
* @throws SystemException
*/
public static function ensure_composite_value($values, $compositetype, $owner) {
......@@ -708,10 +712,10 @@ abstract class ArtefactTypeResumeComposite extends ArtefactTypeResume implements
$fileid = ArtefactTypeFile::save_uploaded_file($filesindex, $attachment);
}
catch (QuotaExceededException $e) {
return array('message'=>$e->getMessage(), 'goto'=>$goto);
return array('error'=>$e->getMessage(), 'goto'=>$goto);
}
catch (UploadException $e) {
return array('message'=>$e->getMessage(), 'goto'=>$goto);
return array('error'=>$e->getMessage(), 'goto'=>$goto);
}
$a->attach($fileid, $itemid);
......@@ -763,11 +767,11 @@ abstract class ArtefactTypeResumeComposite extends ArtefactTypeResume implements
else {
$error = get_string('duplicateattachment', 'artefact.resume', implode(', ', $is_error));
}
return array('message'=>$error);
return array('error'=>$error);
}
}
}
return $a->id;
return array('artefactid' => $a->id, 'itemid' => $itemid);
}
public function delete() {
......@@ -969,7 +973,7 @@ function compositeSaveCallback(form, data) {
\$j('#' + key + 'form').collapse('hide');
tableRenderers[key].doupdate();
tableRenderers[key].doupdate(null, { focusid: data['focusid'] });
\$j('#add' + key + 'button').focus();
// Do a double check to make sure the formchange checker for the submitted form is actually reset
tableRenderers[key].postupdatecallback = function(response) {
......@@ -1004,7 +1008,7 @@ function moveComposite(type, id, artefact, direction) {
{'id': id, 'artefact': artefact, 'direction':direction},
'GET',
function(data) {
tableRenderers[type].doupdate();
tableRenderers[type].doupdate(null, { focusid: id });
},
function() {
// @todo error
......@@ -1132,7 +1136,10 @@ EOF;
});
return TD({'class':'control-buttons'}, DIV({'class':'btn-group'}, null, editlink, ' ', dellink));
}
]
],
{
focusElement: 'a:first'
}
);
tableRenderers.{$compositetype}.type = '{$compositetype}';
......@@ -2002,13 +2009,15 @@ function addbook_validate(Pieform $form, $values) {
function compositeform_submit(Pieform $form, $values) {
try {
call_static_method(generate_artefact_class_name($values['compositetype']),
$result = call_static_method(generate_artefact_class_name($values['compositetype']),
'process_compositeform', $form, $values);
}
catch (Exception $e) {
$form->json_reply(PIEFORM_ERR, $e->getMessage());
}
$form->json_reply(PIEFORM_OK, get_string('compositesaved', 'artefact.resume'));
$form->json_reply(PIEFORM_OK, array(
'focusid' => $result['itemid'], 'message' => get_string('compositesaved', 'artefact.resume')
));
}
function compositeformedit_submit(Pieform $form, $values) {
......
......@@ -18,6 +18,7 @@ function TableRenderer(target, source, columns, options) {
var self = this;
this.source = source;
this.columns = columns;
this.options = options;
this.offset = 0;
this.limit = 10;
this.paginate = true;
......@@ -34,12 +35,11 @@ function TableRenderer(target, source, columns, options) {
this.init = function() {
self.table = getElement(target);
self.loadingMessage = DIV(
{'class': 'loading-box'},
DIV({'class':'loading-inner'},
SPAN({'class':'icon-spinner icon-pulse icon icon-lg'}),
{'class': 'loading-box'},
DIV({'class':'loading-inner'},
SPAN({'class':'icon-spinner icon-pulse icon icon-lg'}),
SPAN({'class':'loading-message'}, get_string('loading'))
)
);
insertSiblingNodesAfter(self.table, self.loadingMessage);
......@@ -147,7 +147,7 @@ function TableRenderer(target, source, columns, options) {
return false;
};
this.renderdata = function(data) {
this.renderdata = function(data, options) {
replaceChildNodes(self.tbody);
var rownumber = 0;
......@@ -160,7 +160,7 @@ function TableRenderer(target, source, columns, options) {
var tr = self.rowfunction(row, rownumber, data);
if ( row._class ) { tr.className = row._class; }
if ( row._id ) { tr.id = row._id; }
forEach(self.columns, function (column) {
if ( typeof(column) == 'string' ) {
appendChildNodes(tr, TD(null,row[column]));
......@@ -177,11 +177,16 @@ function TableRenderer(target, source, columns, options) {
});
appendChildNodes(self.tbody, tr);
if (options && row.id == options.focusid && self.options.focusElement) {
if (jQuery(tr).find(self.options.focusElement).length) {
jQuery(tr).find(self.options.focusElement).focus();
}
}
});
}
};
this.doupdate = function(request_args) {
this.doupdate = function(request_args, options) {
if (!request_args) {
request_args = {};
}
......@@ -233,7 +238,7 @@ function TableRenderer(target, source, columns, options) {
self.loadingMessage = null;
}
self.renderdata(response);
self.renderdata(response, options);
removeElementClass(self.table, 'hidden');
......@@ -289,11 +294,11 @@ function TableRenderer(target, source, columns, options) {
self.doupdate();
}
else {
addLoadEvent(partial(self.doupdate, request_args));
addLoadEvent(partial(self.doupdate, request_args, null));
}
};
this.defaultPagerOptions =
this.defaultPagerOptions =
{ 'pageChangeCallback': self.pageChange,
'previousPageString': get_string('prevpage'),
'nextPageString': get_string('nextpage'),
......
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