/*
 * This file is part of TbSync.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 
 */
 
 "use strict";

Components.utils.import("chrome://tbsync/content/tbsync.jsm");

var tbSyncErrorLog = {
    
    onload: function () {
        let errorlog = document.getElementById('tbsync.errorlog');
        errorlog.hidden = true;
        
        //init list
        for (let i=0; i < tbSync.errors.length; i++) {
            let item = tbSyncErrorLog.addLogEntry(tbSync.errors[i]);
            errorlog.appendChild(item);
        }

        errorlog.hidden = false;
    },

    
    addLogEntry: function (entry) {
        
        //left column
        let leftColumn = document.createElement("vbox");

        let image = document.createElement("image");
        image.setAttribute("src", "chrome://tbsync/skin/" + "warning16.png");
        image.setAttribute("style", "margin:2px 4px 4px 4px;");
        leftColumn.appendChild(image);
        
        //right column        
        let rightColumn = document.createElement("vbox");
        rightColumn.setAttribute("flex","1");

        let d = new Date(entry.timestamp);
        let timestamp = document.createElement("description");
        timestamp.setAttribute("flex", "1");
        timestamp.setAttribute("class", "header");
        timestamp.textContent = d.toLocaleTimeString();
        rightColumn.appendChild(timestamp);

            let hBox = document.createElement("hbox");
            let vBoxLeft = document.createElement("vbox");
            let vBoxSpacer = document.createElement("vbox");
            let vBoxRight = document.createElement("vbox");
            vBoxSpacer.flex = "1";
            hBox.appendChild(vBoxLeft);
            hBox.appendChild(vBoxSpacer);
            hBox.appendChild(vBoxRight);
            rightColumn.appendChild(hBox);
            
            let msg = document.createElement("description");
            msg.setAttribute("flex", "1");
            msg.setAttribute("class", "header");
            msg.textContent = entry.message;
            vBoxLeft.appendChild(msg);

            if (entry.link) {
                let link = document.createElement("button");
                link.setAttribute("label",  tbSync.getLocalizedMessage("manager.help"));
                link.setAttribute("oncommand",  "tbSync.openLink('" + entry.link + "')");
                vBoxRight.appendChild(link);
            }

        if (entry.accountname) {
            let account = document.createElement("label");
            account.setAttribute("value",  "Account: " + entry.accountname);
            rightColumn.appendChild(account);
        }

        if (entry.foldername) {
            let folder = document.createElement("label");
            folder.setAttribute("value",  "Resource: " + entry.foldername);
            rightColumn.appendChild(folder);
        }

        if (entry.details) {
            let lines = entry.details.split("\n");
            let line = document.createElement("textbox");
            line.setAttribute("readonly", "true");                
            line.setAttribute("multiline", "true");                
            line.setAttribute("rows", lines.length);                
            line.setAttribute("style", "font-family: monospace; font-size: 10px; overflow: auto;");                
            line.setAttribute("class", "plain");                
            line.setAttribute("value", entry.details.trim());
            
            let container = document.createElement("vbox");
            container.setAttribute("style", "margin-left:1ex;margin-top:1ex;");                
            container.appendChild(line);
            
            rightColumn.appendChild(container);
        }
        
        //columns
        let columns = document.createElement("hbox");
        columns.setAttribute("flex", "1");
        columns.appendChild(leftColumn);
        columns.appendChild(rightColumn);
        
        //richlistitem
        let richlistitem = document.createElement("richlistitem");
        richlistitem.setAttribute("style", "padding:4px; border-bottom: 1px solid lightgrey;");
        richlistitem.appendChild(columns);
        
        return richlistitem;
    },    
};

@@ -1601,114 +1601,23 @@
     
-let vBoxLeft = document.createElement(%22vbox%22);%0A            let vBoxSpacer = document.createElement(%22vbox%22)
+hBox.flex = %221%22
 ;%0A  
@@ -1634,20 +1634,19 @@
 let vBox
-Righ
+Lef
 t = docu
@@ -1689,22 +1689,20 @@
     vBox
-Spacer
+Left
 .flex = 
@@ -1722,159 +1722,53 @@
     
-hBox.appendChild(vBoxLeft);%0A            hBox.appendChild(vBoxSpacer);%0A            hBox.appendChild(vBoxRight);%0A            rightColumn.appendChild(hB
+let vBoxRight = document.createElement(%22vb
 ox
+%22
 );%0A 
@@ -2339,32 +2339,162 @@
 %0A            %7D%0A%0A
+            hBox.appendChild(vBoxLeft);%0A            hBox.appendChild(vBoxRight);%0A            rightColumn.appendChild(hBox);%0A%09    %0A
         if (entr

fix description size in error log (parent vbox needs flex=1)