Skip to content

Commit

Permalink
MDL-53254 tags: tags management inplace editable
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Mar 18, 2016
1 parent 352bfbf commit 21d9596
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 265 deletions.
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.

92 changes: 16 additions & 76 deletions lib/amd/src/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,80 +61,19 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
*/
initManagePage: function() {

var update_modified = function(el) {
var row = el.closest('tr').get(0);
if (row) {
var td = $(row).find('td.col-timemodified').get(0);
str.get_string('now').done(function(s) {
$(td).html(s);
});
// Set cell 'time modified' to 'now' when any of the element is updated in this row.
$('body').on('updated', '[data-inplaceeditable]', function(e) {
str.get_string('now').done(function(s) {
$(e.target).closest('tr').find('td.col-timemodified').html(s);
});
if (e.ajaxreturn.itemtype === 'tagflag') {
var row = $(e.target).closest('tr');
if (e.ajaxreturn.value === '0') {
row.removeClass('flagged-tag');
} else {
row.addClass('flagged-tag');
}
}
};

// Click handler for changing tag type.
$('.tag-management-table').delegate('.tagisstandard', 'click', function(e) {
e.preventDefault();
var target = $( this ),
tagid = target.attr('data-id'),
currentvalue = target.attr('data-value'),
isstandard = (currentvalue === "1") ? 0 : 1;

var promises = ajax.call([{
methodname: 'core_tag_update_tags',
args: { tags : [ { id : tagid , isstandard : isstandard } ] }
}, {
methodname: 'core_tag_get_tags',
args: { tags : [ { id : tagid } ] }
}], true);

$.when.apply($, promises)
.done( function(updateresult, data) {
if (updateresult.warnings[0] === undefined && data.tags[0] !== undefined) {
templates.render('core_tag/tagisstandard', data.tags[0]).done(function(html) {
update_modified(target);
var parent = target.parent();
target.replaceWith(html);
parent.find('.tagisstandard').get(0).focus();
});
}
});
});

// Click handler for flagging/resetting tag flag.
$('.tag-management-table').delegate('.tagflag', 'click', function(e) {
e.preventDefault();
var target = $( this ),
tagid = target.attr('data-id'),
currentvalue = target.attr('data-value'),
flag = (currentvalue === "0") ? 1 : 0;

var promises = ajax.call([{
methodname: 'core_tag_update_tags',
args: { tags : [ { id : tagid , flag : flag } ] }
}, {
methodname: 'core_tag_get_tags',
args: { tags : [ { id : tagid } ] }
}], true);

$.when.apply($, promises)
.done( function(updateresult, data) {
if (updateresult.warnings[0] === undefined && data.tags[0] !== undefined) {
var row = target.closest('tr').get(0);
if (row) {
if (data.tags[0].flag) {
$(row).addClass('flagged-tag');
} else {
$(row).removeClass('flagged-tag');
}
}
templates.render('core_tag/tagflag', data.tags[0]).done(function(html) {
update_modified(target);
var parent = target.parent();
target.replaceWith(html);
parent.find('.tagflag').get(0).focus();
});
}
});
});

// Confirmation for single tag delete link.
Expand Down Expand Up @@ -184,7 +123,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
initManageCollectionsPage: function() {
$('body').on('updated', '[data-inplaceeditable]', function(e) {
var ajaxreturn = e.ajaxreturn,
oldvalue = e.oldvalue,
areaid, collid, isenabled;
if (ajaxreturn.component === 'core_tag' && ajaxreturn.itemtype === 'tagareaenable') {
areaid = $(this).attr('data-itemid');
Expand All @@ -193,7 +131,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
if (isenabled === '1') {
$(this).closest('tr').removeClass('dimmed_text');
collid = $(this).closest('tr').find('[data-itemtype="tagareacollection"]').attr("data-value");
$(".tag-collections-table ul[data-collectionid="+collid+"] li[data-areaid="+areaid+"]").removeClass('hidden');
$(".tag-collections-table ul[data-collectionid="+collid+"] li[data-areaid="+areaid+"]")
.removeClass('hidden');
} else {
$(this).closest('tr').addClass('dimmed_text');
}
Expand All @@ -204,7 +143,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
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');
$(".tag-collections-table ul[data-collectionid="+collid+"] li[data-areaid="+areaid+"]")
.removeClass('hidden');
}
}
});
Expand Down
1 change: 0 additions & 1 deletion tag/classes/collections_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class core_tag_collections_table extends html_table {

/**
* Constructor
* @global \core_renderer $OUTPUT
* @param string|moodle_url $pageurl
*/
public function __construct($pageurl) {
Expand Down
5 changes: 1 addition & 4 deletions tag/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ public static function get_tags($tags) {
unset($rv->official);
}
unset($rv->flag);
unset($rv->changetypeurl);
unset($rv->changeflagurl);
}
$return[] = $rv;
}
Expand Down Expand Up @@ -253,8 +251,6 @@ public static function get_tags_returns() {
'whether this flag is standard (deprecated, use isstandard)', VALUE_OPTIONAL),
'isstandard' => new external_value(PARAM_INT, 'whether this flag is standard', VALUE_OPTIONAL),
'viewurl' => new external_value(PARAM_URL, 'URL to view'),
'changetypeurl' => new external_value(PARAM_URL, 'URL to change type (standard or not)', VALUE_OPTIONAL),
'changeflagurl' => new external_value(PARAM_URL, 'URL to set or reset flag', VALUE_OPTIONAL),
), 'information about one tag')
),
'warnings' => new external_warnings()
Expand Down Expand Up @@ -306,6 +302,7 @@ public static function get_tagindex($params) {
$context = $params['ctx'] ? context::instance_by_id($params['ctx']) : context_system::instance();
require_login(null, false, null, false, true);
self::validate_context($context);
$PAGE->set_context(null);

$tag = core_tag_tag::get_by_name($params['tc'], $params['tag'], '*', MUST_EXIST);
$tagareas = core_tag_collection::get_areas($params['tc']);
Expand Down
10 changes: 5 additions & 5 deletions tag/classes/manage_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function get_row_class($row) {
public function col_name($tag) {
global $OUTPUT;
$tagoutput = new core_tag\output\tagname($tag);
return $OUTPUT->render_from_template('core/inplace_editable', $tagoutput->export_for_template($OUTPUT));
return $tagoutput->render($OUTPUT);
}

/**
Expand All @@ -191,8 +191,8 @@ public function col_name($tag) {
*/
public function col_flag($tag) {
global $OUTPUT;
$tagoutput = new core_tag\output\tag($tag);
return $OUTPUT->render_from_template('core_tag/tagflag', $tagoutput->export_for_template($OUTPUT));
$tagoutput = new core_tag\output\tagflag($tag);
return $tagoutput->render($OUTPUT);
}

/**
Expand Down Expand Up @@ -226,8 +226,8 @@ public function col_timemodified($tag) {
*/
public function col_isstandard($tag) {
global $OUTPUT;
$tagoutput = new core_tag\output\tag($tag);
return $OUTPUT->render_from_template('core_tag/tagisstandard', $tagoutput->export_for_template($OUTPUT));
$tagoutput = new core_tag\output\tagisstandard($tag);
return $tagoutput->render($OUTPUT);
}

/**
Expand Down
11 changes: 0 additions & 11 deletions tag/classes/output/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ public function export_for_template(renderer_base $output) {
$url = core_tag_tag::make_url($r->tagcollid, $r->rawname);
$r->viewurl = $url->out(false);

$manageurl = new moodle_url('/tag/manage.php', array('sesskey' => sesskey(),
'tagid' => $this->record->id));
$url = new moodle_url($manageurl);
$url->param('action', 'changetype');
$url->param('isstandard', $r->isstandard ? 0 : 1);
$r->changetypeurl = $url->out(false);

$url = new moodle_url($manageurl);
$url->param('action', $this->record->flag ? 'resetflag' : 'setflag');
$r->changeflagurl = $url->out(false);

return $r;
}
}
Loading

0 comments on commit 21d9596

Please sign in to comment.