Commit ed5c2891 authored by Pat Kira's avatar Pat Kira Committed by Robert Lyon

Style feedback modal and annotation block (BUG 1465107)

behatnotneeded

Change-Id: I5ac5becac82a0e4801fe095c09d5041bab0fc871
parent 8d2dd779
......@@ -13,17 +13,28 @@
* This should be moved to mahara.js to everyone can use it.
*/
function getURLParameter(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return false;
}
function isTinyMceUsed(elementname) {
return (tinyMCE !== undefined && tinyMCE.get(elementname) !== undefined);
}
function initTinyMCE(formname){
var textareaId = formname + '_message';
if (isTinyMceUsed(formname)) {
tinyMCE.execCommand('mceRemoveEditor', false, textareaId);
tinyMCE.execCommand('mceAddEditor', false, textareaId);
}
}
function modifyAnnotationFeedbackSuccess(form, data) {
var formname = form.name;
......@@ -37,6 +48,10 @@ function modifyAnnotationFeedbackSuccess(form, data) {
}
// Reload the annotation feedback table with the new feedback that's just been made public.
// Calls the save method on all editor instances before
// annotation being submitted.
tinyMCE.triggerSave();
sendjsonrequest('../artefact/annotation/annotations.json.php',
{
'annotationid' : $(formname + '_annotationid').value,
......@@ -48,9 +63,13 @@ function modifyAnnotationFeedbackSuccess(form, data) {
}, 'GET', function (data) {
var blockid = $(formname + '_blockid').value;
// Populate the div.
$j('#annotationfeedbackview_' + blockid).html(data.data);
connectAddAnnotationFeedbackForms();
connectAnnotationFeedbackLinks();
(function($) {
var scope = $('#annotationfeedbackview_' + blockid);
scope.html(data.data);
dock.init(scope);
initTinyMCE(formname);
})(jQuery);
});
formSuccess(form, data);
......@@ -61,6 +80,7 @@ function addAnnotationFeedbackSuccess(form, data) {
var blockid = $(formname + '_blockid').value;
var limit = getURLParameter('limit');
var offset = getURLParameter('offset');
var tinymce = $(form.id + '_message');
if (limit === false && offset === false) {
// Pagination is not used.
......@@ -68,11 +88,6 @@ function addAnnotationFeedbackSuccess(form, data) {
offset = null;
}
addElementClass(formname, 'hidden');
if ($('overlay')) {
removeElement('overlay');
}
if (typeof(paginator) != 'undefined' && paginator.id == 'annotationfeedback_pagination_' + blockid) {
// Make sure its using the annotation paginator for its block not the feedback paginator.
paginator.updateResults(data);
......@@ -80,6 +95,10 @@ function addAnnotationFeedbackSuccess(form, data) {
}
else {
// Reload the annotation feedback table with the new feedback that's just been entered.
// Calls the save method on all editor instances before
// annotation being submitted.
tinyMCE.triggerSave();
sendjsonrequest('../artefact/annotation/annotations.json.php',
{
'annotationid' : $(formname + '_annotationid').value,
......@@ -90,14 +109,15 @@ function addAnnotationFeedbackSuccess(form, data) {
'offset' : offset,
}, 'GET', function (data) {
var blockid = $(formname + '_blockid').value;
// Populate the div.
$j('#annotationfeedbackview_' + blockid).html(data.data);
connectAddAnnotationFeedbackForms();
connectAnnotationFeedbackLinks();
// Populate the div
(function($) {
var scope = $('#annotationfeedbackview_' + blockid);
scope.html(data.data);
dock.init(scope);
initTinyMCE(formname);
})(jQuery);
});
}
// Clear TinyMCE
if (isTinyMceUsed(formname + '_message')) {
tinyMCE.activeEditor.setContent('');
......@@ -109,162 +129,5 @@ function addAnnotationFeedbackSuccess(form, data) {
messageid = data.fieldnames.message;
}
$(formname + '_' + messageid).value = '';
rewriteCancelButtons(formname);
formSuccess(form, data);
}
function moveAnnotationFeedbackForm(tinymceused, formname, link) {
if (tinymceused) {
tinyMCE.execCommand('mceRemoveEditor', false, formname + '_message');
}
form = $(formname);
removeElement(form);
appendChildNodes($(link).parentNode, form);
if (tinymceused) {
tinyMCE.execCommand('mceAddEditor', false, formname + '_message');
}
}
function rewriteCancelButtons(formname) {
if ($(formname)) {
var buttons = getElementsByTagAndClassName('input', 'cancel', formname);
// hashed field names on anon forms mean we don't know the exact id of this button
var idprefix = 'cancel_' + formname + '_';
forEach(buttons, function(button) {
if (getNodeAttribute(button, 'id').substring(0, idprefix.length) == idprefix) {
disconnectAll(button);
connect(button, 'onclick', function (e) {
e.stop();
addElementClass(formname, 'hidden');
if ($('overlay')) {
removeElement('overlay');
}
return false;
});
}
});
}
}
function isTinyMceUsed(elementname) {
return (typeof(tinyMCE) != 'undefined' && typeof(tinyMCE.get(elementname)) != 'undefined');
}
function connectAddAnnotationFeedbackForms() {
// There could be several add_annotation_feedback_form forms on the view (one for each annotation).
var annotationfeedbackforms = getElementsByTagAndClassName('form', 'add_annotation_feedback_form');
var formidprefix = 'add_annotation_feedback_form_';
forEach(annotationfeedbackforms, function(annotationfeedbackform) {
if (getNodeAttribute(annotationfeedbackform, 'id').substring(0, formidprefix.length) == formidprefix) {
var annotationformid = getNodeAttribute(annotationfeedbackform, 'id');
rewriteCancelButtons(annotationformid);
if ($(annotationfeedbackform)) {
var links = getElementsByTagAndClassName('a', 'placeannotationfeedback');
// There can be more than one add_annotation_feedback_link on a view
// but only one per block.
var idprefix = 'add_annotation_feedback_link_';
forEach(links, function(link) {
if (getNodeAttribute(link, 'id').substring(0, idprefix.length) == idprefix) {
if ($(link)) {
if (typeof(tinyMCE) != 'undefined') {
tinyMCE.on('SetupEditor', function(editor) {
if (editor.id == annotationformid + '_message') {
editor.on('init', function() {
editor.hide();
});
}
});
}
disconnectAll(link);
connect(link, 'onclick', function(e) {
// get the name of the form we're using.
var blockid = getNodeAttribute(link, 'id').substring(idprefix.length);
var annotationformid = formidprefix + blockid;
var tinymceused = isTinyMceUsed(annotationformid + '_message');
e.stop();
removeElementClass(annotationformid, 'js-hidden');
removeElementClass(annotationformid, 'hidden');
if (typeof(annotationfeedbacklinkinblock) != 'undefined') {
// need to display it as a 'popup' form
moveAnnotationFeedbackForm(tinymceused, annotationformid, link);
addElementClass(annotationformid, 'blockinstance');
addElementClass(annotationformid, 'configure');
addElementClass(annotationformid, 'annotation_form_overlay');
addElementClass(annotationformid, 'vertcentre');
appendChildNodes(document.body, DIV({id: 'overlay'}));
}
if (tinymceused) {
var mce = tinyMCE.get(annotationformid + '_message');
mce.show();
jQuery('.mce-toolbar.mce-first').siblings().toggleClass('hidden');
// Clear out old content that may have been left from a cancel.
mce.setContent('');
mce.focus();
}
else {
$j('#' + annotationformid + ' input:text').eq(1).focus();
// Clear out old content that may have been left from a cancel.
$j('#' + annotationformid + ' input:text').eq(1).text('');
}
return false;
});
}
}
});
}
}
});
}
function connectAnnotationFeedbackLinks() {
var links = getElementsByTagAndClassName('a', 'annotationfeedbacklink');
forEach(links, function(link) {
var idprefix = 'annotation_feedback_link_';
if (getNodeAttribute(link, 'id').substring(0, idprefix.length) == idprefix) {
if ($(link)) {
disconnectAll(link);
connect(link, 'onclick', function(e) {
var blockid = getNodeAttribute(link, 'id').substring(idprefix.length);
var chtml = $j('#annotationfeedbacktable_' + blockid).parent();
// Add a 'close' link at the bottom of the list for convenience.
if ($j('#closer_' + blockid).length == 0) {
var closer = $j('<a id="closer_' + blockid + '" href="#" class="close-link">' + get_string('Close') + '</a>').click(function(e) {
$j(this).parent().toggle(400, function() {
link.focus();
});
e.preventDefault();
});
chtml.append(closer);
}
chtml.toggle(400, function() {
if (chtml.is(':visible')) {
chtml.find('a').first().focus();
}
else {
link.focus();
}
});
e.preventDefault();
});
}
}
});
}
......@@ -322,8 +322,7 @@ class PluginBlocktypeAnnotation extends SystemBlocktype {
public static function get_instance_javascript(BlockInstance $bi) {
return array(
array(
'file' => 'js/annotation.js',
'initjs' => 'connectAddAnnotationFeedbackForms(); connectAnnotationFeedbackLinks();',
'file' => 'js/annotation.js'
)
);
}
......
......@@ -59,7 +59,7 @@ $elements['message'] = array(
'rules' => array('maxlength' => 8192),
);
$elements['ispublic'] = array(
'type' => 'checkbox',
'type' => 'switchbox',
'title' => get_string('makepublic', 'artefact.annotation'),
'defaultvalue' => !$annotationfeedback->get('private'),
);
......
......@@ -1099,7 +1099,7 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
'rules' => array('maxlength' => 8192),
);
$form['elements']['ispublic'] = array(
'type' => 'checkbox',
'type' => 'switchbox',
'title' => get_string('makepublic', 'artefact.annotation'),
'defaultvalue' => !$defaultprivate,
);
......
......@@ -718,7 +718,7 @@ class ArtefactTypeComment extends ArtefactType {
'class' => 'center',
'url' => $data->baseurl,
'jsonscript' => $data->jsonscript,
'datatable' => ($onview) ? 'feedbacktable' : 'commentlist',
'datatable' => 'feedbacktable',
'count' => $data->count,
'limit' => $data->limit,
'offset' => $data->offset,
......@@ -740,7 +740,6 @@ class ArtefactTypeComment extends ArtefactType {
$form = array(
'name' => 'add_feedback_form',
'method' => 'post',
//'class' => 'js-hidden',
'plugintype' => 'artefact',
'pluginname' => 'comment',
'jsform' => true,
......
......@@ -142,25 +142,26 @@ function updateTextContent(a) {
jQuery('#instconf_tagsreadonly_display').innerHTML = a.safetags;
jQuery('#instconf_makecopy').prop('checked', false);
if (a.editable == 1) {
addElementClass('instconf_textreadonly_header', 'hidden');
addElementClass('instconf_textreadonly_container', 'hidden');
addElementClass('instconf_readonlymsg_container', 'hidden');
addElementClass('instconf_licensereadonly_header', 'hidden');
addElementClass('instconf_licensereadonly_container', 'hidden');
addElementClass('instconf_tagsreadonly_header', 'hidden');
addElementClass('instconf_tagsreadonly_container', 'hidden');
removeElementClass('instconf_text_header', 'hidden');
removeElementClass('instconf_text_container', 'hidden');
jQuery('#instconf_textreadonly_header').addClass('hidden');
jQuery('#instconf_textreadonly_container').addClass('hidden');
jQuery('#instconf_readonlymsg_container').addClass('hidden');
jQuery('#instconf_licensereadonly_header').addClass('hidden');
jQuery('#instconf_licensereadonly_container').addClass('hidden');
jQuery('#instconf_tagsreadonly_header').addClass('hidden');
jQuery('#instconf_tagsreadonly_container').addClass('hidden');
jQuery('#instconf_text_header').removeClass('hidden');
jQuery('#instconf_text_container').removeClass('hidden');
if (jQuery('#instconf_license_header').length) {
// only deal with these if the license metadata is enabled
removeElementClass('instconf_license_header', 'hidden');
removeElementClass('instconf_license_container', 'hidden');
removeElementClass('instconf_license_description', 'hidden');
removeElementClass('instconf_license_advanced_fieldset', 'hidden');
jQuery('#instconf_license_header').removeClass('hidden');
jQuery('#instconf_license_container').removeClass('hidden');
jQuery('#instconf_license_description').removeClass('hidden');
jQuery('#instconf_license_advanced_fieldset').removeClass('hidden');
}
removeElementClass('instconf_tags_header', 'hidden');
removeElementClass('instconf_tags_container', 'hidden');
removeElementClass('instconf_tags_description', 'hidden');
jQuery('#instconf_tags_header').removeClass('hidden');
jQuery('#instconf_tags_container').removeClass('hidden');
jQuery('#instconf_tags_description').removeClass('hidden');
var blockcountmsg = jQuery('#instconf_otherblocksmsg_container');
if (blockcountmsg && jQuery('#textbox_blockcount')) {
var otherblockcount = 0;
......@@ -194,26 +195,26 @@ function updateTextContent(a) {
}
}
else {
addElementClass('instconf_text_header', 'hidden');
addElementClass('instconf_text_container', 'hidden');
addElementClass('instconf_otherblocksmsg_container', 'hidden');
jQuery('#instconf_text_header').addClass('hidden');
jQuery('#instconf_text_container').addClass('hidden');
jQuery('#instconf_otherblocksmsg_container').addClass('hidden');
if (jQuery('#instconf_license_header').length) {
// only deal with these if the license metadata is enabled
addElementClass('instconf_license_header', 'hidden');
addElementClass('instconf_license_container', 'hidden');
addElementClass('instconf_license_description', 'hidden');
addElementClass('instconf_license_advanced_fieldset', 'hidden');
jQuery('#instconf_license_header').addClass('hidden');
jQuery('#instconf_license_container').addClass('hidden');
jQuery('#instconf_license_description').addClass('hidden');
jQuery('#instconf_license_advanced_fieldset').addClass('hidden');
}
addElementClass('instconf_tags_header', 'hidden');
addElementClass('instconf_tags_container', 'hidden');
addElementClass('instconf_tags_description', 'hidden');
removeElementClass('instconf_textreadonly_header', 'hidden');
removeElementClass('instconf_textreadonly_container', 'hidden');
removeElementClass('instconf_readonlymsg_container', 'hidden');
removeElementClass('instconf_licensereadonly_header', 'hidden');
removeElementClass('instconf_licensereadonly_container', 'hidden');
removeElementClass('instconf_tagsreadonly_header', 'hidden');
removeElementClass('instconf_tagsreadonly_container', 'hidden');
jQuery('#instconf_tags_header').addClass('hidden');
jQuery('#instconf_tags_container').addClass('hidden');
jQuery('#instconf_tags_description').addClass('hidden');
jQuery('#instconf_textreadonly_header').removeClass('hidden');
jQuery('#instconf_textreadonly_container').removeClass('hidden');
jQuery('#instconf_readonlymsg_container').removeClass('hidden');
jQuery('#instconf_licensereadonly_header').removeClass('hidden');
jQuery('#instconf_licensereadonly_container').removeClass('hidden');
jQuery('#instconf_tagsreadonly_header').removeClass('hidden');
jQuery('#instconf_tagsreadonly_container').removeClass('hidden');
}
}
connect('chooseartefactlink', 'onclick', function(e) {
......@@ -236,38 +237,38 @@ forEach(getElementsByTagAndClassName('a', 'copytextboxnote', 'instconf'), functi
}
});
jQuery('#instconf_makecopy').prop('checked', true);
addElementClass('instconf_textreadonly_header', 'hidden');
addElementClass('instconf_textreadonly_container', 'hidden');
addElementClass('instconf_readonlymsg_container', 'hidden');
addElementClass('instconf_otherblocksmsg_container', 'hidden');
addElementClass('instconf_licensereadonly_header', 'hidden');
addElementClass('instconf_licensereadonly_container', 'hidden');
addElementClass('instconf_tagsreadonly_header', 'hidden');
addElementClass('instconf_tagsreadonly_container', 'hidden');
removeElementClass('instconf_text_header', 'hidden');
removeElementClass('instconf_text_container', 'hidden');
jQuery('#instconf_textreadonly_header').addClass('hidden');
jQuery('#instconf_textreadonly_container').addClass('hidden');
jQuery('#instconf_readonlymsg_container').addClass('hidden');
jQuery('#instconf_otherblocksmsg_container').addClass('hidden');
jQuery('#instconf_licensereadonly_header').addClass('hidden');
jQuery('#instconf_licensereadonly_container').addClass('hidden');
jQuery('#instconf_tagsreadonly_header').addClass('hidden');
jQuery('#instconf_tagsreadonly_container').addClass('hidden');
jQuery('#instconf_text_header').removeClass('hidden');
jQuery('#instconf_text_container').removeClass('hidden');
if (jQuery('#instconf_license_header').length) {
// only deal with these if the license metadata is enabled
removeElementClass('instconf_license_header', 'hidden');
removeElementClass('instconf_license_container', 'hidden');
removeElementClass('instconf_license_description', 'hidden');
removeElementClass('instconf_license_advanced_fieldset', 'hidden');
jQuery('#instconf_license_header').removeClass('hidden');
jQuery('#instconf_license_container').removeClass('hidden');
jQuery('#instconf_license_description').removeClass('hidden');
jQuery('#instconf_license_advanced_fieldset').removeClass('hidden');
}
removeElementClass('instconf_tags_header', 'hidden');
removeElementClass('instconf_tags_container', 'hidden');
removeElementClass('instconf_tags_description', 'hidden');
jQuery('#instconf_tags_header').removeClass('hidden');
jQuery('#instconf_tags_container').removeClass('hidden');
jQuery('#instconf_tags_description').removeClass('hidden');
});
});
augment_tags_control('instconf_tags');
if (jQuery('#instconf_license').length) {
removeElementClass('instconf_license', 'hidden');
jQuery('#instconf_license').removeClass('hidden');
}
if (jQuery('#instconf_license_advanced_fieldset').length) {
removeElementClass(getFirstElementByTagAndClassName('fieldset', null, 'instconf_license_advanced_fieldset'), 'hidden');
}
if (jQuery('#instconf_artefactids_upload_browse')) {
// addElementClass('instconf_artefactids_upload_browse', 'hidden');
// removeElementClass('instconf_artefactids_open_upload_browse_container', 'hidden');
jQuery('#instconf_artefactids_upload_browse').addClass('hidden');
jQuery('#instconf_artefactids_open_upload_browse_container').removeClass('hidden');
}
EOF;
}
......@@ -378,7 +379,6 @@ EOF;
),
'chooseartefact' => array(
'type' => 'html',
'class' => 'nojs-hidden-block',
'value' => '<a id="chooseartefactlink" href="#" class="btn btn-default">'
. get_string('usecontentfromanothertextbox1', 'blocktype.internal/textbox') . '</a>',
),
......
......@@ -133,7 +133,7 @@ var Paginator = function(id, list, heading, script, extradata) {
this.updateResults = function (data, params, changedPage) {
var container = self.isTable ? getFirstElementByTagAndClassName('tbody', null, self.list) : self.list,
listdata = self.isTable || data.data.tablerows.length ? data.data.tablerows : data.data.html,
listdata = data.data.html ? data.data.html : data.data.tablerows,
paginationdata = data.data.pagination;
if (listdata === undefined || listdata.length === 0) {
......@@ -216,7 +216,7 @@ var Paginator = function(id, list, heading, script, extradata) {
}
// Fire event to let listseners know to reattach listeners
window.dispatchEvent(new Event('pageupdated'));
jQuery(document).trigger('pageupdated', [ data ]);
self.params = params;
};
......
......@@ -70,21 +70,20 @@ function isTinyMceUsed() {
return (typeof(tinyMCE) != 'undefined' && typeof(tinyMCE.get('add_feedback_form_message')) != 'undefined');
}
addLoadEvent(function () {
if ($('toggle_watchlist_link')) {
connect('toggle_watchlist_link', 'onclick', function (e) {
e.stop();
jQuery(function($j) {
if ($j('#toggle_watchlist_link').length) {
$j('#toggle_watchlist_link').click(function (e) {
e.preventDefault();
e.stopPropagation();
if (typeof artefactid === 'undefined') {
artefactid = null;
artefactid = 0;
}
sendjsonrequest(config.wwwroot + 'view/togglewatchlist.json.php', {'view': viewid, 'artefact': artefactid}, 'POST', function(data) {
$('toggle_watchlist_link').innerHTML = data.newtext;
});
});
}
});
jQuery(function($j) {
$j(".copyview").each(function() {
$j(this).click(function(e) {
if (e.target.href.match(/collection=(.*)/)) {
......
......@@ -308,6 +308,11 @@ function ArtefactChooserSelect(artefacts) {
self.init();
}
// reattach listeners when page has finished updating
jQuery(window).on('pageupdated', {}, function(e, data) {
new ArtefactChooserSelect(data.data.artefactdata);
});
new ArtefactChooserSelect(acSelectArtefacts);
EOF;
......
......@@ -51,6 +51,7 @@ function pieform_renderer_div(Pieform $form, $element) {/*{{{*/
if (!isset($element['isformgroup'])) {
$element['isformgroup'] = true;
}
if (isset($element['type'])) {
$element['isformgroup'] = $element['type'] === 'button' ? false : $element['isformgroup'];
}
......@@ -58,7 +59,7 @@ function pieform_renderer_div(Pieform $form, $element) {/*{{{*/
// add form-group classes to all real form fields
$formgroupclass = $element['isformgroup'] ? 'form-group' : '';
if(isset($element['class'])){
if (isset($element['class'])) {
// remove form-control class and btn class (these should be on the element only)
$element['class'] = str_replace("btn-", " ", $element['class']);
......
......@@ -6200,7 +6200,7 @@ function create_view_form($group=null, $institution=null, $template=null, $colle
$form['elements']['submitcollection'] = array(
'type' => 'button',
'usebuttontag' => true,
'class' => 'btn btn-sm btn-default',
'class' => 'btn-sm btn-default',
'value' => get_string('copycollection', 'collection'),
);
}
......@@ -6210,7 +6210,7 @@ function create_view_form($group=null, $institution=null, $template=null, $colle
'value' => $template,
);
$form['elements']['submit']['value'] = get_string('copyview', 'view');
$form['elements']['submit']['class'] = 'btn btn-default btn-sm mrm';
$form['elements']['submit']['class'] = 'btn-default btn-sm mrm';