Skip to content

Commit

Permalink
MDL-21198 OUTPUT->action_icon improvements, refactoring and fixing co…
Browse files Browse the repository at this point in the history
…nversion regressions
  • Loading branch information
skodak committed Jan 2, 2010
1 parent cb26af1 commit 8ae8bf8
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 366 deletions.
18 changes: 6 additions & 12 deletions admin/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,12 @@

/// Display helper functions ===================================================

function action_url($filterpath, $action) {
function filters_action_url($filterpath, $action) {
global $returnurl;
return $returnurl . '?sesskey=' . sesskey() . '&filterpath=' .
urlencode($filterpath) . '&action=' . $action;
}

function action_icon($url, $icon, $straction) {
global $CFG, $OUTPUT;
return '<a href="' . $url . '" title="' . $straction . '">' .
'<img src="' . $OUTPUT->pix_url('t/' . $icon) . '" alt="' . $straction . '" /></a> ';
}

function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) {
global $CFG, $OUTPUT, $activechoices, $applytochoices, $filternames;
$row = array();
Expand All @@ -249,7 +243,7 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings)
}

// Disable/off/on
$select = html_select::make_popup_form(action_url($filter, 'setstate'), 'newstate', $activechoices, 'active' . basename($filter), $filterinfo->active);
$select = html_select::make_popup_form(filters_action_url($filter, 'setstate'), 'newstate', $activechoices, 'active' . basename($filter), $filterinfo->active);
$select->nothinglabel = false;
$select->form->button->text = get_string('save', 'admin');
$row[] = $OUTPUT->select($select);
Expand All @@ -259,20 +253,20 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings)
$spacer = '<img src="' . $OUTPUT->pix_url('spacer') . '" class="iconsmall" alt="" /> ';
if ($filterinfo->active != TEXTFILTER_DISABLED) {
if (!$isfirstrow) {
$updown .= action_icon(action_url($filter, 'up'), 'up', get_string('up'));
$updown .= $OUTPUT->action_icon(filters_action_url($filter, 'up'), get_string('up'), 't/up');
} else {
$updown .= $spacer;
}
if (!$islastactive) {
$updown .= action_icon(action_url($filter, 'down'), 'down', get_string('down'));
$updown .= $OUTPUT->action_icon(filters_action_url($filter, 'down'), get_string('down'), 't/down');
} else {
$updown .= $spacer;
}
}
$row[] = $updown;

// Apply to strings.
$select = html_select::make_popup_form(action_url($filter, 'setapplyto'), 'stringstoo', $applytochoices, 'applyto' . basename($filter), $applytostrings);
$select = html_select::make_popup_form(filters_action_url($filter, 'setapplyto'), 'stringstoo', $applytochoices, 'applyto' . basename($filter), $applytostrings);
$select->nothinglabel = false;
$select->disabled = $filterinfo->active == TEXTFILTER_DISABLED;
$select->form->button->text = get_string('save', 'admin');
Expand All @@ -288,7 +282,7 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings)

