Commit 2a26e496 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1650414: Eliminate MochiKit from JS: export.js searchtable viewmenu"

parents ac8ad8fc 4f13a99d
......@@ -10,47 +10,45 @@
// TODO: i18n
addLoadEvent(function() {
removeElementClass($('whatviewsselection'), 'hidden');
jQuery(function($) {
$('#whatviewsselection').removeClass('hidden');
var containers = {
'views': {'container': $('whatviews'), 'visible': false}
'views': {'container': $('#whatviews'), 'visible': false}
};
if ($('whatcollections')) {
containers.collections = {'container': $('whatcollections'), 'visible': false};
if ($('#whatcollections').length) {
containers.collections = {'container': $('#whatcollections')[0], 'visible': false};
}
var radios = [];
function toggleRadios(state) {
forEach(radios, function(r) {
r.disabled = state;
$.each(radios, function() {
$(this).prop('disabled', state);
});
}
var enableRadios = partial(toggleRadios, '');
var disableRadios = partial(toggleRadios, 'disabled');
var enableRadios = toggleRadios.bind(null, '');
var disableRadios = toggleRadios.bind(null, 'disabled');
// Make the radio buttons show/hide the view selector
forEach(getElementsByTagAndClassName('input', 'radio', 'whattoexport-buttons'), function(radio) {
$('#whattoexport-buttons input.radio').each(function(id, radio) {
radios.push(radio);
connect(radio, 'onclick', function(e) {
if (radio.checked) {
$(radio).on('click', function(e) {
if ($(radio).prop('checked')) {
for (var c in containers) {
if (c != radio.value && containers[c].visible) {
disableRadios();
containers[c].visible = false;
slideUp(containers[c].container, {'duration': 0.5, 'afterFinish': enableRadios});
containers[c].container.slideUp( 500, enableRadios);
break;
}
}
if (radio.value != 'all' && !containers[radio.value].visible) {
disableRadios();
containers[radio.value].visible = true;
slideDown(containers[radio.value].container, {
'duration': 0.5, 'afterFinish': enableRadios,
'beforeSetup': function() {
removeElementClass(containers[radio.value].container, 'js-hidden');
}
containers[radio.value].container.slideDown( 500, function() {
containers[radio.value].container.removeClass('js-hidden');
enableRadios();
});
}
}
......@@ -58,54 +56,56 @@ addLoadEvent(function() {
// Open the view selector if the views checkbox is select on page load
if (radio.value != 'all' && radio.checked && !containers[radio.value].visible) {
containers[radio.value].visible = true;
removeElementClass(containers[radio.value].container, 'js-hidden');
containers[radio.value].container.removeClass('js-hidden');
}
});
// Make the export format radio buttons show/hide the includefeedback checkbox
forEach(getElementsByTagAndClassName('input', 'radio', 'exportformat-buttons'), function(radio) {
connect(radio, 'onclick', function(e) {
hideElement($('includefeedback'));
if (radio.checked) {
if (radio.value == 'html') {
showElement($('includefeedback'));
$('#exportformat-buttons input.radio').each(function() {
$(this).on('click', function(e) {
$('#includefeedback').hide();
if ($(this).prop('checked')) {
if ($(this).val() === 'html') {
$('#includefeedback').show();
}
}
});
});
// Hook up 'click to preview' links
forEach(getElementsByTagAndClassName('a', 'viewlink', containers.views.container), function(i) {
disconnectAll(i);
setNodeAttribute(i, 'title', 'Click to preview');
connect(i, 'onclick', function (e) {
e.stop();
var href = getNodeAttribute(this, 'href');
var params = parseQueryString(href.substring(href.indexOf('?') + 1, href.length));
params['export'] = 1;
sendjsonrequest(config['wwwroot'] + 'view/viewcontent.json.php', params, 'POST', partial(showPreview, 'big'));
$(containers.views.container).find('a.viewlink').each(function() {
$(this).off();
$(this).prop('title', 'Click to preview');
$(this).on('click', function (event) {
event.preventDefault();
var href = $(this).prop('href');
var params = {
'id': getUrlParameter('id', href) || '',
'export': 1
};
sendjsonrequest(config['wwwroot'] + 'view/viewcontent.json.php', params, 'POST', showPreview.bind(null, 'big'));
});
});
// Checkbox helpers
var checkboxes = getElementsByTagAndClassName('input', 'checkbox', 'whatviews');
var checkboxHelperDiv = DIV();
var checkboxes = $('#whatviews input.checkbox');
var checkboxHelperDiv = $('<div>');
var checkboxSelectAll = $('selection_all');
connect(checkboxSelectAll, 'onclick', function(e) {
e.stop();
forEach(checkboxes, function(i) {
i.checked = true;
var checkboxSelectAll = $('#selection_all');
$(checkboxSelectAll).on('click', function(e) {
e.preventDefault();
checkboxes.each(function() {
$(this).prop('checked', true);
});
});
var checkboxReverseSelection = $('selection_reverse');
connect(checkboxReverseSelection, 'onclick', function(e) {
e.stop();
forEach(checkboxes, function(i) {
i.checked = !i.checked;
});
var checkboxReverseSelection = $('#selection_reverse');
checkboxReverseSelection.on('click', function(e) {
e.preventDefault();
checkboxes.each(function() {
$(this).prop('checked', !$(this).prop('checked'));
});
});
insertSiblingNodesBefore(getFirstElementByTagAndClassName('div', null, containers.views.container), checkboxHelperDiv);
checkboxHelperDiv.insertBefore($(containers.views.container).find('div:first'));
});
......@@ -8,7 +8,8 @@
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
function SearchTable(id) {
var SearchTable = (function($) {
return function (id) {
var self = this;
this.id = id;
......@@ -19,28 +20,28 @@ function SearchTable(id) {
};
this.searchByChildLink = function (element) {
var children = getElementsByTagAndClassName('a', null, element);
var children = $(element).find('a');
if (children.length == 1) {
var href = getNodeAttribute(children[0], 'href');
var href = children.first().prop('href');
self.params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
self.doSearch();
}
};
this.changePage = function(e) {
e.stop();
e.preventDefault();
self.searchByChildLink(this);
};
this.rewritePaging = function() {
forEach(getElementsByTagAndClassName('span', 'pagination', self.id), function(i) {
connect(i, 'onclick', self.changePage);
$('#' + self.id + ' span.pagination').each(function() {
$(this).on('click', self.changePage);
});
};
this.rewriteQueryButtons = function() {
forEach(getElementsByTagAndClassName('button', 'query-button', self.id), function(i) {
connect(i, 'onclick', self.newQuery);
$('#' + self.id + ' button.query-button').each(function() {
$(this).on('click', self.newQuery);
});
};
......@@ -48,17 +49,17 @@ function SearchTable(id) {
this.newQuery = function(e) {
self.params = {};
forEach(getElementsByTagAndClassName('input', null, getFirstParentByTagAndClassName(this, 'form')), function(i) {
self.params[i.name] = i.value;
$(this).closest('form').find('input').each(function() {
self.params[this.name] = this.value;
});
self.doSearch();
e.stop();
e.preventDefault();
};
this.doSearch = function() {
sendjsonrequest(self.id + '.json.php', self.params, 'POST', function(data) {
$(self.id + '_table').innerHTML = data.data.table;
$(self.id + '_pagination').innerHTML = data.data.pagination;
$('#' + self.id + '_table').html(data.data.table);
$('#' + self.id + '_pagination').html(data.data.pagination);
if (data.data.count) {
self.rewritePaging();
self.rewriteOther();
......@@ -66,7 +67,8 @@ function SearchTable(id) {
});
};
addLoadEvent(self.init);
}
$(document).ready(self.init);
};
}(jQuery));
//searchTable = new SearchTable();
......@@ -28,8 +28,8 @@ function addFeedbackError(form, data) {
function addFeedbackSuccess(form, data) {
paginator.updateResults(data);
// Clear rating from previous submission
forEach(getElementsByTagAndClassName('input', 'star', 'add_feedback_form_rating_container'), function (r) {
r.checked = false;
jQuery('#add_feedback_form_rating_container input.star').each(function() {
jQuery(this).prop('checked', false);
});
paginator.alertProxy('pagechanged', data['data']);
......@@ -43,10 +43,10 @@ function addFeedbackSuccess(form, data) {
if (data.fieldnames && data.fieldnames.message) {
messageid = data.fieldnames.message;
}
$('add_feedback_form_' + messageid).value = '';
jQuery('#add_feedback_form_' + messageid).val('');
// Clear the "Make public" switch back to its default "public" setting
$j('input#add_feedback_form_ispublic').prop('checked', true);
jQuery('input#add_feedback_form_ispublic').prop('checked', true);
// need to change the watchlist link
if (data.data.updatelink) {
......@@ -57,82 +57,82 @@ function addFeedbackSuccess(form, data) {
// Check if the form is displayed inside a modal
// then close the modal
if ($j('#feedback-form').length) {
if (jQuery('#feedback-form').length) {
dock.hide();
}
}
function objectionSuccess(form, data) {
$('objection_form_message').value = '';
jQuery('#objection_form_message').val('');
formSuccess(form, data);
// close the form when the form is submited
// Using bootstrap modal
if ($j('#report-form').length) {
$j('#report-form').modal('hide');
if (jQuery('#report-form').length) {
jQuery('#report-form').modal('hide');
}
}
function resetFeedbackReplyto() {
$j('#comment_reply_parent').hide();
$j('#add_feedback_form_replyto').val('');
$j('#add_feedback_form_ispublic_container .form-switch').show().removeClass('hidden');
$j('#add_feedback_form_ispublic_container .add_feedback_form_privacy_message').remove();
jQuery('#comment_reply_parent').hide();
jQuery('#add_feedback_form_replyto').val('');
jQuery('#add_feedback_form_ispublic_container .form-switch').show().removeClass('hidden');
jQuery('#add_feedback_form_ispublic_container .add_feedback_form_privacy_message').remove();
}
function isTinyMceUsed() {
return (typeof(tinyMCE) != 'undefined' && typeof(tinyMCE.get('add_feedback_form_message')) != 'undefined');
}
jQuery(function($j) {
jQuery(function($) {
// Watchlist
if ($j('#toggle_watchlist_link').length) {
$j('#toggle_watchlist_link').click(function (e) {
if ($('#toggle_watchlist_link').length) {
$('#toggle_watchlist_link').click(function (e) {
e.preventDefault();
e.stopPropagation();
if (typeof artefactid === 'undefined') {
artefactid = 0;
}
sendjsonrequest(config.wwwroot + 'view/togglewatchlist.json.php', {'view': viewid, 'artefact': artefactid}, 'POST', function(data) {
$('toggle_watchlist_link').innerHTML = data.newtext;
jQuery('#toggle_watchlist_link').html(data.newtext);
});
});
}
// Copy view
var copyurl = $j("#copyview-button").attr('href');
$j("#copyview-button").on('click', function(event) {
var copyurl = $("#copyview-button").attr('href');
$("#copyview-button").on('click', function(event) {
if (event.currentTarget.href.match(/collection=(.*)/)) {
event.preventDefault();
event.stopPropagation();
$j("#copyview-form").modal('show');
$("#copyview-form").modal('show');
}
});
$j("#copy-view-button").on('click', function() {
$("#copy-view-button").on('click', function() {
// drop the collection bit from the url
var url = copyurl.replace(/collection=(.*)/, '');
window.location = url;
});
$j("#copy-collection-button").on('click', function() {
$("#copy-collection-button").on('click', function() {
window.location = copyurl;
});
function setupCommentButton(element) {
// Set up the onclick method for all comment reply buttons
var replybutton = $j(element);
var replybutton = $(element);
// Each comment stores its ID as a "replyto" data attribute
var replyto = replybutton.data('replyto');
var canpublicreply = replybutton.data('canpublicreply');
var canprivatereply = replybutton.data('canprivatereply');
if (replyto) {
// Put this comment's ID in the "replyto" hidden form field
$j('#add_feedback_form_replyto').val(replyto);
$('#add_feedback_form_replyto').val(replyto);
var replyview = $j('#comment_reply_parent');
var replyview = $('#comment_reply_parent');
// Remove any previous "reply to" comment that was being displayed
replyview.find('div').remove();
// Display a copy of this comment below the feedback form
var commentcopy = $j('#comment' + replyto).clone();
var commentcopy = $('#comment' + replyto).clone();
// Disable the action buttons from the display copy
commentcopy.find('.comment-item-buttons').remove();
commentcopy.appendTo(replyview);
......@@ -140,8 +140,8 @@ jQuery(function($j) {
// Check whether we need to force a "private" or "public" message
// (This is only for display. We'll also check & enforce this on the server side.)
var makepublicswitch = $j('#add_feedback_form_ispublic_container .form-switch');
$j('#add_feedback_form_ispublic_container .add_feedback_form_privacy_message').remove();
var makepublicswitch = $('#add_feedback_form_ispublic_container .form-switch');
$('#add_feedback_form_ispublic_container .add_feedback_form_privacy_message').remove();
if (canpublicreply && canprivatereply) {
// If they have both options, show the normal switch
makepublicswitch.show().removeClass('hidden');
......@@ -153,44 +153,44 @@ jQuery(function($j) {
// They can only post a public reply
if (!canprivatereply) {
makepublicswitch.find("input#add_feedback_form_ispublic").prop('checked', true);
msg = $j(".add_feedback_form_forcepublic_message").clone().show().removeClass("hidden");
msg = $(".add_feedback_form_forcepublic_message").clone().show().removeClass("hidden");
}
// They can only post a private reply
else {
makepublicswitch.find("input#add_feedback_form_ispublic").prop('checked', false);
msg = $j(".add_feedback_form_forceprivate_message").clone().show().removeClass("hidden");
msg = $(".add_feedback_form_forceprivate_message").clone().show().removeClass("hidden");
}
$j('#add_feedback_form_ispublic_container').append(msg);
$('#add_feedback_form_ispublic_container').append(msg);
}
}
}
$j('#feedbacktable').on('click', '.js-reply', null, function(e){
var replybutton = $j(this);
$('#feedbacktable').on('click', '.js-reply', null, function(e){
var replybutton = $(this);
e.preventDefault();
setupCommentButton(replybutton);
if (replybutton.parents('.js-feedbackbase').length) {
$j('#add_feedback_heading').focus();
$('#add_feedback_heading').focus();
jQuery('html, body').animate({ scrollTop: jQuery('#add_feedback_heading').offset().top }, 'fast');
return false;
}
if (replybutton.parents('.js-feedbackblock').length) {
var commentModal = $j('#add_feedback_link').attr('data-target');
var target = $j(commentModal);
var commentModal = $('#add_feedback_link').attr('data-target');
var target = $(commentModal);
dock.show(target, false, true);
}
});
$j('.js-add-comment-modal').on('click', function(e) {
var replyviewContent = $j('#comment_reply_parent').children();
$('.js-add-comment-modal').on('click', function(e) {
var replyviewContent = $('#comment_reply_parent').children();
e.preventDefault();
// Remove any previous "reply to" comment that was being displayed
replyviewContent.remove();
$j('input#add_feedback_form_replyto').val('');
$('input#add_feedback_form_replyto').val('');
});
});
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