r24958: This is the final text, and the final version. I'll send the release
[jelmer/samba4-debian.git] / webapps / swat / source / class / swat / module / ldbbrowse / LdifViewer.js
1 /*                                                                                                                    
2  * Copyright::                                                                                                         
3  *   (C) 2006 by Simo Sorce
4  * 
5  * License: 
6  *   GPL v2 or later
7  */
8
9 /**
10  * Ldif Viewer Class
11  */
12 qx.OO.defineClass("swat.module.ldbbrowse.LdifViewer", qx.ui.embed.HtmlEmbed,
13 function()
14 {
15   qx.ui.embed.HtmlEmbed.call(this, "");
16
17   this.setStyleProperty("whiteSpace", "nowrap");
18   this.setStyleProperty("textOverflow", "ellipsis");
19
20   this.setOverflow("auto");
21   this.setSelectable(true);
22
23   this.innerText = "";
24 });
25
26 qx.OO.addProperty({ name : "innerText", type : "string" });
27
28 qx.Proto._update = function() {
29   this.setHtml("<pre>" + this.innerText + "</pre>");
30 }
31
32 /**
33  * Reset the ldif contents and return to an empty page
34  */
35 qx.Proto.reset = function() {
36   this.innerText = "";
37   this.setHtml("");
38 }
39
40 /**
41  * Add a comment to the ldif output
42  *
43  * @param aText {String}
44  *   A string to show up as an ldif Comment
45  */
46 qx.Proto.appendComment = function(aText) {
47   this.innerText = this.innerText + "# " + a Text + "\n\n";
48   this._update();
49 }
50
51 /**
52  * Append an object to be shown
53  *
54  * @param o {Object}
55  *   An Object returned by an ldb search
56  */
57 qx.Proto.appendObject = function(o) {
58
59   // First print the Object name as comment
60   // TODO: Prettify it later
61   var ldifRecord = "# " + o["dn"] + "\n";
62
63   // Now the dn
64   ldifRecord = ldifRecord + "dn: " + o["dn"] + "\n";
65
66   // Now the attributes;
67   for (var field in o)
68   {
69
70     // If it's multi-valued (type is an array)...
71     if (typeof(o[field]) == "object")
72     {
73       // ... then add each value with same name
74       var a = o[field];
75       for (var i = 0; i < a.length; i++)
76       {
77         ldifRecord = ldifRecord + field + ": " + a[i] + "\n";
78       }
79     }
80     else    // single-valued
81     {
82       ldifRecord = ldifRecord + field + ": " + o[field] + "\n";
83     }
84   }
85
86   // Terminate the record with an empty line
87   ldifRecord = ldifRecord + "\n";
88
89   this.innerText = this.innerText + ldifRecord;
90   this._update();
91 }