Commit eec30691 authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review

Merge "Set default layout columns/widths hardcoded once (Bug #1307760)"

parents 50d69f71 a4ba6cac
......@@ -138,21 +138,21 @@
$('#viewlayout_basic_container legend a, #viewlayout_adv_container legend a').click(function(event) {
$('.basiclayoutfieldset').toggleClass('collapsed');
$('.advancedlayoutfieldset').toggleClass('collapsed');
$selected = $('#viewlayout_layoutselect').val();
var fallback = 5; // 1 row, 3 columns
if ($('.layoutselect :radio[value=' + $selected +']').length ) {
$('.layoutselect :radio[value=' + $selected +']').attr("checked","checked");
var layoutselected = $('#viewlayout_layoutselect').val();
var layoutfallback = $('#viewlayout_layoutfallback').val();
if ($('.layoutselect :radio[value=' + layoutselected +']').length ) {
$('.layoutselect :radio[value=' + layoutselected +']').attr("checked","checked");
}
else {
$('.layoutselect :radio[value=' + fallback + ']').attr("checked","checked");
$('#viewlayout_layoutselect').val(fallback);
$('.layoutselect :radio[value=' + layoutfallback + ']').attr("checked","checked");
$('#viewlayout_layoutselect').val(layoutfallback);
}
if ($('.advancedlayoutselect :radio[value=' + $selected +']').length ) {
$('.advancedlayoutselect :radio[value=' + $selected +']').attr("checked","checked");
if ($('.advancedlayoutselect :radio[value=' + layoutselected +']').length ) {
$('.advancedlayoutselect :radio[value=' + layoutselected +']').attr("checked","checked");
}
else {
$('.advancedlayoutselect :radio[value=' + fallback + ']').attr("checked","checked");
$('#viewlayout_layoutselect').val(fallback);
$('.advancedlayoutselect :radio[value=' + layoutfallback + ']').attr("checked","checked");
$('#viewlayout_layoutselect').val(layoutfallback);
}
});
......
......@@ -295,10 +295,6 @@ class View {
$this->ownerobj = $USER;
}
if (empty(self::$layoutcolumns)) {
self::$layoutcolumns = get_records_assoc('view_layout_columns', '', '', 'columns,id');
}
$this->atime = time();
$this->rows = array();
$this->columns = array();
......@@ -557,7 +553,7 @@ class View {
$defaultdata = array(
'numcolumns' => 2,
'numrows' => 1,
'columnsperrow' => array(1 => (object)array('row' => 1, 'columns' => 3)),
'columnsperrow' => self::default_columnsperrow(),
'template' => 0,
'type' => 'portfolio',
'title' => (array_key_exists('title', $viewdata)) ? $viewdata['title'] : self::new_title(get_string('Untitled', 'view'), (object)$viewdata),
......@@ -608,6 +604,14 @@ class View {
return new View($view->get('id')); // Reread to ensure defaults are set
}
public function default_columnsperrow() {
$default = array(1 => (object)array('row' => 1, 'columns' => 3, 'widths' => '33,33,33'));
if (!$id = get_field('view_layout_columns', 'id', 'columns', $default[1]->columns, 'widths', $default[1]->widths)) {
throw new SystemException("View::default_columnsperrow: Default columns = 3, widths = '33,33,33' not in view_layout_columns table");
}
return $default;
}
public function get($field) {
if (!property_exists($this, $field)) {
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
......@@ -2822,6 +2826,7 @@ class View {
foreach ($columnsperrow as $row) {
$numcolumns = $row->columns;
$widths = self::$defaultcolumnlayouts[$numcolumns];
$layout->id = get_field('view_layout_columns', 'id', 'columns', $numcolumns, 'widths', $widths);
$layout->rows[$row->row]['widths'] = $widths;
$layout->rows[$row->row]['columns'] = $numcolumns;
}
......
......@@ -92,9 +92,8 @@ foreach ($columnlayouts as $layout => $percents) {
}
// provide a simple default to build custom layouts with
$defaultcustomlayout = array(1 => 5); // row => column layout id
$customlayout = $defaultcustomlayout[1];
$defaultlayout = get_record('view_layout_columns', 'id', $customlayout );
$defaultcustomlayout = $view->default_columnsperrow();
$defaultlayout = get_record('view_layout_columns', 'columns', $defaultcustomlayout[1]->columns, 'widths', $defaultcustomlayout[1]->widths);
$clnumcolumnsdefault = $defaultlayout->columns;
$clwidths = $defaultlayout->widths;
......@@ -125,6 +124,10 @@ $elements['layoutselect'] = array(
'value' => $currentlayout,
'sesskey' => $USER->get('sesskey'),
);
$elements['layoutfallback'] = array(
'type' => 'hidden',
'value' => $defaultlayout->id,
);
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('save'),
......@@ -138,7 +141,7 @@ $templatedata = array(
'clnumcolumnsoptions' => $clnumcolumnsoptions,
'clnumcolumnsdefault' => $clnumcolumnsdefault,
'columnlayoutoptions' => $columnlayoutoptions,
'customlayout' => $customlayout,
'customlayout' => $defaultlayout->id,
'clwidths' => $clwidths,
'maxrows' => $maxrows
);
......@@ -178,7 +181,7 @@ $smarty->display('view/layout.tpl');
function viewlayout_validate(Pieform $form, $values) {
global $layoutrows;
if (!isset($layoutrows[$values['layoutselect']]) ) {
$form->set_error('invalidlayout');
$form->set_error(null, get_string('invalidlayoutselection', 'error'));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment