Skip to content

Commit

Permalink
MDL-53254 tags: tag collections inplace editable
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Mar 18, 2016
1 parent 131b78b commit 352bfbf
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 170 deletions.
3 changes: 3 additions & 0 deletions lang/en/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
$string['deletedcoursetags'] = 'Deleted - Course tags';
$string['description'] = 'Description';
$string['editisstandard'] = 'Change standard tag usage';
$string['editcollname'] = 'Edit tag collection name';
$string['editname'] = 'Edit tag name';
$string['editsearchable'] = 'Change searchable';
$string['edittag'] = 'Edit this tag';
$string['edittagcollection'] = 'Change tag collection';
$string['entertags'] = 'Enter tags...';
Expand Down Expand Up @@ -78,6 +80,7 @@
$string['moretags'] = 'more...';
$string['name'] = 'Tag name';
$string['namesalreadybeeingused'] = 'Tag names already being used';
$string['newcollnamefor'] = 'New name for tag collection {$a}';
$string['newnamefor'] = 'New name for tag {$a}';
$string['nextpage'] = 'More';
$string['notagsfound'] = 'No tags matching "{$a}" found';
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.

82 changes: 73 additions & 9 deletions lib/amd/src/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,30 +183,94 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
*/
initManageCollectionsPage: function() {
$('body').on('updated', '[data-inplaceeditable]', function(e) {
var ajaxreturn = e.ajaxreturn;
var oldvalue = e.oldvalue;
var ajaxreturn = e.ajaxreturn,
oldvalue = e.oldvalue,
areaid, collid, isenabled;
if (ajaxreturn.component === 'core_tag' && ajaxreturn.itemtype === 'tagareaenable') {
var areaid = $(this).attr('data-itemid');
areaid = $(this).attr('data-itemid');
$(".tag-collections-table ul[data-collectionid] li[data-areaid="+areaid+"]").addClass('hidden');
var isenabled = ajaxreturn.value;
isenabled = ajaxreturn.value;
if (isenabled === '1') {
$(this).closest('tr').removeClass('dimmed_text');
var collid = $(this).closest('tr').find('[data-itemtype="tagareacollection"]').attr("data-value");
collid = $(this).closest('tr').find('[data-itemtype="tagareacollection"]').attr("data-value");
$(".tag-collections-table ul[data-collectionid="+collid+"] li[data-areaid="+areaid+"]").removeClass('hidden');
} else {
$(this).closest('tr').addClass('dimmed_text');
}
}
if (ajaxreturn.component === 'core_tag' && ajaxreturn.itemtype === 'tagareacollection') {
var areaid = $(this).attr('data-itemid');
areaid = $(this).attr('data-itemid');
$(".tag-collections-table ul[data-collectionid] li[data-areaid="+areaid+"]").addClass('hidden');
var collid = $(this).attr('data-value');
var isenabled = $(this).closest('tr').find('[data-itemtype="tagareaenable"]').attr("data-value");
collid = $(this).attr('data-value');
isenabled = $(this).closest('tr').find('[data-itemtype="tagareaenable"]').attr("data-value");
if (isenabled === "1") {
$(".tag-collections-table ul[data-collectionid="+collid+"] li[data-areaid="+areaid+"]").removeClass('hidden');
}
}
});
});

$('body').on('click', '.addtagcoll > a', function(e) {
e.preventDefault();
var href = $(this).attr('data-url') + '&sesskey=' + M.cfg.sesskey;
str.get_strings([
{key : 'addtagcoll', component : 'tag'},
{key : 'name'},
{key : 'searchable', component : 'tag'},
{key : 'create'},
{key : 'cancel'},
]).done(function(s) {
var el = $('<div><form id="addtagcoll_form" class="form-inline">'+
'<p><label for="addtagcoll_name"></label>: ' +
'<input id="addtagcoll_name" type="text"/><br/>' +
'<label for="addtagcoll_searchable"></label>: ' +
'<input id="addtagcoll_searchable" type="checkbox" value="1" checked/></p>' +
'<p class="mdl-align"><input type="submit" id="addtagcoll_submit"/>'+
'<input type="button" id="addtagcoll_cancel"/></p>' +
'</form></div>');
el.find('label[for="addtagcoll_name"]').html(s[1]);
el.find('label[for="addtagcoll_searchable"]').html(s[2]);
el.find('#addtagcoll_submit').attr('value', s[3]);
el.find('#addtagcoll_cancel').attr('value', s[4]);
var panel = new M.core.dialogue ({
draggable: true,
modal: true,
closeButton: true,
headerContent: s[0],
bodyContent: el.html()
});
panel.show();
$('#addtagcoll_form #addtagcoll_name').focus();
$('#addtagcoll_form #addtagcoll_cancel').on('click', function() {
panel.destroy();
});
$('#addtagcoll_form').on('submit', function() {
var name = $('#addtagcoll_form #addtagcoll_name').val();
var searchable = $('#addtagcoll_form #addtagcoll_searchable').prop('checked') ? 1 : 0;
if (String(name).length > 0) {
window.location.href = href + "&name=" + encodeURIComponent(name) + "&searchable=" + searchable;
}
return false;
});
}
);

});

$('body').on('click', '.tag-collections-table .action_delete', function(e) {
e.preventDefault();
var href = $(this).attr('data-url') + '&sesskey=' + M.cfg.sesskey;
str.get_strings([
{key : 'delete'},
{key : 'suredeletecoll', component : 'tag', param : $(this).attr('data-collname') },
{key : 'yes'},
{key : 'no'},
]).done(function(s) {
notification.confirm(s[0], s[1], s[2], s[3], function() {
window.location.href = href;
});
}
);
});
}
};
});
10 changes: 10 additions & 0 deletions lib/classes/output/inplace_editable.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,14 @@ public function export_for_template(\renderer_base $output) {
'linkeverything' => $this->get_linkeverything() ? 1 : 0,
);
}

/**
* Renders this element
*
* @param renderer_base $output typically, the renderer that's calling this function
* @return string
*/
public function render(\renderer_base $output) {
return $output->render_from_template('core/inplace_editable', $this->export_for_template($output));
}
}
4 changes: 2 additions & 2 deletions tag/classes/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static function display_name($record) {
return get_string($identifier, $component);
}
if (!empty($record->name)) {
return format_string($record->name, true, $syscontext);
return format_string($record->name, true, array('context' => $syscontext));
} else if ($record->isdefault) {
return get_string('defautltagcoll', 'tag');
} else {
Expand Down Expand Up @@ -216,7 +216,7 @@ public static function create($data) {
* Updates the tag collection information
*
* @param stdClass $tagcoll existing record in DB table tag_coll
* @param stdClass $data data from form core_tag_collection_form
* @param stdClass $data data to update
* @return bool wether the record was updated
*/
public static function update($tagcoll, $data) {
Expand Down
79 changes: 0 additions & 79 deletions tag/classes/collection_form.php

This file was deleted.

Loading

0 comments on commit 352bfbf

Please sign in to comment.