// Delete
if (substr($filter, 0, 4) != 'mod/') {
$row[] = '<a href="' . action_url($filter, 'delete') . '">' . get_string('delete') . '</a>';
$row[] = '<a href="' . filters_action_url($filter, 'delete') . '">' . get_string('delete') . '</a>';
} else {
$row[] = '';
}
Expand Down
28 changes: 8 additions & 20 deletions blocks/global_navigation_tree/block_global_navigation_tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,33 +159,21 @@ function get_content() {
// Grab the items to display
$this->content->items = array($this->page->navigation);

$reloadicon = new moodle_action_icon();
$reloadicon->link->url = $this->page->url;
$reloadicon->link->url->param('regenerate','navigation');
$reloadicon->link->add_class('customcommand');
$reloadicon->image->src = $OUTPUT->pix_url('t/reload');
$reloadicon->image->alt = get_string('reload');
$reloadicon->title = get_string('reload');
$this->content->footer .= $OUTPUT->action_icon($reloadicon);
$this->content->footer .= $OUTPUT->action_icon($this->page->url, get_string('reload'), array('class'=>'customcommand'), 't/reload');

if (empty($this->config->enablesidebarpopout) || $this->config->enablesidebarpopout == 'yes') {
user_preference_allow_ajax_update('nav_in_tab_panel_globalnav'.block_global_navigation_tree::$navcount, PARAM_INT);

$moveicon = new moodle_action_icon();
$moveicon->link->add_classes('moveto customcommand requiresjs');
$moveicon->link->url = $this->page->url;
$movelink = new html_link($this->page->url);
$movelink->add_classes('moveto customcommand requiresjs');
if ($this->docked) {
$moveicon->image->src = $OUTPUT->pix_url('t/movetoblock');
$moveicon->image->alt = $toggleblockdisplay;
$moveicon->image->title = $toggleblockdisplay;
$moveicon->link->url->param('undock', $this->instance->id);
$movelink->url->param('undock', $this->instance->id);
$moveicon = $OUTPUT->action_icon($movelink, $toggleblockdisplay, 't/movetoblock');
} else {
$moveicon->image->src = $OUTPUT->pix_url('t/movetosidetab');
$moveicon->image->alt = $togglesidetabdisplay;
$moveicon->image->title = $togglesidetabdisplay;
$moveicon->link->url->param('dock', $this->instance->id);
$movelink->url->param('dock', $this->instance->id);
$moveicon = $OUTPUT->action_icon($movelink, $toggleblockdisplay, 't/movetosidetab');
}
$this->content->footer .= $OUTPUT->action_icon($moveicon);
$this->content->footer .= $moveicon;
}

// Set content generated to true so that we know it has been done
Expand Down
24 changes: 9 additions & 15 deletions blocks/rss_client/managefeeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,15 @@
'<div class="url">' . $OUTPUT->link($feed->url, $feed->url) .'</div>' .
'<div class="description">' . $feed->description . '</div>';

$editaction = new moodle_action_icon();
$editaction->link->url = $CFG->wwwroot .'/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams;
$editaction->link->title = get_string('edit');
$editaction->image->src = $OUTPUT->pix_url('t/edit');
$editaction->image->alt = get_string('edit');

$deleteaction = new moodle_action_icon();
$deleteaction->link->url = $CFG->wwwroot .'/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id .
'&sesskey=' . sesskey() . $extraparams;
$deleteaction->link->title = get_string('delete');
$deleteaction->image->src = $OUTPUT->pix_url('t/delete');
$deleteaction->image->alt = get_string('delete');
$deleteaction->link->add_confirm_action(get_string('deletefeedconfirm', 'block_rss_client'));

$feedicons = $OUTPUT->action_icon($editaction) . ' ' . $OUTPUT->action_icon($deleteaction);
$editurl = $CFG->wwwroot .'/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams;
$editaction = $OUTPUT->action_icon($editurl, get_string('edit'), 't/edit');

$deleteurl = $CFG->wwwroot .'/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id . '&sesskey=' . sesskey() . $extraparams;
$deletelink = new html_link($deleteurl);
$deletelink->add_confirm_action(get_string('deletefeedconfirm', 'block_rss_client'));
$deleteaction = $OUTPUT->action_icon($deletelink, get_string('delete'), 't/delete');

$feedicons = $editaction . ' ' . $deleteaction;

$table->add_data(array($feedinfo, $feedicons));
}
Expand Down
30 changes: 9 additions & 21 deletions blocks/settings_navigation_tree/block_settings_navigation_tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,35 +140,23 @@ function get_content() {
$this->content->footer = '';
}

$reloadicon = new moodle_action_icon();
$url = $this->page->url;
$url->param('regenerate','navigation');
$reloadicon->link->url = $url;
$reloadicon->link->add_class('customcommand');
$reloadicon->image->src = $OUTPUT->pix_url('t/reload');
$reloadicon->image->alt = get_string('reload');
$reloadicon->title = get_string('reload');
$reloadicon = $OUTPUT->action_icon($this->page->url, get_string('reload'), 't/reload', array('class'=>'customcommand'));

$this->content->footer .= $OUTPUT->action_icon($reloadicon);
$this->content->footer .= $reloadicon;

