Changeset 509348 for modules/vI_identityDataExtras.js
- Timestamp:
- Nov 3, 2014, 12:35:40 PM (8 years ago)
- Branches:
- ng_0.9
- Children:
- 7204cb
- Parents:
- 3c9c29
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/vI_identityDataExtras.js
r3c9c29 r509348 25 25 var EXPORTED_SYMBOLS = ["identityDataExtras", "registerIdExtrasObject", "identityDataExtrasObject", "identityDataExtrasCheckboxObject"]; 26 26 27 const {classes: Cc, interfaces: Ci, utils: Cu, results : Cr} = Components; 27 const { 28 classes: Cc, 29 interfaces: Ci, 30 utils: Cu, 31 results: Cr 32 } = Components; 28 33 29 34 Cu.import("resource://v_identity/vI_log.js"); … … 47 52 .getService(Ci.nsIWindowMediator) 48 53 .getMostRecentWindow(null); 49 for each 54 for each(let [, identityDataExtrasObject] in Iterator(idExtrasObjects)) { 50 55 this.extras.push(new identityDataExtrasObject(currentWindow)); 51 56 } … … 53 58 this.loopThroughExtras( 54 59 function (extra) { 55 extra.value = rdfDatasource._getRDFValue(resource, extra.field);}); 60 extra.value = rdfDatasource._getRDFValue(resource, extra.field); 61 }); 56 62 } 57 63 identityDataExtras.prototype = { 58 loopThroughExtras : function(k, returnVal) {59 for ( var i = 0; i < this.extras.length; i++) {64 loopThroughExtras: function (k, returnVal) { 65 for (var i = 0; i < this.extras.length; i++) { 60 66 try { 61 67 returnVal = k(this.extras[i], i, returnVal) 62 } 63 catch (e) { 68 } catch (e) { 64 69 Log.warn("identityDataExtras '" + this.extras[i].field + "' returned an error:", e); 65 70 dumpCallStack(e); … … 68 73 return returnVal; 69 74 }, 70 75 71 76 // just give a duplicate of the current identityDataExtras, else we will work with pointers 72 getDuplicate : function() {77 getDuplicate: function () { 73 78 var newExtras = new identityDataExtras(); 74 79 this.loopThroughExtras(function (extra, i) { … … 77 82 return newExtras; 78 83 }, 79 84 80 85 // copys all values of an identity. This way we can create a new object with a different document-context 81 copy : function(extras) {86 copy: function (extras) { 82 87 this.loopThroughExtras(function (extra, i) { 83 88 extra.value = extras.extras[i].value; … … 85 90 }, 86 91 87 equal : function(identityDataExtras) {92 equal: function (identityDataExtras) { 88 93 var returnVal = true; 89 94 return this.loopThroughExtras(function (extra, i, returnVal) { 90 return extra.active ?(extra.equal(identityDataExtras.extras[i]) && returnVal):returnVal;95 return extra.active ? (extra.equal(identityDataExtras.extras[i]) && returnVal) : returnVal; 91 96 }, returnVal); 92 97 }, 93 94 getMatrix : function() {98 99 getMatrix: function () { 95 100 var returnVal = ""; 96 101 return this.loopThroughExtras(function (extra, i, returnVal) { 97 102 if (extra.active && extra.valueHtml) 98 103 returnVal += "<tr>" + 99 100 101 104 "<td class='col1 extras '>" + stringBundle.GetStringFromName("vident.identityData.extras." + extra.field) + "</td>" + 105 "<td class='col2 extras '>" + extra.valueHtml + "</td>" + 106 "</tr>" 102 107 return returnVal; 103 108 }, returnVal); 104 109 }, 105 110 106 getCompareMatrix : function() {111 getCompareMatrix: function () { 107 112 var returnVal = ""; 108 113 return this.loopThroughExtras(function (extra, i, returnVal) { 109 114 if (extra.active) { 110 var classEqual = (extra.lastCompareResult) ?"equal":"unequal";115 var classEqual = (extra.lastCompareResult) ? "equal" : "unequal"; 111 116 returnVal += "<tr>" + 112 "<td class='col1 extras " + classEqual + "'>" + stringBundle.GetStringFromName("vident.identityData.extras." + extra.field) + "</td>" +113 "<td class='col2 extras " + classEqual + "'>" + extra.lastCompareValue + "</td>" +114 "<td class='col3 extras " + classEqual + "'>" + extra.valueHtml + "</td>" +115 "</tr>"117 "<td class='col1 extras " + classEqual + "'>" + stringBundle.GetStringFromName("vident.identityData.extras." + extra.field) + "</td>" + 118 "<td class='col2 extras " + classEqual + "'>" + extra.lastCompareValue + "</td>" + 119 "<td class='col3 extras " + classEqual + "'>" + extra.valueHtml + "</td>" + 120 "</tr>" 116 121 } 117 122 return returnVal … … 119 124 }, 120 125 121 status : function() {126 status: function () { 122 127 var returnVal = ""; 123 128 return this.loopThroughExtras(function (extra) { 124 return returnVal += returnVal ?" ":"" + extra.status;129 return returnVal += returnVal ? " " : "" + extra.status; 125 130 }, returnVal); 126 131 }, 127 132 128 readIdentityValues : function(identity) {133 readIdentityValues: function (identity) { 129 134 this.loopThroughExtras(function (extra) { 130 135 extra.readIdentityValue(identity) … … 132 137 }, 133 138 134 setValuesToEnvironment : function() {139 setValuesToEnvironment: function () { 135 140 this.loopThroughExtras(function (extra) { 136 141 extra.setValueToEnvironment() 137 142 }); 138 143 }, 139 140 getValuesFromEnvironment : function() {144 145 getValuesFromEnvironment: function () { 141 146 this.loopThroughExtras(function (extra) { 142 147 extra.getValueFromEnvironment() 143 148 }); 144 149 }, 145 150 146 151 // add value's to the pref object, required for rdfDataTreeCollection 147 addPrefs : function(pref) {152 addPrefs: function (pref) { 148 153 this.loopThroughExtras(function (extra) { 149 154 pref[extra.field + "Col"] = extra.valueNice; … … 156 161 } 157 162 identityDataExtrasObject.prototype = { 158 value : null,// will contain the current value of the object and can be accessed from outside159 field : null,// short description of the field160 option : null,// option from preferences, boolean161 window : null,// the current Window the object was created for162 163 lastCompareValue 164 lastCompareResult 163 value: null, // will contain the current value of the object and can be accessed from outside 164 field: null, // short description of the field 165 option: null, // option from preferences, boolean 166 window: null, // the current Window the object was created for 167 168 lastCompareValue: "", 169 lastCompareResult: false, 165 170 166 171 get valueHtml() { 167 168 169 return "<div class='bool" + ((this.value=="true")?" checked":"") + "'>" +170 171 172 172 if (!this.value) 173 return ""; 174 return "<div class='bool" + ((this.value == "true") ? " checked" : "") + "'>" + 175 "<label class='screen'> </label>" + 176 "<label class='braille'>" + this.valueNice + "</label>" + 177 "</div>" 173 178 }, 174 179 get valueNice() { 175 176 177 return (this.value=="true")?"yes":"no";180 if (!this.value) 181 return ""; 182 return (this.value == "true") ? "yes" : "no"; 178 183 }, 179 184 get status() { … … 182 187 return ""; 183 188 }, 184 get active() { return vIprefs.get("storage") && vIprefs.get(this.option) }, 185 equal : function(compareIdentityDataExtrasObject) { 189 get active() { 190 return vIprefs.get("storage") && vIprefs.get(this.option) 191 }, 192 equal: function (compareIdentityDataExtrasObject) { 186 193 this.lastCompareValue = compareIdentityDataExtrasObject.valueHtml; 187 194 this.lastCompareResult = (!this.value || !compareIdentityDataExtrasObject.value || this.value == compareIdentityDataExtrasObject.value); 188 195 if (!this.lastCompareResult) { 189 Log.debug("extras not equal " + this.field + " ('" + this.value + "' != '" + compareIdentityDataExtrasObject.value + "')");196 Log.debug("extras not equal " + this.field + " ('" + this.value + "' != '" + compareIdentityDataExtrasObject.value + "')"); 190 197 } 191 198 return this.lastCompareResult; 192 199 }, 193 200 // function to read the value from a given identity (probably not part of identity) 194 readIdentityValue : function(identity) {},201 readIdentityValue: function (identity) {}, 195 202 // function to set or read the value from/to the environment 196 setValueToEnvironment : function() {203 setValueToEnvironment: function () { 197 204 let id = this.currentWindow.document.documentElement.id; 198 switch (id) {199 200 201 202 203 204 205 206 207 208 209 210 211 } 212 }, 213 getValueFromEnvironment : function() {205 switch (id) { 206 case "msgcomposeWindow": 207 this.setValueToEnvironment_msgCompose(); 208 break; 209 case "messengerWindow": 210 this.setValueToEnvironment_messenger(); 211 break; 212 case "vI_rdfDataTreeWindow": 213 case "vI_rdfDataEditor": 214 this.setValueToEnvironment_dataEditor(); 215 break; 216 default: 217 Log.error("getValueFromEnvironment unknown window: " + id) 218 } 219 }, 220 getValueFromEnvironment: function () { 214 221 let id = this.currentWindow.document.documentElement.id; 215 switch (id) {216 217 218 219 220 221 222 223 224 225 226 227 228 } 229 }, 230 setValueToEnvironment_msgCompose : function() {222 switch (id) { 223 case "msgcomposeWindow": 224 this.getValueFromEnvironment_msgCompose(); 225 break; 226 case "messengerWindow": 227 this.getValueFromEnvironment_messenger(); 228 break; 229 case "vI_rdfDataTreeWindow": 230 case "vI_rdfDataEditor": 231 this.getValueFromEnvironment_dataEditor(); 232 break; 233 default: 234 Log.error("getValueFromEnvironment unknown window: " + id) 235 } 236 }, 237 setValueToEnvironment_msgCompose: function () { 231 238 Log.error("setValueToEnvironment not implemented for msgCompose and " + this.field) 232 239 }, 233 setValueToEnvironment_messenger : function() {240 setValueToEnvironment_messenger: function () { 234 241 Log.error("setValueToEnvironment not implemented for Messenger and " + this.field) 235 242 }, 236 setValueToEnvironment_dataEditor : function() {243 setValueToEnvironment_dataEditor: function () { 237 244 Log.error("setValueToEnvironment not implemented for dataEditor and " + this.field) 238 245 }, 239 getValueFromEnvironment_msgCompose : function() {246 getValueFromEnvironment_msgCompose: function () { 240 247 Log.error("setValueToEnvironment not implemented for msgCompose and " + this.field) 241 248 }, 242 getValueFromEnvironment_messenger : function() {249 getValueFromEnvironment_messenger: function () { 243 250 Log.error("setValueToEnvironment not implemented for Messenger and " + this.field) 244 251 }, 245 getValueFromEnvironment_dataEditor : function() {252 getValueFromEnvironment_dataEditor: function () { 246 253 Log.error("setValueToEnvironment not implemented for dataEditor and " + this.field) 247 254 } … … 254 261 identityDataExtrasCheckboxObject.prototype = { 255 262 __proto__: identityDataExtrasObject.prototype, 256 257 updateFunction_msgCompose : function() {},258 elementID_msgCompose 259 260 readIdentityValue : function(identity) {263 264 updateFunction_msgCompose: function () {}, 265 elementID_msgCompose: null, 266 267 readIdentityValue: function (identity) { 261 268 if (this.active) 262 this.value = (this.func_valueFromIdentity(identity)) ?"true":"false";263 }, 264 265 setValueToEnvironment_msgCompose: function () {269 this.value = (this.func_valueFromIdentity(identity)) ? "true" : "false"; 270 }, 271 272 setValueToEnvironment_msgCompose: function () { 266 273 var element = this.currentWindow.document.getElementById(this.elementID_msgCompose); 267 274 if (!this.active || (this.value == null) || !element) 268 275 return; 269 276 270 277 this.updateFunction_msgCompose(); 271 278 if ((element.getAttribute("checked") == "true") != (this.value == "true")) { 272 Log.debug("change " + this.field + " to " + this.value + " with doCommand");279 Log.debug("change " + this.field + " to " + this.value + " with doCommand"); 273 280 element.doCommand(); 274 281 } 275 282 }, 276 277 setValueToEnvironment_dataEditor: function () {283 284 setValueToEnvironment_dataEditor: function () { 278 285 if (this.value != null) { 279 286 this.currentWindow.document.getElementById("vI_" + this.option).setAttribute("checked", this.value); … … 282 289 this.currentWindow.document.getElementById("vI_" + this.option + "_store").doCommand(); 283 290 }, 284 285 getValueFromEnvironment_msgCompose: function () {291 292 getValueFromEnvironment_msgCompose: function () { 286 293 var element = this.currentWindow.document.getElementById(this.elementID_msgCompose) 287 294 if (this.active && element) { 288 295 this.updateFunction_msgCompose(); 289 this.value = ((element.getAttribute("checked") == "true") ?"true":"false");290 } 291 }, 292 293 getValueFromEnvironment_dataEditor: function () {296 this.value = ((element.getAttribute("checked") == "true") ? "true" : "false"); 297 } 298 }, 299 300 getValueFromEnvironment_dataEditor: function () { 294 301 if (this.currentWindow.document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true") { 295 302 var elementValue = this.currentWindow.document.getElementById("vI_" + this.option).getAttribute("checked"); 296 this.value = (elementValue == "true")?"true":"false" 297 } 298 else 303 this.value = (elementValue == "true") ? "true" : "false" 304 } else 299 305 this.value = null; 300 306 }
Note: See TracChangeset
for help on using the changeset viewer.