Commit b4203597 authored by Ivan Barreto's avatar Ivan Barreto Committed by Robert Lyon

Bug #1353809: Avoid making duplicate group categories

This change stops one having duplicate group category entries.
We will do the comparison in a case insensitive way so we avoid
having: CatA, caTa, catA, cAta etc.

behatnotneeded

Change-Id: I2daafe898f78e78b0aa0b0bf2ffac29ea1b814e4
parent 4e5bc28e
......@@ -142,7 +142,7 @@ jQuery(function($) {
// Either a save, a cancel button, or both.
var savecancel = [];
var save = $('<input>', {'type':'button','class':'button btn btn-secondary btn-add-group'});
var save = $('<input>', {'type':'button','class':'button btn btn-sm btn-secondary'});
save.on('click', function () { saveitem(item.id); });
var rowtype = 'add';
......@@ -151,6 +151,7 @@ jQuery(function($) {
item.label = {$getstring['addnewgroupcategory']};
// The save button says 'add', and there's no cancel button.
save.prop('value',{$getstring['add']});
save.removeClass('btn-sm btn-secondary').addClass('btn-primary');
savecancel = [save];
}
else { // Editing an existing menu item.
......@@ -159,7 +160,8 @@ jQuery(function($) {
save.prop('value',{$getstring['update']});
var cancel = $('<input>', {'type':'button','class':'button btn btn-sm btn-secondary','value':{$getstring['cancel']}});
cancel.on('click', closeopenedits);
savecancel = [save,cancel];
var savecancelwrapper = $('<span class="btn-group btn-add-group">').append(save).append(cancel);
savecancel = [savecancelwrapper];
item.label = {$getstring['edit']};
}
......@@ -174,7 +176,7 @@ jQuery(function($) {
});
var parentspan = $('<span>').append(label,name);
var row = $('<tr>', {'id':'row'+item.id, 'class':rowtype});
row.append($('<td>').append(parentspan), $('<td>').append(savecancel));
row.append($('<td>').append(parentspan), $('<td>', {'class':rowtype}).append(savecancel));
return row;
}
......@@ -213,12 +215,25 @@ jQuery(function($) {
// Send the menu item in the form to the database.
function saveitem(itemid) {
var f = $('#form');
var name = $('#name'+itemid).val();
var name = $('#name' + itemid).val();
var names = [];
if (name == '') {
displayMessage(get_string('namedfieldempty', 'mahara', {$getstring['name']}), 'error');
return false;
}
$("[id^=menuitem_]:not(.d-none) td:first-child").each(function() {
names.push($(this).text().toLowerCase());
});
if (names.length > 0) {
if (names.includes(name.toLowerCase())) {
displayMessage(get_string('duplicatenamedfield', 'mahara', {$getstring['name']}), 'error');
return false;
}
}
var data = {'name':name,
'itemid':itemid};
sendjsonrequest('updategroup.json.php', data, 'POST', function(r) {
......
......@@ -759,6 +759,7 @@ $string['emailnotsent'] = 'Failed to send contact email. Error messa
// mahara.js
$string['namedfieldempty'] = 'The required field "%s" is empty';
$string['duplicatenamedfield'] = 'The value entered already exists';
$string['processing'] = 'Processing';
$string['unknownerror'] = 'An unknown error occurred (0x20f91a0)';
......
......@@ -1384,6 +1384,7 @@ function jsstrings() {
'processing',
'unknownerror',
'loading',
'duplicatenamedfield',
'showtags',
'couldnotgethelp',
'password',
......
......@@ -431,9 +431,9 @@ td.action-list-copy {
}
}
// Group categories.php: 138
.btn-add-group {
margin-top: 20px;
// For groupcategories.php
#rownew .add {
vertical-align: bottom;
}
.reportsettings .btn.filter {
......
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