if (!empty($this->config->enablesidebarpopout) && $this->config->enablesidebarpopout == 'yes') {
user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav'.block_settings_navigation_tree::$navcount, PARAM_INT);

$moveicon = new moodle_action_icon();
$moveicon->link->add_classes('moveto customcommand requiresjs');
$moveicon->link->url = $this->page->url;
$movelink = new html_link($this->page->url);
$movelink->add_classes('moveto customcommand requiresjs');
if ($this->docked) {
$moveicon->image->src = $OUTPUT->pix_url('t/movetoblock');
$moveicon->image->alt = $toggleblockdisplay;
$moveicon->image->title = $toggleblockdisplay;
$moveicon->link->url->param('undock', $this->instance->id);
$movelink->url->param('undock', $this->instance->id);
$moveicon = $OUTPUT->action_icon($movelink, $toggleblockdisplay, 't/movetoblock');
} else {
$moveicon->image->src = $OUTPUT->pix_url('t/movetosidetab');
$moveicon->image->alt = $togglesidetabdisplay;
$moveicon->image->title = $togglesidetabdisplay;
$moveicon->link->url->param('dock', $this->instance->id);
$movelink->url->param('dock', $this->instance->id);
$moveicon = $OUTPUT->action_icon($movelink, $toggleblockdisplay, 't/movetosidetab');
}
$this->content->footer .= $OUTPUT->action_icon($moveicon);
$this->content->footer .= $moveicon;
}
}

Expand Down
22 changes: 8 additions & 14 deletions blog/external_blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,14 @@
$validicon = $OUTPUT->image('i/tick_green_big', array('alt'=>get_string('feedisvalid', 'blog'), 'title'=>get_string('feedisvalid', 'blog')));
}

$editicon = new moodle_action_icon;
$editicon->link->url = new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php', array('id' => $blog->id));
$editicon->link->title = get_string('editexternalblog', 'blog');
$editicon->image->src = $OUTPUT->pix_url('t/edit');
$editicon->image->alt = get_string('editexternalblog', 'blog');

$deleteicon = new moodle_action_icon;
$deleteicon->link->url = new moodle_url($CFG->wwwroot.'/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey' => sesskey()));
$deleteicon->link->title = get_string('deleteexternalblog', 'blog');
$deleteicon->image->src = $OUTPUT->pix_url('t/delete');
$deleteicon->image->alt = get_string('deleteexternalblog', 'blog');
$deleteicon->add_confirm_action(get_string('externalblogdeleteconfirm', 'blog'));
$icons = $OUTPUT->action_icon($editicon) . $OUTPUT->action_icon($deleteicon);
$table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $icons));
$editurl = new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php', array('id' => $blog->id));
$editicon = $OUTPUT->action_icon($editurl, get_string('editexternalblog', 'blog'), 't/edit');

$deletelink = new html_link(new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php', array('id' => $blog->id, 'sesskey'=>sesskey())));
$deletelink->add_confirm_action(get_string('externalblogdeleteconfirm', 'blog'));
$deleteicon = $OUTPUT->action_icon($deletelink, get_string('deleteexternalblog', 'blog'), 't/delete');

$table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $editicon . $deleteicon));
}
echo $OUTPUT->table($table);
}
Expand Down
16 changes: 6 additions & 10 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,9 @@ public function print_html($return=false) {
foreach ($blogassociations as $assocrec) {
$contextrec = $DB->get_record('context', array('id' => $assocrec->contextid));
if ($contextrec->contextlevel == CONTEXT_COURSE) {
$associcon = new moodle_action_icon();
$associcon->link->url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id' => $contextrec->instanceid));
$associcon->image->src = $OUTPUT->pix_url('i/course');
$associcon->linktext = $DB->get_field('course', 'shortname', array('id' => $contextrec->instanceid));
$assocstr .= $OUTPUT->action_icon($associcon);
$url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id' => $contextrec->instanceid));
$text = $DB->get_field('course', 'shortname', array('id' => $contextrec->instanceid)); //TODO: performance!!!!
$assocstr .= $OUTPUT->action_icon($associconurl, $text, 'i/course');
$hascourseassocs = true;
$assoctype = get_string('course');
}
Expand All @@ -260,11 +258,9 @@ public function print_html($return=false) {
$modinfo = $DB->get_record('course_modules', array('id' => $contextrec->instanceid));
$modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module));

$associcon = new moodle_action_icon();
$associcon->link->url = new moodle_url($CFG->wwwroot.'/mod/'.$modname.'/view.php', array('id' => $modinfo->id));
$associcon->image->src = $OUTPUT->pix_url('icon', $modname);
$associcon->linktext = $DB->get_field($modname, 'name', array('id' => $modinfo->instance));
$assocstr .= $OUTPUT->action_icon($associcon);
$url = new moodle_url($CFG->wwwroot.'/mod/'.$modname.'/view.php', array('id' => $modinfo->id));
$text = $DB->get_field($modname, 'name', array('id' => $modinfo->instance)); //TODO: performance!!!!
$assocstr .= $OUTPUT->action_icon($associconurl, $text, $OUTPUT->pix_url('icon', $modname));
$assocstr .= ', ';
$assoctype = get_string('modulename', $modname);

Expand Down
29 changes: 7 additions & 22 deletions grade/edit/tree/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,12 @@ public function build_html_tree($element, $totals, $parents, $level, &$row_count

if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) {
if ($this->element_deletable($element)) {
$actionicon = new moodle_action_icon();
$actionicon->link->url = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey()));
$actionicon->image->src = $OUTPUT->pix_url('t/delete');
$actionicon->image->alt = get_string('delete');
$actionicon->image->title = get_string('delete');
$actionicon->image->add_class('iconsmall');
$actions .= $OUTPUT->action_icon($actionicon);
$aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey()));
$actions .= $OUTPUT->action_icon($aurl, get_string('delete'), 't/delete', array('class'=>'iconsmall'));
}

