Commit ba8da71f authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fixes to menu editor

parent e56aab83
......@@ -59,7 +59,7 @@ function displaymenuitems(itemlist) {
var table = $('menuitemlist');
var newrow = TR({'id':'additem','style':'background-color: #ddd;'},
TD({'colspan':4},addform()));
replaceChildNodes(table,TBODY(null,[thead,rows,newrow]));
replaceChildNodes(table,cols(),TBODY(null,[thead,rows,newrow]));
}
// Creates one table row
......@@ -72,7 +72,7 @@ function formatrow (item) {
var edit = INPUT({'type':'button','value':get_string('edit')});
edit.onclick = function () { edititem(item); };
var cells = map(partial(TD,null),[type,item.name,linkedto,[del,edit]]);
return TR({'id':'menuitem_'+item.id,'class':'menueditcell'},cells);
return TR({'id':'menuitem_'+item.id},cells);
}
// Returns the form which adds a new menu item
......@@ -142,8 +142,8 @@ function editform(item) {
setNodeAttribute(elink,'checked',true);
}
var radios = [DIV(null,elink,eval('externallink')),DIV(null,afile,eval('adminfile'))];
var row = TR(null,map(partial(TD,{'class':'menueditcell'}),[radios,name,linkedto,savecancel]));
return TABLE(null,TBODY(null,row));
var row = TR(null,map(partial(TD,null),[radios,name,linkedto,savecancel]));
return TABLE({'width':'100%'},cols(),TBODY(null,row));
}
// Close all open edit forms
......@@ -210,12 +210,22 @@ function delitem(itemid) {
// Send the menu item in the form to the database.
function saveitem(formid) {
var f = $(formid);
var name = f.name.value;
var linkedto = f.linkedto.value;
if (name == '') {
displayMessage(get_string('namedfieldempty',get_string('name')),'error');
return false;
}
if (linkedto == '') {
displayMessage(get_string('namedfieldempty',get_string('linkedto')),'error');
return false;
}
processingStart();
displayMessage(get_string('savingmenuitem'),'info');
var f = $(formid);
var data = {'type':f.type[0].checked ? 'externallink' : 'adminfile',
'name':f.name.value,
'linkedto':f.linkedto.value,
'name':name,
'linkedto':linkedto,
'itemid':f.itemid.value,
'public':selectedmenu == 'loggedoutmenu'};
var req = getXMLHttpRequest();
......@@ -257,6 +267,12 @@ function changemenu() {
getitems();
}
// Set column widths
function cols () {
COL = partial(createDOM,'col');
return [COL({'width':"20%"}),COL({'width':"25%"}),COL({'width':"40%"}),COL({'width':"15%"})];
}
var selectedmenu = 'loggedoutmenu';
addLoadEvent(function () {
$('menuselect').value = selectedmenu;
......@@ -271,9 +287,10 @@ foreach ($menulist as &$menu) {
'name' => get_string($menu));
}
$style = '<style type="text/css">.invisible{display:none;} .menueditcell{width:200px;}</style>';
$strings = array('deletefailed','deletingmenuitem','menuitemdeleted','noadminfiles',
'edit','delete','update','cancel','add','loggedinmenu','loggedoutmenu');
$style = '<style type="text/css">.invisible{display:none;}</style>';
$strings = array('deletefailed','deletingmenuitem','menuitemdeleted','savingmenuitem','noadminfiles',
'edit','delete','update','cancel','add','loggedinmenu','loggedoutmenu','name',
'linkedto');
$smarty = smarty(array(),array($style),$strings);
$smarty->assign('INLINEJAVASCRIPT',$ijs);
$smarty->assign('EDIT',get_string('edit') . ':');
......
......@@ -75,6 +75,6 @@ else {
}
}
json_reply(false,get_string('savedsuccessfully'));
json_reply(false,get_string('menuitemsaved'));
?>
......@@ -146,6 +146,8 @@ $string['delete'] = 'Delete';
$string['edit'] = 'Edit';
$string['loggedinmenu'] = 'Logged in menu';
$string['loggedoutmenu'] = 'Logged out menu';
$string['menuitemsaved'] = 'Menu item saved';
$string['savingmenuitem'] = 'Saving menu item';
// Site content
$string['about'] = 'About';
......
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