This is just some static backup of the original site, don't expect every link to work!

source: content/vI_rdfDataEditor.js

ng_0.9 0.10.3
Last change on this file was b7742f, checked in by rene <rene@…>, 4 years ago

adapted for new identityData

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24
25Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
26virtualIdentityExtension.ns(function () {
27  with(virtualIdentityExtension.LIB) {
28
29    Components.utils.import("resource://v_identity/vI_identityData.js", virtualIdentityExtension);
30    let Log = vI.setupLogging("virtualIdentity.rdfDataEditor");
31    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
32
33    var rdfDataEditor = {
34      __rdfDatasource: null,
35      __rdfDataTree: null,
36      __type: null,
37      __recipient: null,
38      __identityData: null,
39
40      __populateIdentityMenu: function () {
41        var listitem = document.createElement("menuitem");
42        listitem.setAttribute("label", "");
43        document.getElementById("virtualIdentityExtension_IdentityListPopup").appendChild(listitem);
44        document.getElementById("virtualIdentityExtension_IdentityList").selectedItem = listitem;
45        var separator = document.createElement("menuseparator");
46        document.getElementById("virtualIdentityExtension_IdentityListPopup").appendChild(separator);
47
48        FillIdentityList(document.getElementById("virtualIdentityExtension_IdentityList"))
49      },
50
51      init: function () {
52        if (window.arguments[0]["recipientCol"])
53          rdfDataEditor.__recipient = window.arguments[0]["recipientCol"];
54        rdfDataEditor.__type = window.arguments[1];
55        rdfDataEditor.__rdfDatasource = window.arguments[2];
56        rdfDataEditor.__rdfDataTree = window.arguments[3];;
57        rdfDataEditor.__identityData = new vI.identityData(window);
58        rdfDataEditor.__identityData.copy(window.arguments[0].identityData);
59
60
61        // set recipient
62        document.getElementById("recipient").value = rdfDataEditor.__recipient;
63
64        // set type of entry (and populate Menu)
65        var typeMenuPopup = document.getElementById("type_menu_popup")
66        for (var typeField of Array("email", "maillist", "newsgroup", "filter")) {
67          var menuitem = document.createElement("menuitem");
68          var label = Components.classes["@mozilla.org/intl/stringbundle;1"]
69            .getService(Components.interfaces.nsIStringBundleService)
70            .createBundle("chrome://v_identity/locale/vI_rdfDataEditor.properties")
71            .GetStringFromName("vI_rdfDataTree.dataType." + typeField);
72          menuitem.setAttribute("label", label);
73          menuitem.setAttribute("key", typeField);
74          typeMenuPopup.appendChild(menuitem);
75          if (typeField == rdfDataEditor.__type) document.getElementById("type_menu").selectedItem = menuitem
76        }
77
78        // set sender
79        document.getElementById("sender").value = rdfDataEditor.__identityData.combinedName;
80
81        // set Identity
82        rdfDataEditor.__populateIdentityMenu();
83        var MenuItems = document.getElementById("virtualIdentityExtension_IdentityListPopup").childNodes;
84        for (var index = 0; index < MenuItems.length; index++) {
85          if (MenuItems[index].getAttribute("identitykey") == rdfDataEditor.__identityData.id.key) {
86            document.getElementById("virtualIdentityExtension_IdentityList").selectedItem =
87              MenuItems[index];
88            break;
89          }
90        }
91
92        // set extra values
93        rdfDataEditor.__identityData.extras.setValuesToEnvironment();
94       
95        // only display hide-switch if not all extras are enabled in preferences
96        var allEnabled = true;
97        rdfDataEditor.__identityData.extras.loopThroughExtras(
98          function (extra) {
99            allEnabled = allEnabled && vI.vIprefs.get(extra.option);
100          }
101        )
102        if (allEnabled)
103            document.getElementById("vI_storageExtras_hideUnusedEditorFields").setAttribute("hidden", true);
104        else
105            this.hideUnusedEditorFields();
106       
107        Log.debug("init done");
108      },
109
110      hideUnusedEditorFields: function () {
111        var allHidden = true;
112        var hide = (document.getElementById("vI_storageExtras_hideUnusedEditorFields").getAttribute("checked") == "true")
113        rdfDataEditor.__identityData.extras.loopThroughExtras(
114          function (extra) {
115            var hidden = hide && !vI.vIprefs.get(extra.option);
116            document.getElementById("vI_" + extra.option).setAttribute("hidden", hidden)
117            document.getElementById("vI_" + extra.option + "_store").setAttribute("hidden", hidden)
118            if (!hidden) allHidden = false
119          });
120        document.getElementById("storeValue").setAttribute("hidden", allHidden)
121          // resize the window to the content
122        window.sizeToContent();
123      },
124
125      identityExtras_adapt: function (sourceId, targetId) {
126        var checked = document.getElementById(sourceId).getAttribute("checked");
127        if (targetId) var target = document.getElementById(targetId)
128        else var target = document.getElementById(sourceId.replace(/_store/, ""))
129        if (checked == "true") target.removeAttribute("disabled")
130        else target.setAttribute("disabled", "true");
131      },
132
133      blurEvent: function (elementId) {
134        var elem = document.getElementById(elementId);
135        var localIdentityData = new vI.identityData(window, elem.value, null, null, null, null, null);
136        elem.value = localIdentityData.combinedName;
137      },
138
139      accept: function () {
140        Log.debug("accept");
141        var localIdentityData = new vI.identityData(window, document.getElementById("sender").value, null,
142          document.getElementById("virtualIdentityExtension_IdentityList").selectedItem.getAttribute("identitykey"));
143
144        localIdentityData.extras.getValuesFromEnvironment();
145        rdfDataEditor.__rdfDatasource.updateRDF(
146          document.getElementById("recipient").value,
147          document.getElementById("type_menu").selectedItem.getAttribute("key"),
148          localIdentityData,
149          true, rdfDataEditor.__recipient, rdfDataEditor.__type, true);
150        Log.debug("updateRDF done " + localIdentityData.extras.status());
151        return document.getElementById("type_menu").selectedItem.getAttribute("key");
152      }
153    }
154    vI.rdfDataEditor = rdfDataEditor;
155  }
156});
Note: See TracBrowser for help on using the repository browser.