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

source: content/vI_rdfDataEditor.js @ b65d61

ng_0.9
Last change on this file since b65d61 was b65d61, checked in by rene <rene@…>, 5 years ago

fix for github bugreport #15

  • Property mode set to 100644
File size: 7.4 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 SMTP
93        document.getElementById("virtualIdentityExtension_smtpServerListHbox").addNoneServer(); // add non (not stored) Server
94        document.getElementById("virtualIdentityExtension_smtpServerListHbox").smtp = rdfDataEditor.__identityData.smtp.keyNice;
95
96        // set extra values
97        rdfDataEditor.__identityData.extras.setValuesToEnvironment();
98       
99        // only display hide-switch if not all extras are enabled in preferences
100        var allEnabled = true;
101        rdfDataEditor.__identityData.extras.loopThroughExtras(
102          function (extra) {
103            allEnabled = allEnabled && vI.vIprefs.get(extra.option);
104          }
105        )
106        if (allEnabled)
107            document.getElementById("vI_storageExtras_hideUnusedEditorFields").setAttribute("hidden", true);
108        else
109            this.hideUnusedEditorFields();
110       
111        Log.debug("init done");
112      },
113
114      hideUnusedEditorFields: function () {
115        var allHidden = true;
116        var hide = (document.getElementById("vI_storageExtras_hideUnusedEditorFields").getAttribute("checked") == "true")
117        rdfDataEditor.__identityData.extras.loopThroughExtras(
118          function (extra) {
119            var hidden = hide && !vI.vIprefs.get(extra.option);
120            document.getElementById("vI_" + extra.option).setAttribute("hidden", hidden)
121            document.getElementById("vI_" + extra.option + "_store").setAttribute("hidden", hidden)
122            if (!hidden) allHidden = false
123          });
124        document.getElementById("storeValue").setAttribute("hidden", allHidden)
125          // resize the window to the content
126        window.sizeToContent();
127      },
128
129      identityExtras_adapt: function (sourceId, targetId) {
130        var checked = document.getElementById(sourceId).getAttribute("checked");
131        if (targetId) var target = document.getElementById(targetId)
132        else var target = document.getElementById(sourceId.replace(/_store/, ""))
133        if (checked == "true") target.removeAttribute("disabled")
134        else target.setAttribute("disabled", "true");
135      },
136
137      blurEvent: function (elementId) {
138        var elem = document.getElementById(elementId);
139        var localIdentityData = new vI.identityData(window, elem.value, null, null, null, null, null, null);
140        elem.value = localIdentityData.combinedName;
141      },
142
143      accept: function () {
144        Log.debug("accept");
145        var localIdentityData = new vI.identityData(window, document.getElementById("sender").value, null,
146          document.getElementById("virtualIdentityExtension_IdentityList").selectedItem.getAttribute("identitykey"),
147          document.getElementById("virtualIdentityExtension_SmtpServerList").selectedItem.getAttribute("key"));
148        localIdentityData.extras.getValuesFromEnvironment();
149        rdfDataEditor.__rdfDatasource.updateRDF(
150          document.getElementById("recipient").value,
151          document.getElementById("type_menu").selectedItem.getAttribute("key"),
152          localIdentityData,
153          true, true, rdfDataEditor.__recipient, rdfDataEditor.__type, true);
154        Log.debug("updateRDF done " + localIdentityData.extras.status());
155        return document.getElementById("type_menu").selectedItem.getAttribute("key");
156      }
157    }
158    vI.rdfDataEditor = rdfDataEditor;
159  }
160});
Note: See TracBrowser for help on using the repository browser.