18 require_once SQ_CORE_PACKAGE_PATH.
'/content_type/content_type_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.
'/var_serialise/var_serialise.inc';
42 parent::__construct();
58 if ($asset->writeAccess(
'attributes')) {
59 hidden_field($prefix.
'_structure_value',
'bla');
61 $pre_serialised = $asset->attr(
'structure');
62 foreach ($asset->attr(
'structure') as $index => $row) {
63 $pre_serialised[$index][
'content'] = str_replace(
"'",
"\'", $row[
'content']);
65 $serialised = var_serialise($pre_serialised);
66 $serialised =
'var init_data = \''.$serialised;
67 $serialised = str_replace(
"\n",
"\\n'; init_data += '", $serialised);
68 $serialised = substr($serialised, 0, strrpos($serialised,
';') + 1).
"\n\n";
69 $format_options = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($asset->type(),
'SQ_STRUCTURE_TREE_FORMATTING');
71 <style type=
"text/css">
75 border: 1px solid grey;
82 <script type=
"text/javascript" src=
"<?php echo sq_web_path('fudge'); ?>/var_serialise/var_serialise.js"></script>
83 <script type=
"text/javascript" src=
"<?php echo sq_web_path('lib'); ?>/js/general.js"></script>
84 <script type=
"text/javascript">
86 var data_path =
"<?php echo sq_web_path('data').'/asset_types/'.$asset->type(); ?>/files/";
102 this.elt =
'<?php echo $prefix; ?>_cont';
104 this.getValue =
function()
106 return var_serialise(this.rows);
109 this.init =
function()
112 <?php echo $serialised; ?>
113 var un_serialised = var_unserialise(init_data);
115 for (var i = 0; i < un_serialised.length; i++) {
117 a.indent = un_serialised[i][
'indent'];
118 a.content = un_serialised[i][
'content'];
119 a.bold = un_serialised[i][
'bold'];
120 a.italic = un_serialised[i][
'italic'];
121 a.underline = un_serialised[i][
'underline'];
127 this.draw =
function()
129 var elt = document.getElementById(this.elt);
131 src +=
'<table style="width: 600px;" cellspacing="1" cellpadding="1">';
133 for (var i in this.rows) {
134 var indent = this.rows[i].indent * 20;
136 src +=
'<td style="border-right: 1px dotted #999999; border-bottom: 1px dotted #999999; width: 50px;">';
137 src +=
'<TABLE cellSpacing=0 cellPadding=0 border=0>';
140 src +=
'<TD rowSpan=2><IMG alt=lef src="'+data_path+
'arrow_left_blue.png" border=0 onclick="<?php echo $prefix; ?>_structure.moveLeft(' + i +
');" title="Decrease Row Indent" /></TD>';
141 src +=
'<TD ><IMG alt=up src="'+data_path+
'arrow_up_blue.png" border=0 onclick="<?php echo $prefix; ?>_structure.moveUp(' + i +
');" title="Move Row Up Tree" /></TD>';
142 src +=
'<TD rowSpan=2><IMG alt=right src="'+data_path+
'arrow_right_blue.png" border=0 onclick="<?php echo $prefix; ?>_structure.moveRight(' + i +
');" title="Increase Row Indent" /></TD></TR>';
144 src +=
'<TD><IMG style="margin-top: 2px;" alt=down src="'+data_path+
'arrow_down_blue.png" border=0 onclick="<?php echo $prefix; ?>_structure.moveDown(' + i +
');" title="Move Row Down Tree" ></TD></TR></TBODY></TABLE>';
145 src +=
'</td><td style="border-bottom: 1px dotted #999999;">';
146 var inline_style =
'style="';
147 if (this.rows[i].italic ==
'1') inline_style +=
'font-style: italic;';
148 if (this.rows[i].bold ==
'1') inline_style +=
'font-weight: bold;';
149 if (this.rows[i].underline ==
'1') inline_style +=
'text-decoration: underline;';
151 src +=
'<span style="margin-left: ' + indent +
'px; ">';
152 src +=
'<input class="structure" type="text" value="' + htmlspecialchars(this.rows[i].content) +
'" ';
154 src +=
' onBlur="<?php echo $prefix; ?>_structure.updateText(' + i +
', this);" />';
155 src +=
'</span></td><td style="margin-right: 0px; width: 55px; border-left: 1px dotted #999999;border-bottom: 1px dotted #999999;">';
156 var style_base =
' style="border: 1px solid ';
159 if ($format_options[
'bold']) {
161 var style_colour =
'white';
162 src +=
'<img src="'+data_path+
'text_bold.png" onclick="<?php echo $prefix; ?>_structure.makeBold(' + i +
');" title="Bold Text" ';
163 if (this.rows[i].bold ==
'1') style_colour =
'red';
164 src += style_base + style_colour +
';" />';
167 if ($format_options[
'underline']) {
169 style_colour =
'white';
170 src +=
'<img src="'+data_path+
'text_underlined.png" onclick="<?php echo $prefix; ?>_structure.underline(' + i +
');" title="Underline Row Text" ';
171 if (this.rows[i].underline ==
'1') style_colour =
'red';
172 src += style_base + style_colour +
';" />';
175 if ($format_options[
'italic']) {
177 style_colour =
'white';
178 src +=
'<img src="'+data_path+
'text_italics.png" onclick="<?php echo $prefix; ?>_structure.italicize(' + i +
');" title="Italicise Row Text" ';
179 if (this.rows[i].italic ==
'1') style_colour =
'red';
180 src += style_base + style_colour +
';" />';
186 if ($format_options[
'delete']) {
188 src +=
'<td style="border-left: 1px dotted #999999;border-bottom: 1px dotted #999999; margin-right: 0px; width: 18px;"><img src="<?php echo sq_web_path('data
'); ?>/asset_types/bodycopy/images/icons/delete.png" onclick="<?php echo $prefix; ?>_structure.remove(' + i +
');" title="Delete This Row"/></td>';
195 if ($format_options[
'insert']) {
197 src +=
'<tr><td colspan="3" style=""><img src="'+data_path+
'add.png" onclick="<?php echo $prefix; ?>_structure.addRow();" title="Add New Row" /> Add New Row: <input id="<?php echo $prefix; ?>_new_row_text" style="margin-left: 5px;" class="structure" type="text">';
207 this.moveLeft =
function(index)
209 if (this.rows[index].indent > 0) {
210 this.rows[index].indent--;
215 this.moveRight =
function(index)
218 if (this.rows[index].indent <= this.rows[index - 1].indent) {
219 this.rows[index].indent++;
225 this.moveUp =
function(index)
228 var dummy = this.rows[index - 1];
229 this.rows[index - 1] = this.rows[index];
230 this.rows[index] = dummy;
235 this.moveDown =
function(index)
237 if (index != this.rows.length - 1) {
238 var dummy = this.rows[index + 1];
239 this.rows[index + 1] = this.rows[index];
240 this.rows[index] = dummy;
245 this.
remove =
function(index)
247 this.rows.splice(index, 1);
251 this.makeBold =
function(index)
253 if (this.rows[index].bold ==
'1') {
254 this.rows[index].bold =
'0';
256 this.rows[index].bold =
'1';
261 this.underline =
function(index)
263 if (this.rows[index].underline ==
'1') {
264 this.rows[index].underline =
'0';
266 this.rows[index].underline =
'1';
271 this.italicize =
function(index)
273 if (this.rows[index].italic ==
'1') {
274 this.rows[index].italic =
'0';
276 this.rows[index].italic =
'1';
281 this.updateText =
function(index, elt)
283 this.rows[index].content = elt.value;
287 this.addRow =
function()
289 var new_row =
new row();
290 var new_doc_text = document.getElementById(
'<?php echo $prefix; ?>_new_row_text');
291 if (new_doc_text.value ==
'') {
292 new_row.content =
'New Row';
294 new_row.content = new_doc_text.value;
296 new_doc_text.value =
'';
297 var index = this.rows.length - 1;
300 indent = this.rows[index].indent;
302 new_row.indent = indent;
303 this.rows.push(new_row);
307 this.addSpacer =
function()
309 var new_row =
new row();
311 new_row.content =
'.<br />.<br />.<br />';
312 new_row.spacer =
true;
313 var index = this.rows.length - 1;
316 indent = this.rows[index].indent;
318 new_row.indent = indent;
319 this.rows.push(new_row);
323 this.update =
function()
326 for (var i = 0; i < this.rows.length; i++) {
328 if (i == 0 && this.rows[i].indent != 0) {
329 this.rows[i].indent = 0;
331 if (i > 0 && this.rows[i].indent > this.rows[i - 1].indent + 1) {
332 this.rows[i].indent = this.rows[i - 1].indent + 1;
335 document.getElementById(
'<?php echo $prefix; ?>_structure_value').value = this.getValue();
341 var <?php echo $prefix; ?>_structure =
new structure();
345 <div
id=
"<?php echo $prefix; ?>_cont" style=
"width: 100%;"><br /></div>
346 <script type=
"text/javascript">
347 <?php echo $prefix; ?>_structure.init();
350 if ($format_options[
'connections']) {
351 check_box($prefix.
'_show_trailers',
'1', $asset->attr(
'trailers'));
352 label(
'Show Connections between non-adjacent nodes on the frontend', $prefix.
'_show_trailers');
372 if ($asset->writeAccess(
'attributes')) {
373 $serialised = array_get_index($_POST, $prefix.
'_structure_value',
'');
374 $full_data = var_unserialise($serialised);
375 $asset->setAttrValue(
'structure', $full_data);
376 $trailers = isset($_POST[$prefix.
'_show_trailers']) ? TRUE : FALSE;
377 $asset->setAttrValue(
'trailers', $trailers);
379 $asset->setAttrValue(
'html', $asset->drawTree($trailers));