$actionicon = new moodle_action_icon();
$actionicon->link->url = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey()));
$actionicon->image->src = $OUTPUT->pix_url('t/move');
$actionicon->image->alt = get_string('move');
$actionicon->image->title = get_string('move');
$actionicon->image->add_class('iconsmall');
$actions .= $OUTPUT->action_icon($actionicon);
$aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey()));
$actions .= $OUTPUT->action_icon($aurl, get_string('move'), 't/move', array('class'=>'iconsmall'));
}

$actions .= $this->gtree->get_hiding_icon($element, $this->gpr);
Expand Down Expand Up @@ -218,19 +208,14 @@ public function build_html_tree($element, $totals, $parents, $level, &$row_count
$strmovehere = get_string('movehere');
$actions = ''; // no action icons when moving

$moveicon = new moodle_action_icon();
$moveicon->link->url = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey()));
$aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey()));
if ($first) {
$moveicon->link->url->params($first);
$aurl->params($first);
}
$moveicon->image->add_class('movetarget');
$moveicon->image->src = $OUTPUT->pix_url('movehere');
$moveicon->image->alt = $strmovehere;
$moveicon->image->title = $strmovehere;

$cell = new html_table_cell();
$cell->colspan = 12;
$cell->text = $OUTPUT->action_icon($moveicon);
$cell->text = $OUTPUT->action_icon($aurl, $strmovehere, 'movehere', array('class'=>'movetarget'));

$moveto = html_table_row::make(array($cell));
}
Expand Down
26 changes: 8 additions & 18 deletions grade/export/keymanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,16 @@
$line[1] = $key->iprestriction;
$line[2] = empty($key->validuntil) ? get_string('always') : userdate($key->validuntil);

$icon = new moodle_action_icon();
$icon->link->url = new moodle_url('key.php');
$url = new moodle_url('key.php');
if (!empty($key->id)) {
$icon->link->url->param('id', $key->id);
$url->param('id', $key->id);
}
$icon->image->add_class('iconsmall');

$editicon = clone($icon);
$editicon->image->src = $OUTPUT->pix_url('t/edit');
$editicon->image->title = $stredit;
$editicon->image->alt = $stredit;
$buttons = $OUTPUT->action_icon($editicon);

$deleteicon = clone($icon);
$deleteicon->image->src = $OUTPUT->pix_url('t/delete');
$deleteicon->image->title = $strdelete;
$deleteicon->image->alt = $strdelete;
$deleteicon->link->url->param('delete', 1);
$deleteicon->link->url->param('sesskey', sesskey());
$buttons .= $OUTPUT->action_icon($deleteicon);

$buttons = $OUTPUT->action_icon($url, $stredit, 't/edit', array('class'=>'iconsmall'));

$url->param('delete', 1);
$url->param('sesskey', sesskey());
$buttons .= $OUTPUT->action_icon($url, $strdelete, 't/delete', array('class'=>'iconsmall'));

$line[3] = $buttons;
$data[] = $line;
Expand Down
Loading

0 comments on commit 8ae8bf8

Please sign in to comment.