Skip to content

Commit

Permalink
Implemented icons as part of the types plugin
Browse files Browse the repository at this point in the history
- Implemented icons and valid_children of the jstree
- enabled drag and drop in the tree
  • Loading branch information
torinfo committed May 29, 2014
1 parent a491ec9 commit 05ce84e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 22 deletions.
12 changes: 9 additions & 3 deletions editor/css/complex.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
display: block;
}


button
{
padding: 1px;
}

body {
font-family: Arial, sans-serif;
Expand Down Expand Up @@ -69,7 +72,7 @@ table {
text-align: left;
}
td {
padding: 2px 7px 3px;
padding: 2px;
border-color: #666 #CCC;
vertical-align: top;
}
Expand Down Expand Up @@ -416,8 +419,11 @@ table.wizard{
width: 100%;
}

td.wizardlabel {
width: 200px;
}

td.wizardvalue {
width: 85%;
}

img.optional {
Expand Down
19 changes: 14 additions & 5 deletions editor/js/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ var EDITOR = (function ($, parent) {
menu_options[a[j].name] = a[j].value;
}

// newnodes (+ defaults)
var new_nodes = [];
var new_nodes_defaults = []
$($(this).children('newNodes').children()).each( function () {
new_nodes.push(this.nodeName);
new_nodes_defaults.push($(this)[0].firstChild.data);
});

// collect and organize the options
var node_options = {};
var all_options = [];
var name_option = [];
Expand Down Expand Up @@ -135,7 +144,7 @@ var EDITOR = (function ($, parent) {
node_options['optional'] = opt_options;
node_options['all'] = all_options;

wizard_data[main_node] = {'menu_options' : menu_options, 'node_options' : node_options};
wizard_data[main_node] = {menu_options : menu_options, new_nodes: new_nodes, new_nodes_defaults: new_nodes_defaults, node_options : node_options};
});
//wizard_data.menus = String(wizard_xml[0].attributes["menus"].value).split(',');

Expand All @@ -149,9 +158,9 @@ var EDITOR = (function ($, parent) {
// Parse the file
var x2js = new X2JS({
// XML attributes. Default is "_"
attributePrefix : "@"
attributePrefix : "$"
});
selected_language = x2js.xml_str2json(xml);
selected_language = x2js.xml_str2json(xml).language;
waittomerge();
},

Expand All @@ -160,9 +169,9 @@ var EDITOR = (function ($, parent) {
// Parse the file
var x2js = new X2JS({
// XML attributes. Default is "_"
attributePrefix : "@"
attributePrefix : "$"
});
fallback_language = x2js.xml_str2json(xml);
fallback_language = x2js.xml_str2json(xml).language;
waittomerge();
},

Expand Down
29 changes: 24 additions & 5 deletions editor/js/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ var EDITOR = (function ($, parent) {
var this_json = {
id : key,
text : (xmlData[0].attributes['name'] ? xmlData[0].attributes['name'].value : xmlData[0].nodeName),
icon : 'editor/img/page_types/' + xmlData[0].nodeName + '.png'
type : xmlData[0].nodeName
}
console.log(this_json);

// if we are at top level then make sure it's open and display node data
if (parent_id == null) {
Expand Down Expand Up @@ -138,6 +139,17 @@ var EDITOR = (function ($, parent) {
return value;
},

getIcon = function (nodeName)
{
var node = wizard_data[nodeName];
var icon = "";
if (node.menu_options.icon)
{
icon = moduleurlvariable + "/icons/" + node.menu_options.icon + ".png";
}

return icon;
},

getAttributeValue = function (attributes, name, options, key)
{
Expand Down Expand Up @@ -167,9 +179,10 @@ var EDITOR = (function ($, parent) {
},


displayParameter = function (id, all_options, name, value, key)
displayParameter = function (id, all_options, name, value, key, nodelabel)
{
var options = getOptionValue(all_options, name);
var options = (nodelabel ? {type : name} : getOptionValue(all_options, name));
var label = (nodelabel ? nodelabel : options.label);
if (options != null)
{
var output_string = '<tr class="wizardattribute">';
Expand All @@ -181,7 +194,7 @@ var EDITOR = (function ($, parent) {
{
output_string += '<td class="wizardparameter"></td>';
}
output_string += '<td class="wizardlabel">' + options.label + ' : </td>';
output_string += '<td class="wizardlabel">' + label + ' : </td>';
output_string += '<td class="wizardvalue">' + displayDataType(value, options, name, key) + '</td>';
output_string += '</tr>';
$(id).append(output_string);
Expand Down Expand Up @@ -418,7 +431,7 @@ var EDITOR = (function ($, parent) {
case 'textarea':
var id = "textarea_" + form_id_offset;
form_id_offset++;
html = "<div style=\"width:1000px\"><textarea id=\"" + id + "\" class=\"ckeditor\" onchange=\"inputChanged('" + id + "', '" + key + "', '" + name + "')\" style=\"";
html = "<div style=\"width:100%\"><textarea id=\"" + id + "\" class=\"ckeditor\" onchange=\"inputChanged('" + id + "', '" + key + "', '" + name + "')\" style=\"";
if (options.height) html += "height:" + options.height + "px";
html += "\">" + value + "</textarea></div>";
textareas_options.push({id: id, key: key, name: name, options: options});
Expand Down Expand Up @@ -504,6 +517,11 @@ var EDITOR = (function ($, parent) {
html += '</select>';
break;
case 'hotspot':
// this is a special one. the attributes in the node are called x, y, w, h
var id = 'button_' + form_id_offset;
form_id_offset++;
html = '<button id="' + id + '" onclick="hotspotEdit(\'' + id + '\', \'' + key + '\', \'' + name + '\')" >Edit ...</button>';
break;
case 'drawing':
case 'datefield':
case 'datagrid':
Expand All @@ -528,6 +546,7 @@ var EDITOR = (function ($, parent) {
my.convertTextAreas = convertTextAreas;
my.convertTextInputs = convertTextInputs;
my.convertColorPickers = convertColorPickers;
my.getIcon = getIcon;

return parent;

Expand Down
45 changes: 36 additions & 9 deletions editor/js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ var EDITOR = (function ($, parent) {

buttons = $('<div />').attr('id', 'top_buttons');
$([
{name:'Insert', icon:'editor/img/insert.png', id:'insert_button', click:insert_page},
{name:'Copy', icon:'editor/img/copy.png', id:'copy_button', click:duplicate_page},
{name:'Delete', icon:'editor/img/delete.gif', id:'delete_button', click:delete_page}
{name: language.btnInsert.$label, tooltip: language.btnInsert.$tooltip, icon:'editor/img/insert.png', id:'insert_button', click:insert_page},
{name: language.btnDuplicate.$label, tooltip: language.btnDuplicate.$tooltip, icon:'editor/img/copy.png', id:'copy_button', click:duplicate_page},
{name: language.btnDelete.$label, tooltip: language.btnDelete.$tooltip, icon:'editor/img/delete.gif', id:'delete_button', click:delete_page}
])
.each(function(index, value) {
var button = $('<button>')
.attr('id', value.id)
.attr('title', value.tooltip)
.click(value.click)
.append($('<img>').attr('src', value.icon).height(14))
.append(value.name);
Expand All @@ -48,12 +49,13 @@ var EDITOR = (function ($, parent) {

buttons = $('<div />').attr('id', 'save_buttons');
$([
{name:'Preview', icon:'editor/img/insert.png', id:'insert_button', click:preview},
{name:'Publish', icon:'editor/img/copy.png', id:'copy_button', click:publish},
{name:language.btnPreview.$label, tooltip: language.btnPreview.$tooltip, icon:'editor/img/insert.png', id:'preview_button', click:preview},
{name:language.btnPublishXot.$label, tooltip: language.btnPublishXot.$tooltip, icon:'editor/img/copy.png', id:'publish_button', click:publish},
])
.each(function(index, value) {
var button = $('<button>')
.attr('id', value.id)
.attr('title', value.tooltip)
.click(value.click)
.append($('<img>').attr('src', value.icon).height(14))
.append(value.name);
Expand Down Expand Up @@ -133,7 +135,7 @@ var EDITOR = (function ($, parent) {

// Get the node name
var node_name = '';

var node_label = '';
for (var i=0, len=attributes.length; i<len; i++)
{
if (attributes[i].name == 'nodeName')
Expand All @@ -144,7 +146,10 @@ var EDITOR = (function ($, parent) {
}

var node_options = wizard_data[node_name].node_options;

if (wizard_data[node_name].menu_options.label)
{
node_label = wizard_data[node_name].menu_options.label;
}
// Clear editor array
textareas_options = [];
textinputs_options = [];
Expand All @@ -156,6 +161,7 @@ var EDITOR = (function ($, parent) {
// Build the form
var attribute_name;
var attribute_value;
// Always display name option first
if (node_options['name'].length > 0)
{
attribute_name = node_options['name'][0].name;
Expand All @@ -165,6 +171,11 @@ var EDITOR = (function ($, parent) {
toolbox.displayParameter('#mainPanel', node_options['name'], attribute_name, attribute_value.value, key);
}
}
// If the main node has a label, display the node item second (unconditionaly)
if (node_label.length > 0)
{
toolbox.displayParameter('#mainPanel', node_options['normal'], node_name, '', key, node_label);
}
// Optional parameters
for (var i=0; i<node_options['optional'].length; i++)
{
Expand Down Expand Up @@ -255,16 +266,32 @@ var EDITOR = (function ($, parent) {
// Build the tree once the data has loaded
build = function (xml) {
var tree_json = toolbox.build_lo_data($($.parseXML(xml)).find("learningObject"), null);

// build Types structure for the types plugin
var node_types = {};
$.each(wizard_data, function (key, value) {
// Add a object to nod_types containg the icon, and the valid children
//var key = wizard_data['learningObject'].new_nodes[i];
var node_type = {
icon: parent.toolbox.getIcon(key),
valid_children: value.new_nodes
};
node_types[key] = node_type;
});

console.log(node_types);

//console.log(JSON.stringify(tree_json));
var treeview = $('<div />').attr('id', 'treeview');
$(".ui-layout-west .content").append(treeview);
$("#treeview").jstree({
/*"plugins" : [ "wholerow"],*/
"plugins" : [ "types", "dnd"],
"core" : {
"data" : tree_json,
"check_callback" : true, // Need this to allow the copy_node function to work...
"multiple" : false // Need to disable this just now as nodes could be on different levels
}
},
"types" : node_types
})
.one('ready.jstree', function (e, data) {
data.instance.open_node(["treeroot"]);
Expand Down
10 changes: 10 additions & 0 deletions library/Xerte/Authentication/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,23 @@ public function getSurname()
public function check()
{
global $xerte_toolkits_site;
_debug("Calling check");
// check for existence of the 'user' db table?
$x = db_query("SHOW CREATE TABLE {$xerte_toolkits_site->database_table_prefix}user");
if (empty($x)) {
// Create the user table
$x = db_query("create table {$xerte_toolkits_site->database_table_prefix}user ( `iduser` INT NOT NULL AUTO_INCREMENT, `username` VARCHAR(45) NULL , `password` VARCHAR(45) NULL , `firstname` VARCHAR(45) NULL , `surname` VARCHAR(45) NULL , `email` VARCHAR(45) NULL, PRIMARY KEY (`iduser`) )");
if (empty($x))
{
_debug("Failed: Does the user table exist?");
$this->addError("Does the user table exist?");
return false;
}
else
{
_debug("Succeeded!");
return true;
}
}
else
{
Expand All @@ -68,12 +73,17 @@ public function check()
if (empty($x))
{
$this->addError("Could not add email column to the user table.");
_debug("Failed: Could not add email column to the user table.");
return false;
}
else
{
_debug("Succeeded!");
return true;
}
}
}
_debug("Succeeded!");
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions modules/xerte/edithtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function output_editor_code($row_edit, $xerte_toolkits_site, $read_status, $vers

$xwd_url = "modules/" . $row_edit['template_framework'] . "/parent_templates/" . $row_edit['template_name'] . "/";

$module_url = "modules/" . $row_edit['template_framework'] . "/";

/**
* sort of the screen sies required for the preview window
*/
Expand Down Expand Up @@ -181,6 +183,7 @@ function output_editor_code($row_edit, $xerte_toolkits_site, $read_status, $vers
echo "languagecodevariable=\"" . $_SESSION['toolkits_language'] . "\";\n";
echo "editorlanguagefile=\"" . getWizardfile($_SESSION['toolkits_language']) . "\";\n";
echo "originalpathvariable=\"" . $xwd_url . "\";\n";
echo "moduleurlvariable=\"" . $module_url . "\";\n";
echo "template_id=\"" . $row_edit['template_id'] . "\";\n";
echo "template_height=\"" . $temp[1] . "\";\n";
echo "template_width=\"" . $temp[0] . "\";\n";
Expand Down

0 comments on commit 05ce84e

Please sign in to comment.