Ticket #67 (closed defect: fixed)
Patch: Linker-Plugin - labels for files
| Reported by: | Niko <ns@…> | Owned by: | gogo |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Xinha Core | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Patch: labels for files
If you have a dynamic website links may look like this: http://www.example.com/news.php?id=34.
When using the Linker-Plugin you can write our own backend file to get all news-links out of a database (or you use #66), but you can't give these links a title, they stay as news.php?id=34 in the tree.
With this patch it is possible to give everay link a specific caption - so the links to the news can have a nice caption (fetched from the database too of course).
Usage-Example, scan.php should return an object like this:
//old syntax (still works)
['/info.php', [ [ '/news', [ '/news.php?id=33', '/news.php?id=34' ] ] ] ];
//new syntax
lDialog.files = {'/info.php': 'Info', 0:[ 'News', { '/news.php?id=33': 'News Number 33', '/news.php?id=34': 'News with the ID 34' } ] };
//new syntax, where you can select the folder "News" too
lDialog.files = {'/info.php': 'Info', 'newslist.php':[ 'News', { '/news.php?id=33': 'News Number 33', '/news.php?id=34': 'News with the ID 34' } ] };
(I don't understand why i need this 'lDialog.files = ', it won't work without it)
Please review this patch carefully... i'm not a good JavaScript?-coder :D
--- linker.js (Revision 38)
+++ linker.js (Arbeitskopie)
@@ -362,20 +368,42 @@
Linker.Dialog.prototype.makeNodes = function(files, parent)
{
- for(var i = 0; i < files.length; i++)
+ //convert array to a object (key and val are the same then)
+ if(files.length)
{
- if(typeof files[i] == 'string')
+ var files2 = new Object();
+ for(var i = 0; i < files.length; i++) {
+ if(typeof files[i] == 'string') {
+ files2[files[i]] = files[i];
+ } else {
+ files2[i] = files[i];
+ }
+ }
+ }
+ else
+ {
+ var files2 = files;
+ }
+
+ for(var i in files2)
+ {
+ if(typeof files2[i] == 'string')
{
this.dTree.add(Linker.nxtid++, parent,
- files[i].replace(/^.*\//, ''),
- 'javascript:document.getElementsByName(\'' + this.dialog.id.href + '\')[0].value=unescape(\'' + escape(files[i]) + '\');document.getElementsByName(\'' + this.dialog.id.type + '\')[0].click();document.getElementsByName(\'' + this.dialog.id.href + '\')[0].focus();void(0);',
- files[i]);
+ files2[i].replace(/^.*\//, ''),
+ 'javascript:document.getElementsByName(\'' + this.dialog.id.href + '\')[0].value=unescape(\'' + escape(i) + '\');document.getElementsByName(\'' + this.dialog.id.type + '\')[0].click();document.getElementsByName(\'' + this.dialog.id.href + '\')[0].focus();void(0);',
+ files2[i]);
}
else
{
+ if(i=="0" || i+0 > 0) {
+ var target = null;
+ } else {
+ var target = 'javascript:document.getElementsByName(\'' + this.dialog.id.href + '\')[0].value=unescape(\'' + escape(i) + '\');document.getElementsByName(\'' + this.dialog.id.type + '\')[0].click();document.getElementsByName(\'' + this.dialog.id.href + '\')[0].focus();void(0);';
+ }
var id = this.Dialog_nxtid++;
- this.dTree.add(id, parent, files[i][0].replace(/^.*\//, ''), null, files[i][0]);
- this.makeNodes(files[i][1], id);
+ this.dTree.add(id, parent, files2[i][0].replace(/^.*\//, ''), target, files2[i][0]);
+ this.makeNodes(files2[i][1], id);
}
}
}
