mirror of
https://github.com/moodle/moodle.git
synced 2025-05-08 17:26:13 +02:00
MDL-39814 frontend: introduced an action_menu_action class
This commit is contained in:
parent
b59f2e3bef
commit
cf69a00a1c
course
lib
theme/bootstrapbase
102
course/lib.php
102
course/lib.php
@ -1773,7 +1773,7 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
|
||||
$editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign');
|
||||
$dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
|
||||
|
||||
// no permission to edit anything
|
||||
// No permission to edit anything.
|
||||
if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) {
|
||||
return array();
|
||||
}
|
||||
@ -1799,21 +1799,20 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
|
||||
}
|
||||
$actions = array();
|
||||
|
||||
// AJAX edit title
|
||||
// AJAX edit title.
|
||||
if ($mod->has_view() && $hasmanageactivities &&
|
||||
(($mod->course == $COURSE->id && course_ajax_enabled($COURSE)) ||
|
||||
($mod->course == SITEID && course_ajax_enabled($SITE)))) {
|
||||
// we will not display link if we are on some other-course page (where we should not see this module anyway)
|
||||
$actions['title'] = new action_link(
|
||||
$actions['title'] = new action_menu_secondary_action(
|
||||
new moodle_url($baseurl, array('update' => $mod->id)),
|
||||
new pix_icon('t/editstring', $str->edittitle, 'moodle', array('class' => 'iconsmall visibleifjs', 'title' => '')),
|
||||
$str->edittitle,
|
||||
null,
|
||||
array('class' => 'editing_title', 'title' => $str->edittitle, 'data-action' => 'edittitle'),
|
||||
new pix_icon('t/editstring', $str->edittitle, 'moodle', array('class' => 'iconsmall visibleifjs', 'title' => ''))
|
||||
array('class' => 'editing_title', 'data-action' => 'edittitle')
|
||||
);
|
||||
}
|
||||
|
||||
// leftright
|
||||
// Indent.
|
||||
if ($hasmanageactivities) {
|
||||
if (right_to_left()) { // Exchange arrows on RTL
|
||||
$rightarrow = 't/left';
|
||||
@ -1827,96 +1826,86 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
|
||||
if ($indent > 0) {
|
||||
$hiddenclass = '';
|
||||
}
|
||||
$actions['moveleft'] = new action_link(
|
||||
$actions['moveleft'] = new action_menu_secondary_action(
|
||||
new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')),
|
||||
new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->moveleft,
|
||||
null,
|
||||
array('class' => 'editing_moveleft ' . $hiddenclass, 'title' => $str->moveleft, 'data-action' => 'moveleft'),
|
||||
new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_moveleft ' . $hiddenclass, 'data-action' => 'moveleft')
|
||||
);
|
||||
$hiddenclass = 'hidden';
|
||||
if ($indent >= 0) {
|
||||
$hiddenclass = '';
|
||||
}
|
||||
$actions['moveright'] = new action_link(
|
||||
$actions['moveright'] = new action_menu_secondary_action(
|
||||
new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')),
|
||||
new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->moveright,
|
||||
null,
|
||||
array('class' => 'editing_moveright ' . $hiddenclass, 'title' => $str->moveright, 'data-action' => 'moveright'),
|
||||
new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_moveright ' . $hiddenclass, 'data-action' => 'moveright')
|
||||
);
|
||||
}
|
||||
|
||||
// move
|
||||
// Move.
|
||||
if ($hasmanageactivities) {
|
||||
$actions['move'] = new action_link(
|
||||
$actions['move'] = new action_menu_primary_action(
|
||||
new moodle_url($baseurl, array('copy' => $mod->id)),
|
||||
new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->move,
|
||||
null,
|
||||
array('class' => 'editing_move status', 'title' => $str->move, 'data-action' => 'move'),
|
||||
new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_move status', 'data-action' => 'move')
|
||||
);
|
||||
}
|
||||
|
||||
// Update
|
||||
// Update.
|
||||
if ($hasmanageactivities) {
|
||||
$actions['update'] = new action_link(
|
||||
$actions['update'] = new action_menu_secondary_action(
|
||||
new moodle_url($baseurl, array('update' => $mod->id)),
|
||||
new pix_icon('t/edit', $str->update, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->update,
|
||||
null,
|
||||
array('class' => 'editing_update', 'title' => $str->update, 'data-action' => 'update'),
|
||||
new pix_icon('t/edit', $str->update, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_update', 'data-action' => 'update')
|
||||
);
|
||||
}
|
||||
|
||||
// Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php)
|
||||
// note that restoring on front page is never allowed
|
||||
// note that restoring on front page is never allowed.
|
||||
if ($mod->course != SITEID && has_all_capabilities($dupecaps, $coursecontext) &&
|
||||
plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) {
|
||||
$actions['duplicate'] = new action_link(
|
||||
$actions['duplicate'] = new action_menu_secondary_action(
|
||||
new moodle_url($baseurl, array('duplicate' => $mod->id)),
|
||||
new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->duplicate,
|
||||
null,
|
||||
array('class' => 'editing_duplicate', 'title' => $str->duplicate, 'data-action' => 'duplicate'),
|
||||
new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_duplicate', 'data-action' => 'duplicate')
|
||||
);
|
||||
}
|
||||
|
||||
// Delete
|
||||
// Delete.
|
||||
if ($hasmanageactivities) {
|
||||
$actions['delete'] = new action_link(
|
||||
$actions['delete'] = new action_menu_secondary_action(
|
||||
new moodle_url($baseurl, array('delete' => $mod->id)),
|
||||
new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->delete,
|
||||
null,
|
||||
array('class' => 'editing_delete', 'title' => $str->delete, 'data-action' => 'delete'),
|
||||
new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_delete', 'data-action' => 'delete')
|
||||
);
|
||||
}
|
||||
|
||||
// hideshow
|
||||
// Hide/Show.
|
||||
if (has_capability('moodle/course:activityvisibility', $modcontext)) {
|
||||
if ($mod->visible) {
|
||||
$actions['hide'] = new action_link(
|
||||
$actions['hide'] = new action_menu_primary_action(
|
||||
new moodle_url($baseurl, array('hide' => $mod->id)),
|
||||
new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->hide,
|
||||
null,
|
||||
array('class' => 'editing_hide', 'title' => $str->hide, 'data-action' => 'hide'),
|
||||
new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_hide', 'data-action' => 'hide')
|
||||
);
|
||||
$actions['hide']->add_class('status');
|
||||
} else {
|
||||
$actions['show'] = new action_link(
|
||||
$actions['show'] = new action_menu_primary_action(
|
||||
new moodle_url($baseurl, array('show' => $mod->id)),
|
||||
new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->show,
|
||||
null,
|
||||
array('class' => 'editing_show', 'title' => $str->show, 'data-action' => 'show'),
|
||||
new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_show', 'data-action' => 'show')
|
||||
);
|
||||
$actions['show']->add_class('status');
|
||||
}
|
||||
}
|
||||
|
||||
// groupmode
|
||||
// Groupmode.
|
||||
if ($hasmanageactivities and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
|
||||
if ($mod->coursegroupmodeforce) {
|
||||
$modgroupmode = $mod->coursegroupmode;
|
||||
@ -1943,27 +1932,24 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
|
||||
$groupimage = 't/groupn';
|
||||
}
|
||||
if (!$mod->coursegroupmodeforce) {
|
||||
$actions[$actionname] = new action_link(
|
||||
$actions[$actionname] = new action_menu_primary_action(
|
||||
new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $groupmode)),
|
||||
new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$grouptitle,
|
||||
null,
|
||||
array('class' => 'editing_'. $actionname, 'title' => $grouptitle, 'data-action' => $actionname, 'data-groupmode' => $groupmode),
|
||||
new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_'. $actionname, 'data-action' => $actionname, 'data-groupmode' => $groupmode)
|
||||
);
|
||||
} else {
|
||||
$actions[$actionname] = new pix_icon($groupimage, $forcedgrouptitle, 'moodle', array('title' => $forcedgrouptitle, 'class' => 'iconsmall'));
|
||||
$actions[$actionname] = new pix_icon($groupimage, $forcedgrouptitle, 'moodle', array('title' => '', 'class' => 'iconsmall'));
|
||||
}
|
||||
$actions[$actionname]->add_class('status');
|
||||
}
|
||||
|
||||
// Assign
|
||||
// Assign.
|
||||
if (has_capability('moodle/role:assign', $modcontext)){
|
||||
$actions['assign'] = new action_link(
|
||||
$actions['assign'] = new action_menu_secondary_action(
|
||||
new moodle_url('/admin/roles/assign.php', array('contextid' => $modcontext->id)),
|
||||
new pix_icon('t/assignroles', $str->assign, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str->assign,
|
||||
null,
|
||||
array('class' => 'editing_assign', 'title' => $str->assign, 'data-action' => 'assignroles'),
|
||||
new pix_icon('t/assignroles', $str->assign, 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
array('class' => 'editing_assign', 'data-action' => 'assignroles')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -350,12 +350,10 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$menu = new action_menu();
|
||||
$menu->set_owner_selector($ownerselector);
|
||||
foreach ($actions as $action) {
|
||||
$action->add_class('cm-edit-action');
|
||||
if ($action->has_class('status')) {
|
||||
$menu->add_primary_action($action);
|
||||
} else {
|
||||
$menu->add_secondary_action($action);
|
||||
if ($action instanceof action_menu_action) {
|
||||
$action->add_class('cm-edit-action');
|
||||
}
|
||||
$menu->add($action);
|
||||
}
|
||||
$menu->attributes['class'] .= ' section-cm-edit-actions commands';
|
||||
return $this->render($menu);
|
||||
|
31
course/yui/toolboxes/toolboxes.js
vendored
31
course/yui/toolboxes/toolboxes.js
vendored
@ -349,9 +349,9 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
|
||||
// Handle removal/addition of the moveleft button
|
||||
if (newindent == 0) {
|
||||
button.remove();
|
||||
button.addClass('hidden');
|
||||
} else if (newindent == 1 && oldindent == 0) {
|
||||
this.change_indent_add_left_button(button);
|
||||
button.ancestor().one('> [data-action=moveleft]').removeClass('hidden');
|
||||
}
|
||||
|
||||
// Handle massive indentation to match non-ajax display
|
||||
@ -546,33 +546,6 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
this.send_request(data, spinner);
|
||||
return false; // Need to return false to stop the delegate for the new state firing
|
||||
},
|
||||
/**
|
||||
* Add the moveleft button
|
||||
* This is required after moving left from an initial position of 0
|
||||
*
|
||||
* @protected
|
||||
* @method change_indent_add_left_button
|
||||
* @param {Node} moveright. The move right icon which should always be there.
|
||||
*/
|
||||
change_indent_add_left_button : function(moveright) {
|
||||
var moveleft = moveright.cloneNode(true);
|
||||
var icon = (BODY.hasClass('dir-rtl')) ? 't/right' : 't/left';
|
||||
var str = M.util.get_string('moveleft', 'moodle');
|
||||
moveleft.setAttrs({
|
||||
'title' : str,
|
||||
'href' : moveright.getAttribute('href').replace('indent=1', 'indent=-1')
|
||||
});
|
||||
moveleft.setData('activity', moveright.getData('activity'));
|
||||
moveleft.setData('action', 'moveleft');
|
||||
moveleft.one('img').setAttrs({
|
||||
'alt' : str,
|
||||
'src' : M.util.image_url(icon, 'moodle')
|
||||
});
|
||||
if (moveleft.one(SELECTOR.ACTIONLINKTEXT)) {
|
||||
moveleft.one(SELECTOR.ACTIONLINKTEXT).setContent(str);
|
||||
}
|
||||
moveright.insert(moveleft, 'before');
|
||||
},
|
||||
|
||||
/**
|
||||
* Edit the title for the resource
|
||||
|
@ -1037,58 +1037,53 @@ class block_manager {
|
||||
|
||||
if ($this->page->user_can_edit_blocks()) {
|
||||
// Move icon.
|
||||
$controls[] = new action_link(
|
||||
$str = new lang_string('moveblock', 'block', $blocktitle);
|
||||
$controls[] = new action_menu_primary_action(
|
||||
new moodle_url($actionurl, array('bui_moveid' => $block->instance->id)),
|
||||
get_string('moveblock', 'block', $blocktitle),
|
||||
null,
|
||||
array('class' => 'editing_move status', 'title' => get_string('moveblock', 'block', $blocktitle)),
|
||||
new pix_icon('t/move', get_string('moveblock', 'block', $blocktitle), 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
new pix_icon('t/move', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str,
|
||||
array('class' => 'editing_move')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if ($this->page->user_can_edit_blocks() || $block->user_can_edit()) {
|
||||
// Edit config icon - always show - needed for positioning UI.
|
||||
$controls[] = new action_link(
|
||||
$str = new lang_string('configureblock', 'block', $blocktitle);
|
||||
$controls[] = new action_menu_primary_action(
|
||||
new moodle_url($actionurl, array('bui_editid' => $block->instance->id)),
|
||||
get_string('configureblock', 'block', $blocktitle),
|
||||
null,
|
||||
array('class' => 'editing_edit status', 'title' => get_string('configureblock', 'block', $blocktitle)),
|
||||
new pix_icon('t/edit', get_string('configureblock', 'block', $blocktitle), 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
new pix_icon('t/edit', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str,
|
||||
array('class' => 'editing_edit')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if ($this->user_can_delete_block($block)) {
|
||||
// Delete icon.
|
||||
$controls[] = new action_link(
|
||||
$str = new lang_string('deleteblock', 'block', $blocktitle);
|
||||
$controls[] = new action_menu_secondary_action(
|
||||
new moodle_url($actionurl, array('bui_deleteid' => $block->instance->id)),
|
||||
get_string('deleteblock', 'block', $blocktitle),
|
||||
null,
|
||||
array('class' => 'editing_delete', 'title' => get_string('deleteblock', 'block', $blocktitle)),
|
||||
new pix_icon('t/delete', get_string('deleteblock', 'block', $blocktitle), 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
new pix_icon('t/delete', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str,
|
||||
array('class' => 'editing_delete')
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->page->user_can_edit_blocks() && $block->instance_can_be_hidden()) {
|
||||
// Show/hide icon.
|
||||
if ($block->instance->visible) {
|
||||
$controls[] = new action_link(
|
||||
new moodle_url($actionurl, array('bui_hideid' => $block->instance->id)),
|
||||
get_string('hideblock', 'block', $blocktitle),
|
||||
null,
|
||||
array('class' => 'editing_hide status', 'title' => get_string('hideblock', 'block', $blocktitle)),
|
||||
new pix_icon('t/hide', get_string('hideblock', 'block', $blocktitle), 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
);
|
||||
$str = new lang_string('hideblock', 'block', $blocktitle);
|
||||
$url = new moodle_url($actionurl, array('bui_hideid' => $block->instance->id));
|
||||
$icon = new pix_icon('t/hide', $str, 'moodle', array('class' => 'iconsmall', 'title' => ''));
|
||||
$attributes = array('class' => 'editing_hide');
|
||||
} else {
|
||||
$controls[] = new action_link(
|
||||
new moodle_url($actionurl, array('bui_showid' => $block->instance->id)),
|
||||
get_string('showblock', 'block', $blocktitle),
|
||||
null,
|
||||
array('class' => 'editing_show status', 'title' => get_string('showblock', 'block', $blocktitle)),
|
||||
new pix_icon('t/show', get_string('showblock', 'block', $blocktitle), 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
);
|
||||
$str = new lang_string('showblock', 'block', $blocktitle);
|
||||
$url = new moodle_url($actionurl, array('bui_showid' => $block->instance->id));
|
||||
$icon = new pix_icon('t/show', $str, 'moodle', array('class' => 'iconsmall', 'title' => ''));
|
||||
$attributes = array('class' => 'editing_show');
|
||||
}
|
||||
$controls[] = new action_menu_primary_action($url, $icon, $str, $attributes);
|
||||
}
|
||||
|
||||
// Assign roles icon.
|
||||
@ -1101,13 +1096,14 @@ class block_manager {
|
||||
|
||||
$rolesurl = new moodle_url('/admin/roles/assign.php', array('contextid'=>$block->context->id,
|
||||
'returnurl'=>$return));
|
||||
$controls[] = new action_link(
|
||||
$rolesurl,
|
||||
get_string('assignrolesinblock', 'block', $blocktitle),
|
||||
null,
|
||||
array('class' => 'editing_roles', 'title' => get_string('assignrolesinblock', 'block', $blocktitle)),
|
||||
new pix_icon('t/assignroles', get_string('assignrolesinblock', 'block', $blocktitle), 'moodle', array('class' => 'iconsmall', 'title' => ''))
|
||||
);
|
||||
// Delete icon.
|
||||
$str = new lang_string('assignrolesinblock', 'block', $blocktitle);
|
||||
$controls[] = new action_menu_secondary_action(
|
||||
$rolesurl,
|
||||
new pix_icon('t/assignroles', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$str,
|
||||
array('class' => 'editing_roles')
|
||||
);
|
||||
}
|
||||
return $controls;
|
||||
}
|
||||
|
@ -3075,19 +3075,12 @@ class action_menu implements renderable {
|
||||
*/
|
||||
public $attributessecondary = array();
|
||||
|
||||
/**
|
||||
* If set to true only the icons for primary action_link objects will be displayed.
|
||||
* @var bool
|
||||
*/
|
||||
public $displayprimaryiconsonly = true;
|
||||
|
||||
/**
|
||||
* Constructs the action menu with the given items.
|
||||
*
|
||||
* @param array $primaryactions An array of primary actions.
|
||||
* @param array $secondaryactions An array of secondary actions.
|
||||
* @param array $actions An array of actions.
|
||||
*/
|
||||
public function __construct(array $primaryactions = array(), array $secondaryactions = array()) {
|
||||
public function __construct(array $actions = array()) {
|
||||
static $initialised = 0;
|
||||
$this->attributes = array(
|
||||
'id' => 'action-menu-'.$initialised,
|
||||
@ -3103,11 +3096,8 @@ class action_menu implements renderable {
|
||||
'class' => 'secondary',
|
||||
'data-rel' => 'menu-content',
|
||||
);
|
||||
foreach ($primaryactions as $action) {
|
||||
$this->add_primary_action($action);
|
||||
}
|
||||
foreach ($secondaryactions as $action) {
|
||||
$this->add_secondary_action($action);
|
||||
foreach ($actions as $action) {
|
||||
$this->add($action);
|
||||
}
|
||||
// We've initialised!
|
||||
$initialised++;
|
||||
@ -3127,6 +3117,25 @@ class action_menu implements renderable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an action to this action menu.
|
||||
*
|
||||
* @param $action
|
||||
*/
|
||||
public function add($action) {
|
||||
if ($action instanceof action_menu_action) {
|
||||
if ($action->primary) {
|
||||
$this->add_primary_action($action);
|
||||
} else {
|
||||
$this->add_secondary_action($action);
|
||||
}
|
||||
} else if ($action instanceof pix_icon) {
|
||||
$this->add_primary_action($action);
|
||||
} else {
|
||||
$this->add_secondary_action($action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a primary action to the action menu.
|
||||
*
|
||||
@ -3156,13 +3165,7 @@ class action_menu implements renderable {
|
||||
if ($output === null) {
|
||||
$output = $OUTPUT;
|
||||
}
|
||||
$actions = array();
|
||||
foreach ($this->primaryactions as $action) {
|
||||
if ($this->displayprimaryiconsonly && $action instanceof action_link && $action->icon) {
|
||||
$action->text = null;
|
||||
}
|
||||
$actions[] = $action;
|
||||
}
|
||||
$actions = $this->primaryactions;
|
||||
$attributes = array(
|
||||
'type' => 'image',
|
||||
'src' => $output->pix_url('t/contextmenu', 'moodle'),
|
||||
@ -3189,3 +3192,128 @@ class action_menu implements renderable {
|
||||
$this->attributes['data-owner'] = $selector;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An action menu action
|
||||
*
|
||||
* @package core
|
||||
* @category output
|
||||
* @copyright 2013 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class action_menu_action implements renderable {
|
||||
|
||||
/**
|
||||
* True if this is a primary action. False if not.
|
||||
* @var bool
|
||||
*/
|
||||
public $primary = true;
|
||||
|
||||
/**
|
||||
* The URL for the action.
|
||||
* @var moodle_url
|
||||
*/
|
||||
public $url;
|
||||
|
||||
/**
|
||||
* The icon to represent the action.
|
||||
* @var pix_icon
|
||||
*/
|
||||
public $icon;
|
||||
|
||||
/**
|
||||
* The text describing the action.
|
||||
* @var string
|
||||
*/
|
||||
public $text;
|
||||
|
||||
/**
|
||||
* An array of attributes for the action.
|
||||
* @var array
|
||||
*/
|
||||
public $attributes;
|
||||
|
||||
/**
|
||||
* Constructs the object.
|
||||
*
|
||||
* @param moodle_url $url The URL for the action.
|
||||
* @param pix_icon $icon The icon to represent the action.
|
||||
* @param string $text The text to represent the action.
|
||||
* @param bool $primary Whether this is a primary action or not.
|
||||
* @param array $attributes Any attribtues associated with the action.
|
||||
*/
|
||||
public function __construct(moodle_url $url, pix_icon $icon, $text, $primary = true, array $attributes = array()) {
|
||||
$this->url = clone($url);
|
||||
$this->icon = $icon;
|
||||
$this->text = $text;
|
||||
$this->primary = (bool)$primary;
|
||||
$this->attributes = $attributes;
|
||||
$this->add_class('menu-action');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a CSS class to this action link object
|
||||
* @param string $class
|
||||
*/
|
||||
public function add_class($class) {
|
||||
if (empty($this->attributes['class'])) {
|
||||
$this->attributes['class'] = $class;
|
||||
} else {
|
||||
$this->attributes['class'] .= ' ' . $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the specified class has been added to this link.
|
||||
* @param string $class
|
||||
* @return bool
|
||||
*/
|
||||
public function has_class($class) {
|
||||
return strpos(' ' . $this->attributes['class'] . ' ', ' ' . $class . ' ') !== false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A primary action menu action
|
||||
*
|
||||
* @package core
|
||||
* @category output
|
||||
* @copyright 2013 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class action_menu_primary_action extends action_menu_action {
|
||||
/**
|
||||
* Constructs the object.
|
||||
*
|
||||
* @param moodle_url $url
|
||||
* @param pix_icon $icon
|
||||
* @param string $text
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(moodle_url $url, pix_icon $icon, $text, array $attributes = array()) {
|
||||
parent::__construct($url, $icon, $text, true, $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A secondary action menu action
|
||||
*
|
||||
* @package core
|
||||
* @category output
|
||||
* @copyright 2013 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class action_menu_secondary_action extends action_menu_action {
|
||||
/**
|
||||
* Constructs the object.
|
||||
*
|
||||
* @param moodle_url $url
|
||||
* @param pix_icon $icon
|
||||
* @param string $text
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(moodle_url $url, pix_icon $icon, $text, array $attributes = array()) {
|
||||
parent::__construct($url, $icon, $text, false, $attributes);
|
||||
}
|
||||
}
|
||||
|
@ -1036,17 +1036,10 @@ class core_renderer extends renderer_base {
|
||||
if (empty($actions)) {
|
||||
return '';
|
||||
}
|
||||
$menu = new action_menu();
|
||||
$menu = new action_menu($actions);
|
||||
if ($blockid !== null) {
|
||||
$menu->set_owner_selector('#'.$blockid);
|
||||
}
|
||||
foreach ($actions as $action) {
|
||||
if ($action->has_class('status')) {
|
||||
$menu->add_primary_action($action);
|
||||
} else {
|
||||
$menu->add_secondary_action($action);
|
||||
}
|
||||
}
|
||||
$menu->attributes['class'] .= ' block-control-actions commands';
|
||||
return $this->render($menu);
|
||||
}
|
||||
@ -1079,6 +1072,69 @@ class core_renderer extends renderer_base {
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an action_menu_action item.
|
||||
*
|
||||
* @param action_menu_action $action
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
protected function render_action_menu_action(action_menu_action $action) {
|
||||
|
||||
$iconrendered = false;
|
||||
|
||||
$text = '';
|
||||
if ($action->icon) {
|
||||
$icon = $action->icon;
|
||||
if ($action->primary) {
|
||||
$action->attributes['title'] = $action->text;
|
||||
}
|
||||
$text .= $this->render($icon);
|
||||
$iconrendered = true;
|
||||
}
|
||||
|
||||
if (!$iconrendered || $action->primary === false) {
|
||||
$text .= html_writer::start_tag('span', array('class'=>'menu-action-text'));
|
||||
if ($action->text instanceof renderable) {
|
||||
$text .= $this->render($action->text);
|
||||
} else {
|
||||
$text .= $action->text;
|
||||
}
|
||||
$text .= html_writer::end_tag('span');
|
||||
}
|
||||
|
||||
// A disabled link is rendered as formatted text
|
||||
if (!empty($action->attributes['disabled'])) {
|
||||
// do not use div here due to nesting restriction in xhtml strict
|
||||
return html_writer::tag('span', $text, array('class'=>'currentlink'));
|
||||
}
|
||||
|
||||
$attributes = $action->attributes;
|
||||
unset($action->attributes['disabled']);
|
||||
$attributes['href'] = $action->url;
|
||||
|
||||
return html_writer::tag('a', $text, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a primary action_menu_action item.
|
||||
*
|
||||
* @param action_menu_primary_action $action
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
protected function render_action_menu_primary_action(action_menu_primary_action $action) {
|
||||
return $this->render_action_menu_action($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a secondary action_menu_action item.
|
||||
*
|
||||
* @param action_menu_secondary_action $action
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
protected function render_action_menu_secondary_action(action_menu_secondary_action $action) {
|
||||
return $this->render_action_menu_action($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a nice side block with an optional header.
|
||||
*
|
||||
@ -1352,13 +1408,11 @@ class core_renderer extends renderer_base {
|
||||
$text .= $this->render($link->icon);
|
||||
}
|
||||
|
||||
$text .= html_writer::start_tag('span', array('class'=>'actionlinktext'));
|
||||
if ($link->text instanceof renderable) {
|
||||
$text .= $this->render($link->text);
|
||||
} else {
|
||||
$text .= $link->text;
|
||||
}
|
||||
$text .= html_writer::end_tag('span');
|
||||
|
||||
// A disabled link is rendered as formatted text
|
||||
if (!empty($link->attributes['disabled'])) {
|
||||
|
@ -114,7 +114,7 @@ ACTIONMENU.prototype = {
|
||||
|
||||
/**
|
||||
* Displays the menu with the given content and alignment.
|
||||
* @param {Node} bodyContent
|
||||
* @param {Node} menu
|
||||
* @param Array align
|
||||
* @returns {M.core.dialogue|dialogue}
|
||||
*/
|
||||
|
@ -113,7 +113,7 @@ ACTIONMENU.prototype = {
|
||||
|
||||
/**
|
||||
* Displays the menu with the given content and alignment.
|
||||
* @param {Node} bodyContent
|
||||
* @param {Node} menu
|
||||
* @param Array align
|
||||
* @returns {M.core.dialogue|dialogue}
|
||||
*/
|
||||
|
@ -1946,10 +1946,10 @@ div.badge .expireimage {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.moodle-actionmenu .actionlinktext {
|
||||
.moodle-actionmenu .menu-action-text {
|
||||
display:none;
|
||||
}
|
||||
.jsenabled .moodle-actionmenu[data-enhanced] .actionlinktext {
|
||||
.jsenabled .moodle-actionmenu[data-enhanced] .menu-action-text {
|
||||
display:inline;
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user