Skip to content

Commit

Permalink
Merge branch 'wip-MDL-52707-master' of https://github.com/marinaglanc…
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Apr 12, 2016
2 parents 45c49f3 + 0d20278 commit 2121537
Show file tree
Hide file tree
Showing 7 changed files with 514 additions and 24 deletions.
5 changes: 5 additions & 0 deletions lang/en/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
$string['helprelatedtags'] = 'Comma separated related tags';
$string['changename'] = 'Change tag name';
$string['changetype'] = 'Change tag type';
$string['combined'] = 'Tags are combined';
$string['combineselected'] = 'Combine selected';
$string['id'] = 'id';
$string['inalltagcoll'] = 'Everywhere';
$string['itemstaggedwith'] = '{$a->tagarea} tagged with "{$a->tag}"';
Expand All @@ -80,6 +82,7 @@
$string['moretags'] = 'more...';
$string['name'] = 'Tag name';
$string['namesalreadybeeingused'] = 'Tag names already being used';
$string['nameuseddocombine'] = 'This tag name is already used, do you want to combine these tags?';
$string['newcollnamefor'] = 'New name for tag collection {$a}';
$string['newnamefor'] = 'New name for tag {$a}';
$string['nextpage'] = 'More';
Expand Down Expand Up @@ -107,6 +110,8 @@
$string['seeallblogs'] = 'See all blog entries tagged with "{$a}"';
$string['select'] = 'Select';
$string['selectcoll'] = 'Select tag collection';
$string['selectmaintag'] = 'Select the tag that will be used after combining';
$string['selectmultipletags'] = 'Please select more than one tag';
$string['selecttag'] = 'Select tag {$a}';
$string['settypedefault'] = 'Remove from standard tags';
$string['settypestandard'] = 'Make standard';
Expand Down
2 changes: 1 addition & 1 deletion lib/amd/build/tag.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions lib/amd/src/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
if (!cnt) {
return false;
}
var tempElement = $("<input type='hidden'/>").attr('name', this.name);
e.preventDefault();
str.get_strings([
{key : 'delete'},
Expand All @@ -108,11 +109,93 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
{key : 'no'},
]).done(function(s) {
notification.confirm(s[0], s[1], s[2], s[3], function() {
tempElement.appendTo(form);
form.submit();
});
}
);
});

// Confirmation for bulk tag combine button.
$("#tag-management-combine").click(function(e){
e.preventDefault();
var form = $(this).closest('form').get(0),
tags = $(form).find("input[type=checkbox]:checked");
if (tags.length <= 1) {
str.get_strings([
{key : 'combineselected', component : 'tag'},
{key : 'selectmultipletags', component : 'tag'},
{key : 'ok'},
]).done(function(s) {
notification.alert(s[0], s[1], s[2]);
}
);
return false;
}
var tempElement = $("<input type='hidden'/>").attr('name', this.name);
str.get_strings([
{key : 'combineselected', component : 'tag'},
{key : 'selectmaintag', component : 'tag'},
{key : 'continue'},
{key : 'cancel'},
]).done(function(s) {
var el = $('<div><form id="combinetags_form" class="form-inline">'+
'<p class="description"></p><p class="options"></p>' +
'<p class="mdl-align"><input type="submit" id="combinetags_submit"/>'+
'<input type="button" id="combinetags_cancel"/></p>' +
'</form></div>');
el.find('.description').html(s[1]);
el.find('#combinetags_submit').attr('value', s[2]);
el.find('#combinetags_cancel').attr('value', s[3]);
var fldset = el.find('.options');
tags.each(function() {
var tagid = $(this).val(),
tagname = $('.inplaceeditable[data-itemtype=tagname][data-itemid='+tagid+']').attr('data-value');
fldset.append($('<input type="radio" name="maintag" id="combinetags_maintag_'+tagid+'" value="'+tagid+
'"/><label for="combinetags_maintag_'+tagid+'">'+tagname+'</label><br>'));
});
var panel = new M.core.dialogue ({
draggable: true,
modal: true,
closeButton: true,
headerContent: s[0],
bodyContent: el.html()
});
panel.show();
$('#combinetags_form input[type=radio]').first().focus().prop('checked', true);
$('#combinetags_form #combinetags_cancel').on('click', function() {
panel.destroy();
});
$('#combinetags_form').on('submit', function() {
tempElement.appendTo(form);
var maintag = $('input[name=maintag]:checked', '#combinetags_form').val();
$("<input type='hidden'/>").attr('name', 'maintag').attr('value', maintag).appendTo(form);
form.submit();
return false;
});
});
});

// When user changes tag name to some name that already exists suggest to combine the tags.
$('body').on('updatefailed', '[data-inplaceeditable][data-itemtype=tagname]', function(e) {
var exception = e.exception; // The exception object returned by the callback.
var newvalue = e.newvalue; // The value that user tried to udpated the element to.
var tagid = $(e.target).attr('data-itemid');
if (exception.errorcode === 'namesalreadybeeingused') {
e.preventDefault(); // This will prevent default error dialogue.
str.get_strings([
{key : 'nameuseddocombine', component : 'tag'},
{key : 'yes'},
{key : 'cancel'},
]).done(function(s) {
notification.confirm(e.message, s[0], s[1], s[2], function() {
window.location.href = window.location.href + "&newname=" + encodeURIComponent(newvalue) +
"&tagid=" + encodeURIComponent(tagid) +
'&action=renamecombine&sesskey=' + M.cfg.sesskey;
});
});
}
});
},

/**
Expand Down
Loading

0 comments on commit 2121537

Please sign in to comment.