Joomla 2.5: mootools tree in content - how? - joomla

I have an article that has several large lists - and I would like to make them easier to navgiate by converting the -structure into a mootools-tree (following the example from http://mootree.mindplay.dk/example_1.html ).
So I have disabled any text-filtering (only for my admin user) and am using "no editor" to enable plain-text entry, have entered the following code, hoping it would combine mootools.tree-activation within Joomla and the example - but there's no tree being shown.
Any ideas?
<?php
JHTML::_( 'behavior.tree', 'mytree' );
?>
<script type="text/javascript">
var tree;
window.onload = function() {
// --- ordinary MooTreeControl example:
tree = new MooTreeControl({
div: 'mytree',
mode: 'files',
grid: true
},{
text: 'Root Node',
open: true
});
tree.disable(); // this stops visual updates while we're building the tree...
var node1 = tree.insert({text:'Subnode 1', id:'1'});
var node2 = tree.insert({text:'Subnode 2', id:'2', icon:'sample_icons.gif#1', openicon:'sample_icons.gif#2'});
var node3 = tree.insert({text:'Subnode 3', id:'3'});
var node2_1 = node2.insert({text:'Subnode 2.1', id:'2.1'});
var node2_2 = node2.insert({text:'Subnode 2.2', id:'2.2', color:'#ff0000'});
var node2_3 = node2.insert({text:'Subnode 2.3', id:'2.3'});
var node2_2_1 = node2_2.insert({text:'Subnode 2.2.1', id:'2.2.1', color:'#00a000'});
var node2_2_1_1 = node2_2_1.insert({text:'Subnode 2.2.1.1', id:'2.2.1.1', color:'#0000ff'});
var node4 = tree.insert({text:'Subnode 4', id:'4', icon:'sample_icons.gif#3'});
tree.expand();
tree.enable(); // this turns visual updates on again.
}
function find_node() {
var node = tree.get( $('nodeid_input').value );
window.alert( node ? 'found: ' + node.text : 'not found...' );
}
</script>
<h2>mooTree 2</h2>
<h4>example 1: basic tree example</h4>
<p>
This demonstrates most of the basic features of MooTree, including enable() and disable() which can be used
to minimize the number of visual updates performed.
</p>
<p>
This example also demonstrates basic usage of the get() method and node id's - for example, type "2.2" in the
text input at the bottom of this page, and press "find node".
</p>
<div id="mytree">
</div>
<p>
<input type="button" value=" expand all " onclick="tree.expand()" />
<input type="button" value=" collapse all " onclick="tree.collapse()" />
<input type="text" value="" id="nodeid_input" value="2.2" /><input type="submit" value="Find node" onclick="find_node()" />
</p>
The firebug-Console shows a lot of messages, but I don't see references to my code.
[13:59:10.896] GET http://localhost/index.php/2-uncategorised/3-mootree [HTTP/1.1 200 OK 1319ms]
[13:59:12.201] GET http://localhost/templates/system/css/system.css [HTTP/1.1 304 Not Modified 2ms]
[13:59:12.202] GET http://localhost/templates/beez_20/css/position.css [HTTP/1.1 304 Not Modified 2ms]
[13:59:12.203] GET http://localhost/templates/beez_20/css/layout.css [HTTP/1.1 304 Not Modified 5ms]
[13:59:12.203] GET http://localhost/templates/beez_20/css/print.css [HTTP/1.1 304 Not Modified 8ms]
[13:59:12.204] GET http://localhost/templates/beez_20/css/general.css [HTTP/1.1 304 Not Modified 8ms]
[13:59:12.205] GET http://localhost/templates/beez_20/css/general_mozilla.css [HTTP/1.1 304 Not Modified 9ms]
[13:59:12.205] GET http://localhost/templates/beez_20/css/personal.css [HTTP/1.1 304 Not Modified 6ms]
[13:59:12.206] GET http://localhost/media/system/js/mootools-core.js [HTTP/1.1 304 Not Modified 6ms]
[13:59:12.206] GET http://localhost/media/system/js/core.js [HTTP/1.1 304 Not Modified 7ms]
[13:59:12.207] GET http://localhost/media/system/js/caption.js [HTTP/1.1 304 Not Modified 10ms]
[13:59:12.208] GET http://localhost/media/system/js/mootools-more.js [HTTP/1.1 304 Not Modified 8ms]
[13:59:12.209] GET http://localhost/templates/beez_20/javascript/md_stylechanger.js [HTTP/1.1 304 Not Modified 8ms]
[13:59:12.210] GET http://localhost/templates/beez_20/javascript/hide.js [HTTP/1.1 304 Not Modified 9ms]
[13:59:12.183] Unbekannte Eigenschaft '-moz-border-radius'. Deklaration ignoriert. # http://localhost/templates/beez_20/css/general_mozilla.css:13
[13:59:12.390] GET http://localhost/media/system/css/system.css [HTTP/1.1 304 Not Modified 1ms]
[13:59:12.242] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-core.js:123
[13:59:12.246] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-core.js:338
[13:59:12.246] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-core.js:340
[13:59:12.248] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-core.js:382
[13:59:12.255] ReferenceError: reference to undefined property v[i] # http://localhost/media/system/js/mootools-core.js:42
[13:59:12.256] ReferenceError: reference to undefined property Element.prototype.fireEvent # http://localhost/media/system/js/mootools-core.js:260
[13:59:12.256] ReferenceError: reference to undefined property a[1] # http://localhost/media/system/js/mootools-core.js:272
[13:59:12.261] getAttributeNode() sollte nicht mehr verwendet werden. Verwenden Sie stattdessen getAttribute(). # http://localhost/media/system/js/mootools-core.js:343
[13:59:12.268] TypeError: variable a redeclares argument # http://localhost/media/system/js/core.js:9
[13:59:12.269] TypeError: function checkAll does not always return a value # http://localhost/media/system/js/core.js:12
[13:59:12.274] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:247
[13:59:12.275] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:254
[13:59:12.277] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:378
[13:59:12.277] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:385
[13:59:12.282] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:612
[13:59:12.282] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:625
[13:59:12.283] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:628
[13:59:12.283] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:635
[13:59:12.283] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:638
[13:59:12.283] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:650
[13:59:12.284] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:686
[13:59:12.284] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:694
[13:59:12.284] SyntaxError: property name getSelected appears more than once in object literal # http://localhost/media/system/js/mootools-more.js:695
[13:59:12.284] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:699
[13:59:12.284] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:700
[13:59:12.284] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:702
[13:59:12.284] SyntaxError: property name getSelected appears more than once in object literal # http://localhost/media/system/js/mootools-more.js:703
[13:59:12.284] TypeError: anonymous function does not always return a value # http://localhost/media/system/js/mootools-more.js:705
[13:59:12.289] ReferenceError: reference to undefined property this.Binds # http://localhost/media/system/js/mootools-more.js:27
[13:59:12.291] ReferenceError: reference to undefined property this.document # http://localhost/media/system/js/mootools-core.js:192
[13:59:12.291] ReferenceError: reference to undefined property this.document # http://localhost/media/system/js/mootools-core.js:170
[13:59:12.293] ReferenceError: reference to undefined property this.parsed # http://localhost/media/system/js/mootools-more.js:129
[13:59:12.528] GET http://localhost/templates/beez_20/images/personal/bg2.png [HTTP/1.1 304 Not Modified 3ms]
[13:59:12.528] GET http://localhost/images/joomla_black.gif [HTTP/1.1 304 Not Modified 2ms]
[13:59:12.529] GET http://localhost/templates/beez_20/images/system/arrow.png [HTTP/1.1 304 Not Modified 1ms]
[13:59:12.530] GET http://localhost/media/system/images/printButton.png [HTTP/1.1 304 Not Modified 1ms]
[13:59:12.530] GET http://localhost/media/system/images/emailButton.png [HTTP/1.1 304 Not Modified 1ms]
[13:59:12.531] GET http://localhost/templates/beez_20/images/personal/personal2.png [HTTP/1.1 304 Not Modified 2ms]
[13:59:12.531] GET http://localhost/templates/beez_20/images/nature/karo.gif [HTTP/1.1 304 Not Modified 2ms]
[13:59:12.532] GET http://localhost/templates/beez_20/images/content_bg.gif [HTTP/1.1 304 Not Modified 1ms]
[13:59:12.532] GET http://localhost/templates/beez_20/images/nature/arrow1.gif [HTTP/1.1 304 Not Modified 2ms]
[13:59:12.533] GET http://localhost/templates/beez_20/images/personal/tabs_back.png [HTTP/1.1 304 Not Modified 2ms]
[13:59:12.481] ReferenceError: assignment to undeclared variable STATE_PROVINCE_VALUE_MAPPING # resource://gre/modules/XPIProvider.jsm -> jar:file:///C:/Users/MBaas/AppData/Roaming/Mozilla/Firefox/Profiles/b4ue9vdm.default/extensions/onepassword#agilebits.com.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/loader/sandbox.js -> resource://onepassword-at-agilebits-dot-com/onepassword/data/src/end.min.js:32
[13:59:12.481] ReferenceError: assignment to undeclared variable STATE_PROVINCE_REGEX_MAPPING # resource://gre/modules/XPIProvider.jsm -> jar:file:///C:/Users/MBaas/AppData/Roaming/Mozilla/Firefox/Profiles/b4ue9vdm.default/extensions/onepassword#agilebits.com.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/loader/sandbox.js -> resource://onepassword-at-agilebits-dot-com/onepassword/data/src/end.min.js:32
[13:59:12.481] ReferenceError: assignment to undeclared variable COUNTRY_VALUE_MAPPING # resource://gre/modules/XPIProvider.jsm -> jar:file:///C:/Users/MBaas/AppData/Roaming/Mozilla/Firefox/Profiles/b4ue9vdm.default/extensions/onepassword#agilebits.com.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/loader/sandbox.js -> resource://onepassword-at-agilebits-dot-com/onepassword/data/src/end.min.js:32
[13:59:12.485] ReferenceError: MooTreeControl is not defined # http://localhost/index.php/2-uncategorised/3-mootree:220
The whole thing is running on localhost currently, so I can't provide a Live-URL, sorry.

Ok, I finally solved it by using the mooTree-List plugin from http://extensions.joomla.org/extensions/style-a-design/typography/… thanks for helping!

Related

The "error_marshaling_enabled" setting seems to be always enabled

When I run this code:
$client->evaluate('
box.session.settings.error_marshaling_enabled = false
box.error{code = 42, reason = "Foobar", type = "MyError"}
');
regardless of the value of error_marshaling_enabled I always get a response with a new (extended) error format:
[
49 => 'Foobar',
82 => [
0 => [
0 => [
0 => 'CustomError',
2 => 3,
1 => 'eval',
3 => 'Foobar',
4 => 0,
5 => 42,
6 => [
'custom_type' => 'MyError',
],
],
],
],
],
Why is that?
Short answer.
error_marshaling_enabled option affects only how error objects are encoded in response body (48, IPROTO_DATA). It does not affect how they are returned as exceptions, in the response header (82, IPROTO_ERROR).
Long answer.
In Tarantool an error object can be returned in 2 ways: as an exception and as an object. For example, this is how to throw an error as exception:
function throw_error()
box.error({code = 1000, reason = "Error message"})
-- Or
error('Some error string')
end
This is how to return it as an object:
function return_error()
return box.error.new({code = 1000, reason = "Error message"})
end
If the function was called remotely, using IPROTO protocol via a connector like netbox, or PHP connector, or any other one, the error return way affects how it is encoded into MessagePack response packet. When the function throws, and the error reaches the top stack frame without being caught, it is encoded as IPROTO_ERROR (82) and IPROTO_ERROR_24 (49).
When the error object is returned as a regular value, not as an exception, it is encoded also as a regular value, inside IPROTO_DATA (48). Just like a string, a number, a tuple, etc.
With encoding as IPROTO_ERROR/IPROTO_ERROR_24 there is no much of a configuration space. Format of these values can't be changed. IPROTO_ERROR is always returned as a MessagePack map, with a stack of errors in it. IPROTO_ERROR_24 is always an error message. The IPROTO_ERROR_24 field is kept for compatibility with connectors to Tarantool versions < 2.4.1.
With encoding as a part of IPROTO_DATA you can choose serialization way using error_marshaling_enabled option. When it is true, errors are encoded as MessagePack extension type MP_EXT, and contain the whole error stack, encoded exactly like IPROTO_ERROR value. When the option is false (default behaviour in 2.4.1), the error is encoded as a string, MP_STR, which is the error's message. If there is a stack of errors, only the newest error is encoded.
error_marshaling_enabled option exists for backward compatibility, in case your application on Tarantool wants to be compatible with old connectors, which don't support MP_EXT encoded errors.
In Tarantool < 2.4.1 errors were encoded into result MessagePack as a string with error message, and error stacks didn't exist at all. So when the new format and the error stacks feature were introduced, making the new format default would be a too radical change breaking the old connectors.
Consider these examples of how error marshaling affects results. I use Tarantool 2.4.1 console here, and built-in netbox connector. The code below can be copy pasted into the console.
First instance:
box.cfg{listen = 3313}
box.schema.user.grant('guest', 'super')
function throw_error()
box.error({code = 1000, reason = "Error message"})
end
function return_error()
return box.error.new({code = 1000, reason = "Error message"})
end
Second instance:
netbox = require('net.box')
c = netbox.connect(3313)
Now I try to call the function on the second instance:
tarantool> c:call('throw_error')
---
- error: Error message
...
The c:call('throw_error') threw an exception. If I catch it using pcall() Lua function, I will see the error object.
tarantool> ok, err = pcall(c.call, c, 'throw_error')
tarantool> err:unpack()
---
- code: 1000
base_type: ClientError
type: ClientError
message: Error message
trace:
- file: '[string "function throw_error()..."]'
line: 2
...
As you can see, I didn't set error_marshaling_enabled, but got the full error. Now I will call the other function, without exceptions. But the error object won't be full.
tarantool> err = c:call('return_error')
tarantool> err
---
- Error message
...
tarantool> err:unpack()
---
- error: '[string "return err:unpack()"]:1: attempt to call method ''unpack'' (a nil
value)'
...
The error was returned as a mere string, error message. Not as an error object. Now I will turn on the marshaling:
tarantool> c:eval('box.session.settings.error_marshaling_enabled = true')
---
...
tarantool> err = c:call('return_error')
---
...
tarantool> err:unpack()
---
- code: 1000
base_type: ClientError
type: ClientError
message: Error message
trace:
- file: '[C]'
line: 4294967295
...
Now the same function returned the error in the new format, more featured.
On the summary: error_marshaling_enabled affects only returned errors. Not thrown errors.

making VueJS expressions debug-able

My vue js data has some arrays, and in the template I am trying to render them using v-for loops.
something like:
<tr v-for="d in [0,1,2,3]"><td>{{data.people[d].name}}</td></tr>
<tr v-for="d in [0,1,2,3]"><td>{{data.places[d].name}}</td></tr>
<tr v-for="d in [0,1,2,3]"><td>{{data.orders[d].id}}</td></tr>
<tr v-for="d in [0,1,2,3]"><td>{{data.other_array[d].id}}</td></tr>
<tr v-for="d in [0,1,2,3]"><td>{{data.more_array[d].som_property}}</td></tr>
and I am getting an error that looks like this:
TypeError: Cannot read property '0' of undefined
at eval (eval at createFunction (vue.js:10518), <anonymous>:2:3084)
at Proxy.renderList (vue.js:3666)
at Proxy.eval (eval at createFunction (vue.js:10518), <anonymous>:2:2915)
at Vue$3.Vue._render (vue.js:4465)
at Vue$3.updateComponent (vue.js:2765)
at Watcher.get (vue.js:3113)
at new Watcher (vue.js:3102)
at mountComponent (vue.js:2772)
at Vue$3.$mount (vue.js:8416)
at Vue$3.$mount (vue.js:10777)
logError # vue.js:1719
globalHandleError # vue.js:1710
handleError # vue.js:1699
Vue._render # vue.js:4467
updateComponent # vue.js:2765
get # vue.js:3113
Watcher # vue.js:3102
mountComponent # vue.js:2772
Vue$3.$mount # vue.js:8416
Vue$3.$mount # vue.js:10777
Vue._init # vue.js:4557
Vue$3 # vue.js:4646
(anonymous) # astromap.html:291
I do understand that it means that somewhere one of my arrays is not initialized, and I will find that array, I also know I can write using guards and use v-if .
What bothers me is that The above stack trace seems quite useless.
my Q is:
Is there a better way to write such templates, not to prevent them from failing, but so that when they do fail I will get a more indicative output?
Alternatively, Is there any other debugging magic (e.g. some lastParsedExpression secret variable) that I can use in the debug console that can tell me what was the expression that failed?
UPDATE: edited to emphasis that there are multiple places where the error could happen.
I think what you are looking for is ErrorBoundary.
Vue.component('ErrorBoundary', {
data: () => ({ error: null }),
errorCaptured (err, vm, info) {
this.error = `${err.stack}\n\nfound in ${info} of component`
return false
},
render (h) {
if (this.error) {
return h('pre', { style: { color: 'red' }}, this.error)
}
// ignoring edge cases for the sake of demonstration
return this.$slots.default[0]
}
})
<error-boundary>
<another-component/>
</error-boundary>
The first item in your v-for array is 0. The error states:
Cannot read property '0' of undefined
You're attempting to access property 0 on people
people[d].name
Where do you have people defined?
The error is telling you an object is not defined, not an array.

array containing an object without using a data structure

I'm currently using the following. It works, but I'd like to bake it into one data structure. This means moving the status and title into the array somehow. Is this possible?
## Invalid Credentials Object (object)
+ status: 401 (number)
+ title: `Invalid Credentials`
## Invalid Credentials (object)
+ errors (array[Invalid Credentials Object])
I'd like it to somehow resemble:
## Invalid Credentials (object)
+ errors (array[
+ status: 401 (number)
+ title: `Invalid Credentials`
])
Could you not do something like;
# Invalid Credentials (object)
+ errors (array[
#error
+ status: 401 (number)
+ message: 'Invalid Credentials'
])
Of course that's assuming you can next objects within an array.

why is my plivo api call returning an error?

I am using the plivo search number api to list telephone numbers by selected parameters.
The ruby code is:
get '/search_numbers' do
p = RestAPI.new(AUTH_ID, AUTH_TOKEN)
params = {'country_iso' => 'GB'}
response = p.search_phone_number(params)
end
and the error I receive is:
88.106.106.78 - - [22/Jan/2015:15:02:59 +0000] "GET /search_numbers HTTP/1.0" 200 - 1.7485
2015-01-22 15:02:59 +0000: Read error: #<NoMethodError: undefined method `bytesize' for ["api_id", "c025f0cc-a247-11e4-b153-22000abcaa64"]:Array>
I simply cannot figure out what is wrong. I can see no typos, the parameter that is passed is correct and in the correct format and the function is the right function to use.
Help, please!

jQuery.ajax() reports invalid json - Firebug parses it fine

I have jQuery.ajax() creating a request to a url (cms2/docman/dir/%id) (%id is a numeric unsigned integer). The page requested runs some functions and outputs an array. This array is then run through drupal_json. drupal_json() echo's out the content first setting the header to
Content-Type: text/javascript; charset=utf-8
So far, everything seems to be going well. The functions are all running and the JSON is being outputted as expected. Through firebug it shows that the response received is JSON and offers the "JSON" tab to preview it.
However, jQuerys jQuery.ajax() function says that a parser error occurred and that it returned "invalid" json. I copied out the json returned and tossed it into an editor (Eclipse PDT) but it shows that there are no errors.
I'm completely stumped at this point. The only thing I can think of is if there is some kind of limit on the amount of text returned via this method.
Creates the request:
function request(url) {
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
async: false,
success: function(data) {
if(data.status) {
docman.store = data.info;
}
else {
docman.hideMessages();
docman.error(data.message);
}
},
error: function(data,ts,et) {
docman.hideMessages();
docman.error(data);
docman.store = data.responseText;
}
});
}
JSON output here - http://codetidy.com/102
You can use http://www.jsonlint.com/ to check your JSON. You'll find it tells you that line 136 contains an invalid code:
syntax error, unexpected TINVALID at
line 136 Parsing failed
You need to double escape the character code. (Two backslashes).
you have to do something like this
diff --git a/includes/common.inc b/includes/common.inc
index b86f2d2..ff246a3 100644
--- a/includes/common.inc
+++ b/includes/common.inc
## -2539,8 +2539,8 ## function drupal_to_js($var) {
case 'resource':
case 'string':
return '"'. str_replace(array("\r", "\n", "<", ">", "&"),
- array('\r', '\n', '\x3c', '\x3e', '\x26'),
- addslashes($var)) .'"';
+ array('\r', '\n', '\u003c', '\u003e', '\u0026'),
+ str_replace("\'","'", addslashes($var))) .'"';
case 'array':
// Arrays in JSON can't be associative. If the array is empty or if it
// has sequential whole number keys starting with 0, it's not associative

Resources