Changeset 44a21d


Ignore:
Timestamp:
Jan 13, 2009, 1:02:23 AM (13 years ago)
Author:
rene <rene@…>
Branches:
lite_0.1, multiEdit, ng_0.6, ng_0.6_help, ng_0.8, ng_0.9
Children:
3a0314
Parents:
603625
Message:

tabbed rdf Data Editor (not completely working)

Location:
chrome/content/v_identity
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • chrome/content/v_identity/vI_rdfDataTree.js

    r603625 r44a21d  
    2929*/
    3030
    31 var vI_rdfDataTree = {
    32     __idTable : null,
    33     __idData : null,
    34     __treeElem : null,
    35     filterText : "",
    36    
    37     __strings : null,
    38 
    39     promptService : Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
    40             .getService(Components.interfaces.nsIPromptService),
    41 
    42     init : function() {
    43         vI_rdfDatasource.init();
    44         vI_rdfDataTree.__treeElem = document.getElementById("threadTree");
    45         vI_rdfDataTree.__strings = document.getElementById("vI_rdfDataTreeBundle");
    46         vI_storageExtrasHelper.hideUnusedTreeCols();
    47         vI_rdfDataTree.loadTable();
    48     },
    49 
    50     //prepares an object for easy comparison against another. for strings, lowercases them
    51     __prepareForComparison : function(o) {
    52         if (typeof o == "string") { return o.toLowerCase().replace(/\"/g,""); }
    53         return "";
    54     },
    55    
    56     __addNewDatum : function(resource, type, name, localIdentityData) {
     31
     32//prepares an object for easy comparison against another. for strings, lowercases them
     33function prepareForComparison (o) {
     34    if (typeof o == "string") { return o.toLowerCase().replace(/\"/g,""); }
     35    return "";
     36};
     37
     38
     39function rdfDataTree(sourceName) {
     40    this.treeElem = document.getElementById("rdfDataTree_" + sourceName);
     41    this.filterText = "";
     42}
     43rdfDataTree.prototype = {
     44    idTable : null,
     45    idData : null,
     46    treeElem : null,
     47    filterText : null,
     48   
     49    //this function is called every time the tree is sorted, filtered, or reloaded
     50    loadTable : function(container) {
     51        //remember scroll position. this is useful if this is an editable table
     52        //to prevent the user from losing the row they edited
     53        var topVisibleRow = null;
     54        if (this.idTable) { topVisibleRow = this.treeElem.treeBoxObject.getFirstVisibleRow(); }
     55        if (this.idData == null) {
     56            this.idData = [];
     57            vI_rdfDatasource.readAllEntriesFromRDF(container, this);
     58        }
     59        if (this.filterText == "") {
     60            //show all of them
     61            this.idTable = this.idData;
     62        } else {
     63            //filter out the ones we want to display
     64            this.idTable = [];
     65            this.idData.forEach(function(element) {
     66                //we'll match on every property
     67                for (var i in element) {
     68                    if (prepareForComparison(element[i]).indexOf(this.filterText) != -1) {
     69                        this.idTable.push(element);
     70                        break;
     71                    }
     72                }
     73            });
     74        }   
     75        this.sort();
     76        //restore scroll position
     77        if (topVisibleRow) {
     78            this.treeElem.treeBoxObject.scrollToRow(topVisibleRow);
     79        }
     80    },
     81
     82    addNewDatum : function(resource, name, localIdentityData, idData) {
    5783        var pref = {    recipientCol : name,
    58                 typeCol : document.getElementById("vI_rdfDataTreeBundle").getString("vI_rdfDataTree.dataType." + type),
     84                typeCol : "type",
    5985                senderCol : localIdentityData.combinedName,
    6086                smtpCol : localIdentityData.smtp.value,
     
    6389                idKey : localIdentityData.id.key,
    6490                resource : resource,
    65                 type : type,
    66                 identityData : localIdentityData }
    67        
     91                identityData : localIdentityData}
     92//      vI_notificationBar.dump("## addNewDatum.\n");
    6893        localIdentityData.extras.addPrefs(pref);
    69         vI_rdfDataTree.__idData.push(pref);
    70     },
    71    
    72     //this function is called every time the tree is sorted, filtered, or reloaded
    73     loadTable : function() {
    74         //remember scroll position. this is useful if this is an editable table
    75         //to prevent the user from losing the row they edited
    76         var topVisibleRow = null;
    77         if (vI_rdfDataTree.__idTable) {
    78             topVisibleRow = vI_rdfDataTree.__treeElem.treeBoxObject.getFirstVisibleRow();
    79         }
    80         if (vI_rdfDataTree.__idData == null) {
    81             vI_rdfDataTree.__idData = [];
    82             vI_rdfDatasource.readAllVIdentitiesFromRDF(vI_rdfDataTree.__addNewDatum)
    83         }
    84         if (vI_rdfDataTree.filterText == "") {
    85             //show all of them
    86             vI_rdfDataTree.__idTable = vI_rdfDataTree.__idData;
    87         } else {
    88             //filter out the ones we want to display
    89             vI_rdfDataTree.__idTable = [];
    90             vI_rdfDataTree.__idData.forEach(function(element) {
    91                 //we'll match on every property
    92                 for (var i in element) {
    93                     if (vI_rdfDataTree.__prepareForComparison(element[i]).indexOf(vI_rdfDataTree.filterText) != -1) {
    94                         vI_rdfDataTree.__idTable.push(element);
    95                         break;
    96                     }
    97                 }
    98             });
    99         }
    100         vI_rdfDataTree.sort();
    101         //restore scroll position
    102         if (topVisibleRow) {
    103             vI_rdfDataTree.__treeElem.treeBoxObject.scrollToRow(topVisibleRow);
    104         }
    105     },
    106    
     94        idData.push(pref);
     95    },
    10796    sort : function(column) {
    10897        var columnName;
    109         var order = vI_rdfDataTree.__treeElem.getAttribute("sortDirection") == "ascending" ? 1 : -1;
     98        var order = this.treeElem.getAttribute("sortDirection") == "ascending" ? 1 : -1;
    11099        //if the column is passed and it's already sorted by that column, reverse sort
    111100        if (column) {
    112101            columnName = column.id;
    113             if (vI_rdfDataTree.__treeElem.getAttribute("sortResource") == columnName) {
     102            if (this.treeElem.getAttribute("sortResource") == columnName) {
    114103                order *= -1;
    115104            }
    116105        } else {
    117             columnName = vI_rdfDataTree.__treeElem.getAttribute("sortResource");
     106            columnName = this.treeElem.getAttribute("sortResource");
    118107        }
    119108       
    120109        function columnSort(a, b) {
    121             if (vI_rdfDataTree.__prepareForComparison(a[columnName]) >
    122                 vI_rdfDataTree.__prepareForComparison(b[columnName])) return 1 * order;
    123             if (vI_rdfDataTree.__prepareForComparison(a[columnName]) <
    124                 vI_rdfDataTree.__prepareForComparison(b[columnName])) return -1 * order;
     110            if (prepareForComparison(a[columnName]) >
     111                prepareForComparison(b[columnName])) return 1 * order;
     112            if (prepareForComparison(a[columnName]) <
     113                prepareForComparison(b[columnName])) return -1 * order;
    125114            return 0;
    126115        }
    127         vI_rdfDataTree.__idTable.sort(columnSort);
     116        this.idTable.sort(columnSort);
    128117        //setting these will make the sort option persist
    129         vI_rdfDataTree.__treeElem.setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
    130         vI_rdfDataTree.__treeElem.setAttribute("sortResource", columnName);
    131         vI_rdfDataTree.__treeElem.view = new vI_rdfDataTree.treeView(vI_rdfDataTree.__idTable);
     118        this.treeElem.setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
     119        this.treeElem.setAttribute("sortResource", columnName);
     120        this.treeElem.view = new vI_rdfDataTree.treeView(this.idTable);
    132121        //set the appropriate attributes to show to indicator
    133         var cols = vI_rdfDataTree.__treeElem.getElementsByTagName("treecol");
     122        var cols = this.treeElem.getElementsByTagName("treecol");
    134123        for (var i = 0; i < cols.length; i++) {
    135124            cols[i].removeAttribute("sortDirection");
     
    138127    },
    139128
     129}
     130
     131var vI_rdfDataTree = {
     132    promptService : Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
     133            .getService(Components.interfaces.nsIPromptService),
     134
     135    trees : {},
     136    tabbox : null,
     137   
     138    _strings : null,
     139   
     140    onselect : function () {
     141vI_notificationBar.dump("## onselect " + vI_rdfDataTree.tabbox.selectedPanel.id + ".\n");
     142        var tree = vI_rdfDataTree.trees[vI_rdfDataTree.tabbox.selectedPanel.id];
     143        var htmlBox = document.getElementById("vI_rdfDataTreeInfoBox")
     144        if (tree.treeElem.view.selection.count != 1)
     145            { vI_rdfDataTree.hideInfoBox(); return; }
     146       
     147        var identityData = tree.idTable[tree.treeElem.currentIndex]["identityData"];
     148        var _identityInfo =
     149            "<div id='recipientLabel'>" +
     150                tree.idTable[tree.treeElem.currentIndex]["recipientCol"].replace(/>/g,"&gt;").replace(/</g,"&lt;") +
     151            "</div><div id='vICard'>" +
     152            "<table><tr>" +
     153                "<td class='image'><img src='chrome://v_identity/skin/vi-info.png' /></td>" +
     154                "<td class='identityTable'>" +
     155                    "<div class='name'>" + identityData.combinedNameHtml + "</div>" +   
     156                    "<table><tbody>" + identityData.getMatrix() + "</tbody></table>" +
     157                "</td>" +
     158            "</tr></table></div>"
     159
     160        htmlBox.outputString = _identityInfo;
     161        vI_rdfDataTree.infoBoxHidden = false;
     162        htmlBox.setAttribute("style", "height:" + htmlBox.contentDocument.lastChild.scrollHeight +"px");
     163        vI_rdfDataTree.overflow(); // better resize one time too much, mozilla is still magic  :)
     164    },
     165
     166    init : function() {
     167        vI_rdfDataTree.tabbox = document.getElementById("TreeTabbox");
     168        vI_rdfDataTree._strings = document.getElementById("vI_rdfDataTreeBundle");
     169
     170        vI_rdfDatasource.init();
     171        vI_storageExtrasHelper.hideUnusedTreeCols(); // XXX what happens heree ?? :)
     172       
     173        vI_rdfDataTree.trees["email"] = new rdfDataTree("email");
     174        vI_rdfDataTree.trees["email"].loadTable(vI_rdfDatasource.emailContainer);
     175        vI_rdfDataTree.trees["maillist"] = new rdfDataTree("maillist");
     176        vI_rdfDataTree.trees["maillist"].loadTable(vI_rdfDatasource.maillistContainer);
     177        vI_rdfDataTree.trees["newsgroup"] = new rdfDataTree("newsgroup");
     178        vI_rdfDataTree.trees["newsgroup"].loadTable(vI_rdfDatasource.newsgroupContainer);
     179        vI_rdfDataTree.trees["filter"] = new rdfDataTree("filter");
     180        vI_rdfDataTree.trees["filter"].loadTable(vI_rdfDatasource.filterContainer);
     181    },
     182   
    140183    //generic custom tree view stuff
    141184    treeView : function (table) {
     
    163206        this.cycleHeader = function(col, elem) { vI_rdfDataTree.sort(col) };
    164207    },
     208
    165209   
    166210    __setFilter : function (text) {
     211// loop trough all trees
    167212        vI_rdfDataTree.filterText = text;
    168213        vI_rdfDataTree.loadTable();
     
    185230   
    186231    __updateMenu : function(modifySelected, removeSelected) {
    187         var noSelections = (vI_rdfDataTree.__treeElem.view.selection.count == 0)
     232        var tree = vI_rdfDataTree.trees[vI_rdfDataTree.tabbox.selectedPanel.id];
     233        var noSelections = (tree.treeElem.view.selection.count == 0)
    188234        modifySelected.setAttribute("disabled", noSelections)
    189235        removeSelected.setAttribute("disabled", noSelections)   
     
    203249
    204250    modifySelected : function() {
    205         if (vI_rdfDataTree.__treeElem.view.selection.count == 0) return;
    206         if (vI_rdfDataTree.__treeElem.view.selection.count > 5) {
    207             var warning = vI_rdfDataTree.__strings.getString("vI_rdfDataTree.modify.Warning1") + " " +
    208                 vI_rdfDataTree.__treeElem.view.selection.count + " " +
    209                 vI_rdfDataTree.__strings.getString("vI_rdfDataTree.modify.Warning2")
     251        var tree = vI_rdfDataTree.trees[vI_rdfDataTree.tabbox.selectedPanel.id];
     252        if (tree.treeElem.view.selection.count == 0) return;
     253        if (tree.treeElem.view.selection.count > 5) {
     254            var warning = vI_rdfDataTree._strings.getString("vI_rdfDataTree.modify.Warning1") + " " +
     255                tree.treeElem.view.selection.count + " " +
     256                vI_rdfDataTree._strings.getString("vI_rdfDataTree.modify.Warning2")
    210257            if (!vI_rdfDataTree.promptService.confirm(window,"Warning",warning)) return;
    211258        }
    212259       
    213260        var start = new Object(); var end = new Object();
    214         var numRanges = vI_rdfDataTree.__treeElem.view.selection.getRangeCount();
     261        var numRanges = tree.treeElem.view.selection.getRangeCount();
    215262
    216263        for (var t=0; t<numRanges; t++){
    217             vI_rdfDataTree.__treeElem.view.selection.getRangeAt(t,start,end);
     264            tree.treeElem.view.selection.getRangeAt(t,start,end);
    218265            for (var v=start.value; v<=end.value; v++)
    219266                window.openDialog("chrome://v_identity/content/vI_rdfDataEditor.xul",0,
    220267                    "chrome, dialog, modal, alwaysRaised, resizable=yes",
    221                     vI_rdfDataTree.__idTable[v],
     268                    tree.idTable[v],
    222269                    vI_rdfDatasource).focus();
    223270        }
    224271       
    225         vI_rdfDataTree.__idData = null; vI_rdfDataTree.__idTable = null;
    226         vI_rdfDataTree.loadTable();
     272        tree.idData = null; tree.idTable = null;
     273        vI_rdfDataTree.loadTable(vI_rdfDataTree.tabbox.selectedPanel.id);
    227274        vI_rdfDataTree.hideInfoBox();
    228275    },
     
    252299    },
    253300   
    254     onselect : function() {
    255         var htmlBox = document.getElementById("vI_rdfDataTreeInfoBox")
    256         if (vI_rdfDataTree.__treeElem.view.selection.count != 1)
    257             { vI_rdfDataTree.hideInfoBox(); return; }
    258        
    259         var identityData = vI_rdfDataTree.__idTable[vI_rdfDataTree.__treeElem.currentIndex]["identityData"];
    260         var _identityInfo =
    261             "<div id='recipientLabel'>" +
    262                 vI_rdfDataTree.__idTable[vI_rdfDataTree.__treeElem.currentIndex]["recipientCol"].replace(/>/g,"&gt;").replace(/</g,"&lt;") +
    263             "</div><div id='vICard'>" +
    264             "<table><tr>" +
    265                 "<td class='image'><img src='chrome://v_identity/skin/vi-info.png' /></td>" +
    266                 "<td class='identityTable'>" +
    267                     "<div class='name'>" + identityData.combinedNameHtml + "</div>" +   
    268                     "<table><tbody>" + identityData.getMatrix() + "</tbody></table>" +
    269                 "</td>" +
    270             "</tr></table></div>"
    271 
    272         htmlBox.outputString = _identityInfo;
    273         vI_rdfDataTree.infoBoxHidden = false;
    274         htmlBox.setAttribute("style", "height:" + htmlBox.contentDocument.lastChild.scrollHeight +"px");
    275         vI_rdfDataTree.overflow(); // better resize one time too much :)
    276     },
    277301
    278302    infoBoxHidden : true,
  • chrome/content/v_identity/vI_rdfDataTree.xul

    r603625 r44a21d  
    7373<popup id="configContext" onpopupshowing="if (event.target == this) vI_rdfDataTree.updateContextMenu();">
    7474    <menuitem id="context_modifySelected" label="&vI_rdfDataTree.modifySelected.label;"
    75         oncommand="vI_rdfDataTree.modifySelected();"/>
     75        oncommand="vI_rdfDataTree.modifySelected(this);"/>
    7676    <menuitem id="context_removeSelected" label="&vI_rdfDataTree.removeSelected.label;"
    7777        oncommand="vI_rdfDataTree.removeSelected();"/>
     
    119119    <button id="clearFilter" label="&vI_rdfDataTree.showAll.label;" accesskey="&vI_rdfDataTree.showAll.accesskey;" oncommand="vI_rdfDataTree.clearFilter();" disabled="true"/>
    120120</hbox>
    121 
    122 <!-- just to use the same style like the threadTree -->
    123 <tree id="threadTree" flex="1" class="plain" seltype="multiple"
     121<tabbox id="TreeTabbox" flex="1">
     122<tabs>
     123<tab label="Emails"/>
     124<tab label="Mailing Lists"/>
     125<tab label="Newsgroups"/>
     126<tab label="Filter"/>
     127</tabs>
     128<tabpanels flex="1">
     129<tabpanel id="email" flex="1">
     130<tree id="rdfDataTree_email" flex="1" class="plain" seltype="multiple"
     131    persist="sortDirection sortResource" sortDirection="ascending" sortResource="recipientCol"
     132    enableColumnDrag="true" context="configContext" onselect="vI_rdfDataTree.onselect(this);">
     133    <treecols id="rdfDataTreeCols">
     134        <treecol id="recipientCol" label="&vI_rdfDataTree.recipientColumn.label;" flex="10"
     135            class="sortDirectionIndicator"
     136            ignoreincolumnpicker="true"
     137            persist="hidden width ordinal sortDirection"/>
     138        <splitter class="tree-splitter" />
     139        <treecol id="typeCol" label="&vI_rdfDataTree.typeColumn.label;" flex="5"
     140            class="sortDirectionIndicator"
     141            persist="hidden width ordinal sortDirection"/>
     142        <splitter class="tree-splitter" />
     143        <treecol id="senderCol" label="&vI_rdfDataTree.senderColumn.label;" flex="10"
     144            class="sortDirectionIndicator"
     145            persist="hidden width ordinal sortDirection"/>
     146        <splitter class="tree-splitter" />
     147        <treecol id="smtpCol" label="&vI_rdfDataTree.smtpColumn.label;" flex="5"
     148            class="sortDirectionIndicator"
     149            persist="hidden width ordinal sortDirection"/>
     150        <splitter class="tree-splitter" />
     151        <treecol id="idCol" label="&vI_rdfDataTree.idColumn.label;" flex="10"
     152            class="sortDirectionIndicator"
     153            persist="hidden width ordinal sortDirection"/>     
     154    </treecols>
     155    <treechildren id="configTreeBody" ondblclick="if (event.button == 0) vI_rdfDataTree.modifySelected();" />
     156</tree>
     157</tabpanel>
     158
     159<tabpanel id="maillist" flex="1">
     160<tree id="rdfDataTree_maillist" flex="1" class="plain" seltype="multiple"
    124161    persist="sortDirection sortResource" sortDirection="ascending" sortResource="recipientCol"
    125162    enableColumnDrag="true" context="configContext" onselect="vI_rdfDataTree.onselect();">
     
    148185    <treechildren id="configTreeBody" ondblclick="if (event.button == 0) vI_rdfDataTree.modifySelected();" />
    149186</tree>
    150 <splitter />
     187</tabpanel>
     188<tabpanel id="newsgroup" flex="1">
     189<tree id="rdfDataTree_newsgroup" flex="1" class="plain" seltype="multiple"
     190    persist="sortDirection sortResource" sortDirection="ascending" sortResource="recipientCol"
     191    enableColumnDrag="true" context="configContext" onselect="vI_rdfDataTree.onselect();">
     192    <treecols id="rdfDataTreeCols">
     193        <treecol id="recipientCol" label="&vI_rdfDataTree.recipientColumn.label;" flex="10"
     194            class="sortDirectionIndicator"
     195            ignoreincolumnpicker="true"
     196            persist="hidden width ordinal sortDirection"/>
     197        <splitter class="tree-splitter" />
     198        <treecol id="typeCol" label="&vI_rdfDataTree.typeColumn.label;" flex="5"
     199            class="sortDirectionIndicator"
     200            persist="hidden width ordinal sortDirection"/>
     201        <splitter class="tree-splitter" />
     202        <treecol id="senderCol" label="&vI_rdfDataTree.senderColumn.label;" flex="10"
     203            class="sortDirectionIndicator"
     204            persist="hidden width ordinal sortDirection"/>
     205        <splitter class="tree-splitter" />
     206        <treecol id="smtpCol" label="&vI_rdfDataTree.smtpColumn.label;" flex="5"
     207            class="sortDirectionIndicator"
     208            persist="hidden width ordinal sortDirection"/>
     209        <splitter class="tree-splitter" />
     210        <treecol id="idCol" label="&vI_rdfDataTree.idColumn.label;" flex="10"
     211            class="sortDirectionIndicator"
     212            persist="hidden width ordinal sortDirection"/>     
     213    </treecols>
     214    <treechildren id="configTreeBody" ondblclick="if (event.button == 0) vI_rdfDataTree.modifySelected();" />
     215</tree>
     216</tabpanel>
     217<tabpanel id="filter" flex="1">
     218<tree id="rdfDataTree_filter" flex="1" class="plain" seltype="multiple"
     219    persist="sortDirection sortResource" sortDirection="ascending" sortResource="recipientCol"
     220    enableColumnDrag="true" context="configContext" onselect="vI_rdfDataTree.onselect();">
     221    <treecols id="rdfDataTreeCols">
     222        <treecol id="recipientCol" label="&vI_rdfDataTree.recipientColumn.label;" flex="10"
     223            class="sortDirectionIndicator"
     224            ignoreincolumnpicker="true"
     225            persist="hidden width ordinal sortDirection"/>
     226        <splitter class="tree-splitter" />
     227        <treecol id="typeCol" label="&vI_rdfDataTree.typeColumn.label;" flex="5"
     228            class="sortDirectionIndicator"
     229            persist="hidden width ordinal sortDirection"/>
     230        <splitter class="tree-splitter" />
     231        <treecol id="senderCol" label="&vI_rdfDataTree.senderColumn.label;" flex="10"
     232            class="sortDirectionIndicator"
     233            persist="hidden width ordinal sortDirection"/>
     234        <splitter class="tree-splitter" />
     235        <treecol id="smtpCol" label="&vI_rdfDataTree.smtpColumn.label;" flex="5"
     236            class="sortDirectionIndicator"
     237            persist="hidden width ordinal sortDirection"/>
     238        <splitter class="tree-splitter" />
     239        <treecol id="idCol" label="&vI_rdfDataTree.idColumn.label;" flex="10"
     240            class="sortDirectionIndicator"
     241            persist="hidden width ordinal sortDirection"/>     
     242    </treecols>
     243    <treechildren id="configTreeBody" ondblclick="if (event.button == 0) vI_rdfDataTree.modifySelected();" />
     244</tree>
     245</tabpanel>
     246
     247</tabpanels>
     248</tabbox> -->
     249<!-- <splitter /> -->
    151250<browser id="vI_rdfDataTreeInfoBox" class="vI_htmlTextBox" cssSource="vI_rdfTreeInfo.css" disablehistory="true" onoverflow="vI_rdfDataTree.overflow();"/>
    152251
Note: See TracChangeset for help on using the changeset viewer.