Skip to content

Commit

Permalink
MDL-39814 frontend: introduced an action_menu_action class
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Jul 30, 2013
1 parent b59f2e3 commit cf69a00
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 164 deletions.
102 changes: 44 additions & 58 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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';
Expand All @@ -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;
Expand All @@ -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')
);
}

Expand Down
8 changes: 3 additions & 5 deletions course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,10 @@ public function course_section_cm_edit_actions($actions, cm_info $mod = null, $d
$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);
Expand Down
31 changes: 2 additions & 29 deletions course/yui/toolboxes/toolboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
68 changes: 32 additions & 36 deletions lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1037,58 +1037,53 @@ public function edit_controls($block) {

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.
Expand All @@ -1101,13 +1096,14 @@ public function edit_controls($block) {

$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;
}
Expand Down
Loading

0 comments on commit cf69a00

Please sign in to comment.