How to use d.settings.update method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

DimensionSettings.js

Source:DimensionSettings.js Github

copy

Full Screen

1/**2 * Copyright (c) 2011-2017 by Andrew Mustun. All rights reserved.3 * 4 * This file is part of the QCAD project.5 *6 * QCAD is free software: you can redistribute it and/or modify7 * it under the terms of the GNU General Public License as published by8 * the Free Software Foundation, either version 3 of the License, or9 * (at your option) any later version.10 *11 * QCAD is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14 * GNU General Public License for more details.15 *16 * You should have received a copy of the GNU General Public License17 * along with QCAD.18 */19function DimensionSettings() {20 // current unit (might originate from document, ini file or combo box):21 DimensionSettings.unit = undefined;22}23DimensionSettings.getPreferencesCategory = function(appPreferences) {24 if (appPreferences) {25 return [ qsTr("Defaults for New Drawings"), qsTr("Dimension Settings") ];26 }27 return [ qsTr("Dimension"), qsTr("Dimension Settings") ];28};29DimensionSettings.dimx = [30 // widget name, dxf variable, factor relative to dimtxt31 ["DIMTXT", RS.DIMTXT, 1.0],32 ["DIMEXE", RS.DIMEXE, 0.5],33 ["DIMEXO", RS.DIMEXO, 0.25],34 ["DIMGAP", RS.DIMGAP, 0.25],35 ["DIMASZ", RS.DIMASZ, 1.0],36 ["DIMSCALE", RS.DIMSCALE, undefined],37 ];38/**39 * Called when the user changed the drawing / global unit in another40 * preference page.41 */42DimensionSettings.updateUnit = function(unit) {43 var widgets = getWidgets(this.pageWidget);44 if (isNull(widgets)) {45 return;46 }47 DimensionSettings.unit = unit;48 // (re-)init unit labels:49 var unitSymbol = "";50 unitSymbol = RUnit.unitToName(DimensionSettings.unit);51 for (var i=1; i<=5; i++) {52 var w = widgets["DimUnit" + i];53 if (isNull(w)) {54 continue;55 }56 w.text = unitSymbol;57 }58 // update previews:59 DimensionSettings.updateLinearPreview(widgets);60 DimensionSettings.updateAngularPreview(widgets);61 DimensionSettings.updateLinearFormatFromUnit(widgets);62};63DimensionSettings.postInitPreferences = function(pageWidget, calledByPrefDialog, document) {64 if (isNull(document)) {65 var widgets = getWidgets(pageWidget);66 DimensionSettings.updateLinearPreview(widgets);67 DimensionSettings.updateAngularPreview(widgets);68 return;69 }70};71DimensionSettings.initPreferences = function(pageWidget, calledByPrefDialog, document, preferencesAction, unit) {72 var list;73 74 DimensionSettings.pageWidget = pageWidget;75 var settingsName = pageWidget.objectName;76 var widgets = getWidgets(pageWidget);77 var wlf = widgets["LinearFormat"];78 var wlstz = widgets["LinearShowTrailingZeros"];79 var wlp = widgets["LinearPrecision"];80 var waf = widgets["AngularFormat"];81 var wastz = widgets["AngularShowTrailingZeros"];82 var wap = widgets["AngularPrecision"];83 var wdf = widgets["DimensionFont"];84 var wdp = widgets["DecimalPoint"];85 var wfg = widgets["FontGroup"];86 var wkp = widgets["KeepProportions"];87 if (isNull(unit)) {88 // figure out what unit currently applies89 // (the one from the document, ini file or combo box):90 if (!isNull(document)) {91 // drawing unit:92 unit = document.getUnit();93 }94 else {95 // global unit:96 unit = RSettings.getIntValue("UnitSettings/Unit", RS.Millimeter);97 }98 // unit might have been changed by user:99 var unitCombo = objectFromPath("MainWindow::Unit");100 if (isComboBox(unitCombo)) {101 var u = unitCombo.itemData(unitCombo.currentIndex);102 if (!isNull(u)) {103 unit = u;104 }105 }106 }107 DimensionSettings.unit = unit;108 // connect keep proportions check box:109 if (!isNull(widgets["KeepProportions"])) {110 widgets["KeepProportions"].toggled.connect(function(onOff) {111 if (onOff) {112 DimensionSettings.keepProportions(widgets["DIMTXT"].getValue(), widgets);113 }114 });115 }116 if (!isNull(widgets["DIMTXT"])) {117 widgets["DIMTXT"].valueChanged.connect(function(value) {118 DimensionSettings.keepProportions(value, widgets);119 });120 }121 // decimal point:122 if (!isNull(wdp)) {123 wdp.addItem(". (" + qsTr("point") + ")", '.'.charCodeAt(0));124 wdp.addItem(", (" + qsTr("comma") + ")", ','.charCodeAt(0));125 wdp.addItem(" (" + qsTr("space") + ")", ' '.charCodeAt(0));126 wdp.currentIndex = wdp.findData(RSettings.getIntValue(settingsName + "/DecimalPoint", '.'.charCodeAt(0)));127 wdp["activated(int)"].connect(function() {128 DimensionSettings.updateLinearPreview(widgets);129 DimensionSettings.updateAngularPreview(widgets);130 });131 }132 // init linear dimension format combo boxes:133 if (!isNull(wlf)) {134 wlf.addItem(qsTr("Scientific"), RS.Scientific);135 wlf.addItem(qsTr("Decimal"), RS.Decimal);136 wlf.addItem(qsTr("Engineering"), RS.Engineering);137 wlf.addItem(qsTr("Architectural"), RS.ArchitecturalStacked);138 wlf.addItem(qsTr("Fractional"), RS.FractionalStacked);139 var defaultFormat = RUnit.isMetric(unit) ? RS.Decimal : RS.FractionalStacked;140 wlf.currentIndex = wlf.findData(RSettings.getIntValue(settingsName + "/LinearFormat", defaultFormat));141 // unsupported:142 //wlf.addItem(qsTr("Architectural"), RS.Architectural);143 //wlf.addItem(qsTr("Fractional"), RS.Fractional);144 //wlf.addItem(qsTr("Windows Desktop"), RS.WindowsDesktop);145 wlf["activated(int)"].connect(function() {146 DimensionSettings.updateLinearFormatFromUnit(widgets);147 DimensionSettings.updateLinearPrecision(widgets);148 DimensionSettings.updateLinearPreview(widgets);149 });150 }151 if (!isNull(wlstz)) {152 wlstz.stateChanged.connect(function() {153 DimensionSettings.updateLinearPreview(widgets);154 });155 }156 DimensionSettings.updateLinearPrecision(widgets);157 if (!isNull(wlp)) {158 wlp["activated(int)"].connect(function() {159 DimensionSettings.updateLinearPreview(widgets);160 });161 wlp.currentIndex = 4;162 }163 // init angular dimension format combo boxes:164 if (!isNull(waf)) {165 waf.addItem(qsTr("Decimal Degrees"), RS.DegreesDecimal);166 waf.addItem(qsTr("Deg/min/sec"), RS.DegreesMinutesSeconds);167 waf.addItem(qsTr("Gradians"), RS.Gradians);168 waf.addItem(qsTr("Radians"), RS.Radians);169 waf.addItem(qsTr("Surveyor's units"), RS.Surveyors);170 waf.currentIndex = waf.findData(RSettings.getIntValue(settingsName + "/AngularFormat", RS.DegreesDecimal));171 waf["activated(int)"].connect(function() {172 DimensionSettings.updateAngularPrecision(widgets);173 DimensionSettings.updateAngularPreview(widgets);174 });175 }176 if (!isNull(wastz)) {177 wastz.stateChanged.connect(function() {178 DimensionSettings.updateAngularPreview(widgets);179 });180 DimensionSettings.updateAngularPrecision(widgets);181 }182 if (!isNull(wap)) {183 wap["activated(int)"].connect(function() {184 DimensionSettings.updateAngularPreview(widgets, document);185 });186 wap.currentIndex = 0;187 }188 if (isNull(document)) {189 // update unit labels, preview:190 //DimensionSettings.updateUnit(unit);191 //DimensionSettings.updateLinearPrecision(widgets);192 //DimensionSettings.updateAngularPrecision(widgets);193 if (hasPlugin("DWG")) {194 if (!isNull(wdf)) {195 wdf.setProperty("Loaded", true);196 wdf.editable = false;197 initFontComboBox(wdf);198 var dimFont = RSettings.getStringValue(settingsName + "/DimensionFont", "Standard");199 activateFont(wdf, dimFont.isEmpty() ? "Standard" : dimFont);200 }201 }202 else {203 if (!isNull(wfg)) {204 wfg.visible = false;205 }206 }207 // other global preferences are initialized automatically208 return;209 }210 // init dimension settings from document:211 var keepProportions = true;212 var dimtxt = 0.0;213 var w;214 for (var i=0; i<DimensionSettings.dimx.length; i++) {215 var item = DimensionSettings.dimx[i];216 w = widgets[item[0]];217 if (isNull(w)) {218 continue;219 }220 var dimprop = document.getKnownVariable(item[1], 2.5*item[2]);221 if (item[1]===RS.DIMTXT) {222 dimtxt = dimprop;223 }224 else {225 if (Math.abs(dimprop-dimtxt*item[2]) > RS.PointTolerance) {226 keepProportions = false;227 }228 }229 //w.defaultValue = [w.text, w.getDefaultUnit()];230 w.defaultValue = w.text;231 w.setValue(dimprop);232 w.setProperty("Loaded", true);233 }234 // init keep proportions check box:235 if (!isNull(wkp)) {236 wkp.checked = keepProportions;237 wkp.setProperty("Loaded", true);238 }239 // init dimension arrow type:240 var dimblk = document.getKnownVariable(RS.DIMBLK, "");241 var dimtsz = document.getKnownVariable(RS.DIMTSZ, 0.0);242 if (dimblk.toUpperCase()==="ARCHTICK" || dimtsz > RS.PointTolerance) {243 if (!isNull(widgets["ArchitecturalTick"])) {244 widgets["ArchitecturalTick"].checked = true;245 }246 }247 else {248 if (!isNull(widgets["Arrow"])) {249 widgets["Arrow"].checked = true;250 }251 }252 if (!isNull(widgets["ArchitecturalTick"])) {253 widgets["ArchitecturalTick"].setProperty("Loaded", true);254 }255 if (!isNull(widgets["Arrow"])) {256 widgets["Arrow"].setProperty("Loaded", true);257 }258 // init linear dimension format:259 var dimlunit = document.getKnownVariable(RS.DIMLUNIT, RS.Decimal);260 //widgets["LinearFormat"].currentIndex = dimlunit-1;261 if (!isNull(wlf)) {262 wlf.currentIndex = wlf.findData(dimlunit);263 wlf.setProperty("Loaded", true);264 wlf["currentIndexChanged(int)"].connect(function(idx) {265 var lf = wlf.itemData(idx);266 preferencesAction.linearFormatUpdated(lf);267 });268 DimensionSettings.updateLinearPrecision(widgets);269 }270 // init linear dimension precision:271 var dimdec = document.getKnownVariable(RS.DIMDEC, 4);272 if (!isNull(wlp)) {273 wlp.currentIndex = dimdec;274 wlp.setProperty("Loaded", true);275 }276 // init angular dimension format:277 var dimaunit = document.getKnownVariable(RS.DIMAUNIT, RS.DegreesDecimal);278 if (!isNull(waf)) {279 //waf.currentIndex = dimaunit;280 waf.currentIndex = widgets["AngularFormat"].findData(dimaunit);281 waf.setProperty("Loaded", true);282 DimensionSettings.updateAngularPrecision(widgets);283 }284 // init angular dimension precision:285 var dimadec = document.getKnownVariable(RS.DIMADEC, 0);286 if (!isNull(wap)) {287 wap.currentIndex = dimadec;288 wap.setProperty("Loaded", true);289 }290 // show leading / trailing zeroes:291 var dimzin = document.getKnownVariable(RS.DIMZIN, 12);292 if (!isNull(wlstz)) {293 wlstz.checked = !((dimzin & 8) === 8);294 wlstz.setProperty("Loaded", true);295 }296 var dimazin = document.getKnownVariable(RS.DIMAZIN, 3);297 if (!isNull(wastz)) {298 wastz.checked = !((dimazin & 2) === 2);299 wastz.setProperty("Loaded", true);300 }301 // decimal separator:302 var dimdsep = document.getKnownVariable(RS.DIMDSEP, '.');303 if (!isNull(wdp)) {304 wdp.currentIndex = wdp.findData(dimdsep);305 wdp.setProperty("Loaded", true);306 }307 // update unit labels, preview:308 DimensionSettings.updateUnit(unit);309 if (hasPlugin("DWG")) {310 if (!isNull(wdf)) {311 wdf.setProperty("Loaded", true);312 wdf.editable = false;313 //wdf.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred);314 initFontComboBox(wdf);315 var dimFont = document.getDimensionFont();316 activateFont(wdf, dimFont.isEmpty() ? "Standard" : dimFont);317 }318 }319 else {320 if (!isNull(wfg)) {321 wfg.visible = false;322 }323 }324};325/**326 * Updates dimension sizes proportional to dimtxt.327 */328DimensionSettings.keepProportions = function(value, widgets) {329 if (widgets["KeepProportions"].checked) {330 for (var i=1; i<DimensionSettings.dimx.length; i++) {331 var item = DimensionSettings.dimx[i];332 if (!isNull(item[2])) {333 widgets[item[0]].setValue(value*item[2]);334 }335 }336 }337};338/**339 * Makes sure that linear format and drawing unit match.340 */341DimensionSettings.updateLinearFormatFromUnit = function(widgets) {342 var linearFormat = widgets["LinearFormat"].currentIndex+1;343 if ((DimensionSettings.unit!==RS.Inch && DimensionSettings.unit!==RS.Foot) &&344 (linearFormat===RS.ArchitecturalStacked || linearFormat===RS.Engineering)) {345 widgets["LinearFormat"].currentIndex = 1;346 DimensionSettings.showLinearFormatWarning();347 }348};349DimensionSettings.showLinearFormatWarning = function() {350 var appWin = EAction.getMainWindow();351 QMessageBox.warning(appWin,352 qsTr("Unit / Format"),353 qsTr("The drawing unit must be 'Inch' or 'Foot' to display dimension labels in "354 + "formats 'Architectural' or 'Engineering'. "355 + "Format changed to 'Decimal'."));356};357/**358 * Updates the linear precision combobox depending on the current359 * chosen format.360 */361DimensionSettings.updateLinearPrecision = function(widgets) {362 var wFormat = widgets["LinearFormat"];363 var wPrecision = widgets["LinearPrecision"];364 var index = wPrecision.currentIndex;365 wPrecision.clear();366 switch (wFormat.currentIndex+1) {367 case RS.Scientific:368 // scientific369 wPrecision.addItem("0E+00", 0);370 wPrecision.addItem("0.0E+00", 1);371 wPrecision.addItem("0.00E+00", 2);372 wPrecision.addItem("0.000E+00", 3);373 wPrecision.addItem("0.0000E+00", 4);374 wPrecision.addItem("0.00000E+00", 5);375 wPrecision.addItem("0.000000E+00", 6);376 wPrecision.addItem("0.0000000E+00", 7);377 wPrecision.addItem("0.00000000E+00", 8);378 break;379 case RS.Decimal:380 // decimal381 wPrecision.addItem("0", 0);382 wPrecision.addItem("0.0", 1);383 wPrecision.addItem("0.00", 2);384 wPrecision.addItem("0.000", 3);385 wPrecision.addItem("0.0000", 4);386 wPrecision.addItem("0.00000", 5);387 wPrecision.addItem("0.000000", 6);388 wPrecision.addItem("0.0000000", 7);389 wPrecision.addItem("0.00000000", 8);390 break;391 case RS.Engineering:392 // engineering:393 wPrecision.addItem("0'-0\"", 0);394 wPrecision.addItem("0'-0.0\"", 1);395 wPrecision.addItem("0'-0.00\"", 2);396 wPrecision.addItem("0'-0.000\"", 3);397 wPrecision.addItem("0'-0.0000\"", 4);398 wPrecision.addItem("0'-0.00000\"", 5);399 wPrecision.addItem("0'-0.000000\"", 6);400 wPrecision.addItem("0'-0.0000000\"", 7);401 wPrecision.addItem("0'-0.00000000\"", 8);402 break;403 case RS.ArchitecturalStacked:404 // architectural:405 wPrecision.addItem("0'-0\"", 0);406 wPrecision.addItem("0'-0 1/2\"", 1);407 wPrecision.addItem("0'-0 1/4\"", 2);408 wPrecision.addItem("0'-0 1/8\"", 3);409 wPrecision.addItem("0'-0 1/16\"", 4);410 wPrecision.addItem("0'-0 1/32\"", 5);411 wPrecision.addItem("0'-0 1/64\"", 6);412 wPrecision.addItem("0'-0 1/128\"", 7);413 wPrecision.addItem("0'-0 1/256\"", 8);414 break;415 case RS.FractionalStacked:416 // fractional417 wPrecision.addItem("0", 0);418 wPrecision.addItem("0 1/2", 1);419 wPrecision.addItem("0 1/4", 2);420 wPrecision.addItem("0 1/8", 3);421 wPrecision.addItem("0 1/16", 4);422 wPrecision.addItem("0 1/32", 5);423 wPrecision.addItem("0 1/64", 6);424 wPrecision.addItem("0 1/128", 7);425 wPrecision.addItem("0 1/256", 8);426 break;427 default:428 break;429 }430 if (index>=0) {431 wPrecision.currentIndex = index;432 }433};434/**435 * Updates the angular precision combobox depending on the current436 * chosen format.437 */438DimensionSettings.updateAngularPrecision = function(widgets) {439 var wFormat = widgets["AngularFormat"];440 var wPrecision = widgets["AngularPrecision"];441 var index = wPrecision.currentIndex;442 wPrecision.clear();443 switch (wFormat.currentIndex) {444 case 0:445 // decimal446 wPrecision.addItem("0", 0);447 wPrecision.addItem("0.0", 1);448 wPrecision.addItem("0.00", 2);449 wPrecision.addItem("0.000", 3);450 wPrecision.addItem("0.0000", 4);451 wPrecision.addItem("0.00000", 5);452 wPrecision.addItem("0.000000", 6);453 wPrecision.addItem("0.0000000", 7);454 wPrecision.addItem("0.00000000", 8);455 break;456 case 1:457 // deg/min/sec:458 wPrecision.addItem("0d", 0);459 wPrecision.addItem("0d00'", 1);460 wPrecision.addItem("0d00'00\"", 2);461 wPrecision.addItem("0d00'00.0\"", 3);462 wPrecision.addItem("0d00'00.00\"", 4);463 wPrecision.addItem("0d00'00.000\"", 5);464 wPrecision.addItem("0d00'00.0000\"", 6);465 break;466 case 2:467 // gradians:468 wPrecision.addItem("0g", 0);469 wPrecision.addItem("0.0g", 1);470 wPrecision.addItem("0.00g", 2);471 wPrecision.addItem("0.000g", 3);472 wPrecision.addItem("0.0000g", 4);473 wPrecision.addItem("0.00000g", 5);474 wPrecision.addItem("0.000000g", 6);475 wPrecision.addItem("0.0000000g", 7);476 wPrecision.addItem("0.00000000g", 8);477 break;478 case 3:479 // radians:480 wPrecision.addItem("0r", 0);481 wPrecision.addItem("0.0r", 1);482 wPrecision.addItem("0.00r", 2);483 wPrecision.addItem("0.000r", 3);484 wPrecision.addItem("0.0000r", 4);485 wPrecision.addItem("0.00000r", 5);486 wPrecision.addItem("0.000000r", 6);487 wPrecision.addItem("0.0000000r", 7);488 wPrecision.addItem("0.00000000r", 8);489 break;490 case 4:491 // surveyor's units:492 wPrecision.addItem("N 0d E", 0);493 wPrecision.addItem("N 0d00' E", 1);494 wPrecision.addItem("N 0d00'00\" E", 2);495 wPrecision.addItem("N 0d00'00.0\" E", 3);496 wPrecision.addItem("N 0d00'00.00\" E", 4);497 wPrecision.addItem("N 0d00'00.000\" E", 5);498 wPrecision.addItem("N 0d00'00.0000\" E", 6);499 break;500 default:501 break;502 }503 if (index>=0) {504 wPrecision.currentIndex = index;505 }506};507DimensionSettings.updateLinearPreview = function(widgets) {508 var wFormat = widgets["LinearFormat"];509 var showTrailingZeros = isNull(widgets["LinearShowTrailingZeros"]) ? false : widgets["LinearShowTrailingZeros"].checked;510 var dimsep = isNull(widgets["DecimalPoint"]) ? '.' : widgets["DecimalPoint"].itemData(widgets["DecimalPoint"].currentIndex);511 var value = 14.43112351;512 if (showTrailingZeros===true && RUnit.isMetric(DimensionSettings.unit)) {513 value = 10.0;514 }515 var prev;516 if (wFormat.currentIndex < 0 || widgets["LinearPrecision"].currentIndex < 0) {517 prev = "N/A";518 } else {519 prev = RUnit.formatLinear(value,520 DimensionSettings.unit,521 wFormat.itemData(wFormat.currentIndex),522 widgets["LinearPrecision"].currentIndex,523 false, false,524 showTrailingZeros,525 false,526 dimsep);527 if (prev==="") {528 prev = "N/A";529 }530 }531 widgets["LinearPreview"].text = prev;532};533DimensionSettings.updateAngularPreview = function(widgets) {534 var wFormat = widgets["AngularFormat"];535 var showTrailingZeros = widgets["AngularShowTrailingZeros"].checked;536 var dimsep = isNull(widgets["DecimalPoint"]) ? '.' : widgets["DecimalPoint"].itemData(widgets["DecimalPoint"].currentIndex);537 var value = RMath.deg2rad(37.15357578);538 if (showTrailingZeros===true) {539 value = RMath.deg2rad(60.0);540 }541 var prev;542 if (wFormat.currentIndex < 0543 || widgets["AngularPrecision"].currentIndex < 0) {544 prev = "N/A";545 } else { 546 prev = RUnit.formatAngle(value,547 wFormat.itemData(wFormat.currentIndex),548 widgets["AngularPrecision"].currentIndex,549 true, showTrailingZeros,550 dimsep);551 if (prev==="") {552 prev = "N/A";553 }554 }555 widgets["AngularPreview"].text = prev;556};557DimensionSettings.savePreferences = function(pageWidget, calledByPrefDialog, document, transaction) {558 var widgets = getWidgets(pageWidget);559 if (isNull(document)) {560 RSettings.setValue("DimensionSettings/DimensionFont", widgets["DimensionFont"].currentText);561 return;562 }563 for (var i=0; i<DimensionSettings.dimx.length; i++) {564 var item = DimensionSettings.dimx[i];565 document.setKnownVariable(item[1], widgets[item[0]].getValue(), transaction);566 widgets[item[0]].setProperty("Saved", true);567 }568 // dimension arrow type:569 if (widgets["ArchitecturalTick"].checked) {570 document.setKnownVariable(RS.DIMTSZ, document.getKnownVariable(RS.DIMASZ), transaction);571 //document.setKnownVariable(RS.DIMBLK, "ArchTick", transaction);572 }573 else {574 document.setKnownVariable(RS.DIMTSZ, 0.0, transaction);575 //document.setKnownVariable(RS.DIMBLK, "", transaction);576 }577 widgets["ArchitecturalTick"].setProperty("Saved", true);578 widgets["Arrow"].setProperty("Saved", true);579 // decimal point:580 document.setKnownVariable(RS.DIMDSEP, widgets["DecimalPoint"].itemData(widgets["DecimalPoint"].currentIndex), transaction);581 // dimension format / precision:582 document.setKnownVariable(RS.DIMLUNIT, widgets["LinearFormat"].currentIndex+1, transaction);583 document.setKnownVariable(RS.DIMDEC, widgets["LinearPrecision"].currentIndex, transaction);584 document.setKnownVariable(RS.DIMAUNIT, widgets["AngularFormat"].currentIndex, transaction);585 document.setKnownVariable(RS.DIMADEC, widgets["AngularPrecision"].currentIndex, transaction);586 document.setDimensionFont(widgets["DimensionFont"].currentText, transaction);587 // show leading / trailing zeroes:588 if (widgets["LinearShowTrailingZeros"].checked) {589 document.setKnownVariable(RS.DIMZIN, 0, transaction);590 }591 else {592 document.setKnownVariable(RS.DIMZIN, 8, transaction);593 }594 widgets["LinearShowTrailingZeros"].setProperty("Saved", true);595 if (widgets["AngularShowTrailingZeros"].checked) {596 document.setKnownVariable(RS.DIMAZIN, 0, transaction);597 }598 else {599 document.setKnownVariable(RS.DIMAZIN, 2, transaction);600 }601 widgets["AngularShowTrailingZeros"].setProperty("Saved", true);602 // force update of bounding box of dimension entities:603 var ids = document.queryAllEntities();604 for (i=0; i<ids.length; i++) {605 var entityId = ids[i];606 var entity = document.queryEntity(entityId);607 if (!isDimensionEntity(entity)) {608 // ignore non dimension entities:609 continue;610 }611 document.removeFromSpatialIndex(entity);612 entity.update();613 document.addToSpatialIndex(entity);614 }...

Full Screen

Full Screen

settings_test.js

Source:settings_test.js Github

copy

Full Screen

1/* global Settings, ConfigManager, Formatting, MocksHelper, MockCommon,2 MockConfigManager, MockCostControl, SimManager3*/4'use strict';5require('/test/unit/mock_date.js');6require('/test/unit/mock_moz_l10n.js');7require('/shared/test/unit/mocks/mock_lazy_loader.js');8require('/test/unit/mock_debug.js');9require('/test/unit/mock_common.js');10require('/shared/test/unit/load_body_html_helper.js');11require('/js/view_manager.js');12require('/js/views/BalanceView.js');13require('/test/unit/mock_cost_control.js');14require('/test/unit/mock_config_manager.js');15require('/js/utils/formatting.js');16require('/js/views/BalanceLowLimitView.js');17require('/js/views/ResetMenuDialog.js');18require('/js/views/ConfirmDialog.js');19require('/js/settings/limitdialog.js');20require('/js/settings/autosettings.js');21require('/js/settings/settings.js');22require('/js/sim_manager.js');23require('/js/utils/toolkit.js');24require('/shared/js/component_utils.js');25require('/shared/elements/gaia_switch/script.js');26require('/shared/elements/gaia-header/dist/gaia-header.js');27require('/shared/elements/gaia_subheader/script.js');28var realMozL10n,29 realAddNetworkUsageAlarm,30 realDate;31if (!window.navigator.mozL10n) {32 window.navigator.mozL10n = null;33}34if (!window.realAddNetworkUsageAlarm) {35 window.realAddNetworkUsageAlarm = null;36}37var MocksHelperForUnitTest = new MocksHelper([38 'LazyLoader',39 'Common',40 'CostControl',41 'ConfigManager'42]).init();43suite('Settings Test Suite >', function() {44 MocksHelperForUnitTest.attachTestHelpers();45 var mobileUsage, wifiUsage;46 var domSelectorsForLayout = [47 {48 name: 'planTypeSelector',49 selector: '#plantype-settings',50 isHiddenOnPostpaidLayout: false,51 isHiddenOnPrepaidLayout: false,52 isHiddenOnDataUsageOnlyLayout: true53 }, {54 name: 'phoneActivitySettings',55 selector: '#phone-activity-settings + .settings',56 isHiddenOnPostpaidLayout: false,57 isHiddenOnPrepaidLayout: true,58 isHiddenOnDataUsageOnlyLayout: true59 }, {60 name: 'phoneActivityTitle',61 selector: '#phone-activity-settings',62 isHiddenOnPostpaidLayout: false,63 isHiddenOnPrepaidLayout: true,64 isHiddenOnDataUsageOnlyLayout: true65 }, {66 name: 'balanceTitle',67 selector: '#balance-settings',68 isHiddenOnPostpaidLayout: true,69 isHiddenOnPrepaidLayout: false,70 isHiddenOnDataUsageOnlyLayout: true71 }, {72 name: 'balanceSettings',73 selector: '#balance-settings + .settings',74 isHiddenOnPostpaidLayout: true,75 isHiddenOnPrepaidLayout: false,76 isHiddenOnDataUsageOnlyLayout: true77 }, {78 name: 'reportsTitle',79 selector: '#phone-internet-settings',80 isHiddenOnPostpaidLayout: false,81 isHiddenOnPrepaidLayout: true,82 isHiddenOnDataUsageOnlyLayout: false83 }84 ];85 suiteSetup(function() {86 window.Common = new MockCommon();87 realMozL10n = window.navigator.mozL10n;88 window.navigator.mozL10n = window.MockMozL10n;89 realAddNetworkUsageAlarm = window.addNetworkUsageAlarm;90 window.addNetworkUsageAlarm = function() {};91 realDate = window.Date;92 });93 setup(function() {94 var now = new Date(2014, 5, 24); // 2014-06-2495 window.Date = new window.MockDateFactory(now);96 loadBodyHTML('/settings.html');97 // Data usage elements98 mobileUsage = document.querySelector('#mobile-data-usage > span');99 wifiUsage = document.querySelector('#wifi-data-usage > span');100 });101 teardown(function() {102 window.Date = realDate;103 window.location.hash = '';104 });105 suiteTeardown(function() {106 window.navigator.mozL10n = realMozL10n;107 window.addNetworkUsageAlarm = realAddNetworkUsageAlarm;108 });109 function setupApplicationMode(applicationMode, fakeConfiguration) {110 window.ConfigManager = new MockConfigManager({111 fakeConfiguration: fakeConfiguration,112 fakeSettings: {113 dataLimit: true,114 dataLimitValue: 40,115 dataLimitUnit: 'MB',116 lowLimit: true,117 trackingPeriod: 'monthly',118 resetTime: 1119 },120 applicationMode: applicationMode121 });122 }123 function setupPrepaidMode() {124 var fakeConfiguration = {125 default_low_limit_threshold: 3,126 credit: { currency: 'R$' }127 };128 setupApplicationMode('PREPAID', fakeConfiguration);129 }130 function setupTestScenario(costControlConfig, applicationMode) {131 window.CostControl = new MockCostControl(costControlConfig);132 window.ConfigManager = new MockConfigManager({133 fakeConfiguration: {134 default_low_limit_threshold: 3,135 credit: { currency: 'R$' }136 },137 fakeSettings: {138 dataLimit: true,139 dataLimitValue: 40,140 dataLimitUnit: 'MB',141 lowLimit: true,142 lastTelephonyActivity: 3456143 },144 applicationMode: applicationMode145 });146 }147 function triggerEvent(element, eventName) {148 var event = document.createEvent('HTMLEvents');149 event.initEvent(eventName, true, true);150 element.dispatchEvent(event);151 }152 var requestToCheckLayout = function(assertingFunction, done) {153 return {154 request: function(requestedObj, callback) {155 (typeof assertingFunction === 'function') && assertingFunction(done);156 }157 };158 };159 function assertPostpaidLayout(done) {160 domSelectorsForLayout.forEach(function checkVisibility(element) {161 var domElement = document.querySelector(element.selector);162 assert.equal(domElement.hidden, element.isHiddenOnPostpaidLayout,163 'The visibility of ' + element.name + ' is incorrect');164 });165 done();166 }167 function assertPrepaidLayout(done) {168 domSelectorsForLayout.forEach(function checkVisibility(element) {169 var domElement = document.querySelector(element.selector);170 assert.equal(domElement.hidden, element.isHiddenOnPrepaidLayout,171 'The visibility of ' + element.name + ' is incorrect');172 });173 done();174 }175 function assertDataUsageOnlyLayout(done) {176 domSelectorsForLayout.forEach(function checkVisibility(element) {177 var domElement = document.querySelector(element.selector);178 assert.equal(domElement.hidden, element.isHiddenOnDataUsageOnlyLayout,179 'The visibility of ' + element.name + 'is incorrect');180 });181 done();182 }183 test('Layout postpaid mode is correctly loaded', function(done) {184 var costControlConfig = requestToCheckLayout(assertPostpaidLayout, done);185 setupTestScenario(costControlConfig, 'POSTPAID');186 Settings.initialize();187 });188 test('Layout prepaid mode is correctly loaded', function(done) {189 var costControlConfig = requestToCheckLayout(assertPrepaidLayout, done);190 setupTestScenario(costControlConfig, 'PREPAID');191 Settings.initialize();192 });193 test('Layout data_usage_only mode is correctly loaded', function(done) {194 var costControlConfig = requestToCheckLayout(assertDataUsageOnlyLayout,195 done);196 setupTestScenario(costControlConfig, 'DATA_USAGE_ONLY');197 Settings.initialize();198 });199 test('updateDataUsage works correctly', function(done) {200 setupPrepaidMode();201 var lastDataUsage = {202 timestamp: new Date(),203 today: new Date(),204 wifi: {205 total: 222206 },207 mobile: {208 total: 333209 }210 };211 sinon.stub(Settings, 'updateUI', function() {212 ConfigManager.mTriggerCallback('lastDataUsage', lastDataUsage,213 {lastCompleteDataReset: new Date() });214 var mobileDataUsage = Formatting.formatData(215 Formatting.roundData(lastDataUsage.mobile.total));216 var wifiDataUsage = Formatting.formatData(217 Formatting.roundData(lastDataUsage.wifi.total));218 assert.equal(mobileUsage.textContent, mobileDataUsage);219 assert.equal(wifiUsage.textContent, wifiDataUsage);220 Settings.updateUI.restore();221 ConfigManager.mRemoveObservers();222 done();223 });224 Settings.initialize();225 });226 test('Default values for reset time (monthly)', function(done) {227 setupPrepaidMode();228 sinon.stub(Settings, 'updateUI', function() {229 var today = new Date();230 // Initial value for tracking period is monthly and for resetTime 1231 // Force the initialization of the resetTime field232 ConfigManager.mTriggerCallback('trackingPeriod');233 assert.equal(ConfigManager.option('resetTime'), today.getDate());234 Settings.updateUI.restore();235 done();236 });237 Settings.initialize();238 });239 test('Default values for reset time (weekly)', function(done) {240 setupPrepaidMode();241 sinon.stub(Settings, 'updateUI', function() {242 var today = new Date();243 // Initial value for tracking period is monthly and for resetTime 1244 // Change tracking period to weekly245 ConfigManager.option('trackingPeriod', 'weekly');246 ConfigManager.mTriggerCallback('trackingPeriod', 'weekly');247 assert.equal(ConfigManager.option('trackingPeriod'), 'weekly');248 assert.equal(ConfigManager.option('resetTime'), today.getDay());249 Settings.updateUI.restore();250 done();251 });252 Settings.initialize();253 });254 suite('Data Limit Configurator Test Suite >', function() {255 var dataLimitDialog, dataLimitInput, dataLimitOkButton, limitUnitValue,256 dataLimitSwitchUnitButton, dataLimitHeader;257 var evtInput = new CustomEvent('input', {});258 setup(function() {259 dataLimitDialog = document.getElementById('data-limit-dialog');260 dataLimitInput = dataLimitDialog.querySelector('input');261 dataLimitOkButton = dataLimitDialog.querySelector('button.recommend');262 dataLimitHeader = document.getElementById('limit-dialog-header');263 dataLimitSwitchUnitButton = dataLimitDialog.264 querySelector('.switch-unit-button');265 limitUnitValue = dataLimitSwitchUnitButton.querySelector('span.tag');266 });267 function initDataLimitDialog() {268 // Init the dataLimitDialog values269 ConfigManager.mTriggerCallback('dataLimitValue', 40);270 ConfigManager.mTriggerCallback('dataLimitUnit', 'MB');271 // load Limit dialog272 var dataLimitButton =273 document.querySelector('[data-widget-type=data-limit]');274 triggerEvent(dataLimitButton, 'click');275 }276 function assertDataLimitInputInvalid() {277 assert.isTrue(dataLimitInput.classList.contains('error'));278 assert.isTrue(dataLimitOkButton.disabled);279 }280 function assertDataLimitInputValid() {281 assert.isFalse(dataLimitInput.classList.contains('error'));282 assert.isFalse(dataLimitOkButton.disabled);283 }284 suite('Valid Values >', function() {285 test('Real values', function(done) {286 setupPrepaidMode();287 sinon.stub(Settings, 'updateUI', function() {288 initDataLimitDialog();289 dataLimitInput.value = '912.05';290 dataLimitInput.dispatchEvent(evtInput);291 assertDataLimitInputValid();292 dataLimitInput.value = '0.5';293 dataLimitInput.dispatchEvent(evtInput);294 assertDataLimitInputValid();295 triggerEvent(dataLimitHeader, 'action');296 Settings.updateUI.restore();297 done();298 });299 Settings.initialize();300 });301 test('Atypical values', function(done) {302 setupPrepaidMode();303 sinon.stub(Settings, 'updateUI', function() {304 initDataLimitDialog();305 // bug 1073340 - 0.07 produces a decimal multiplication overflow306 dataLimitInput.value = '0.07';307 dataLimitInput.dispatchEvent(evtInput);308 assertDataLimitInputValid();309 triggerEvent(dataLimitHeader, 'action');310 Settings.updateUI.restore();311 done();312 });313 Settings.initialize();314 });315 test('Numbers without significant digits', function(done) {316 setupPrepaidMode();317 sinon.stub(Settings, 'updateUI', function() {318 initDataLimitDialog();319 dataLimitInput.value = '.1';320 dataLimitInput.dispatchEvent(evtInput);321 assertDataLimitInputValid();322 dataLimitInput.value = '.78';323 dataLimitInput.dispatchEvent(evtInput);324 assertDataLimitInputValid();325 triggerEvent(dataLimitHeader, 'action');326 Settings.updateUI.restore();327 done();328 });329 Settings.initialize();330 });331 test('Natural numbers', function(done) {332 setupPrepaidMode();333 sinon.stub(Settings, 'updateUI', function() {334 initDataLimitDialog();335 dataLimitInput.value = '120';336 dataLimitInput.dispatchEvent(evtInput);337 assertDataLimitInputValid();338 dataLimitInput.value = '0000456';339 dataLimitInput.dispatchEvent(evtInput);340 assertDataLimitInputValid();341 triggerEvent(dataLimitHeader, 'action');342 Settings.updateUI.restore();343 done();344 });345 Settings.initialize();346 });347 test('Natural numbers with no significant zeros', function(done) {348 setupPrepaidMode();349 sinon.stub(Settings, 'updateUI', function() {350 initDataLimitDialog();351 dataLimitInput.value = '0000456';352 dataLimitInput.dispatchEvent(evtInput);353 assertDataLimitInputValid();354 triggerEvent(dataLimitHeader, 'action');355 Settings.updateUI.restore();356 done();357 });358 Settings.initialize();359 });360 });361 suite('Invalid values >', function() {362 test('Negative Values', function(done) {363 setupPrepaidMode();364 sinon.stub(Settings, 'updateUI', function() {365 initDataLimitDialog();366 dataLimitInput.value = '-12.456';367 dataLimitInput.dispatchEvent(evtInput);368 assertDataLimitInputInvalid();369 triggerEvent(dataLimitHeader, 'action');370 Settings.updateUI.restore();371 done();372 });373 Settings.initialize();374 });375 test('Separator invalid', function(done) {376 setupPrepaidMode();377 sinon.stub(Settings, 'updateUI', function() {378 initDataLimitDialog();379 dataLimitInput.value = '12,456';380 dataLimitInput.dispatchEvent(evtInput);381 assertDataLimitInputInvalid();382 triggerEvent(dataLimitHeader, 'action');383 Settings.updateUI.restore();384 done();385 });386 Settings.initialize();387 });388 test('Too decimal Separators', function(done) {389 setupPrepaidMode();390 sinon.stub(Settings, 'updateUI', function() {391 initDataLimitDialog();392 dataLimitInput.value = '124..56';393 dataLimitInput.dispatchEvent(evtInput);394 assertDataLimitInputInvalid();395 triggerEvent(dataLimitHeader, 'action');396 Settings.updateUI.restore();397 done();398 });399 Settings.initialize();400 });401 test('Not numeric', function(done) {402 setupPrepaidMode();403 sinon.stub(Settings, 'updateUI', function() {404 initDataLimitDialog();405 dataLimitInput.value = 'a';406 dataLimitInput.dispatchEvent(evtInput);407 assertDataLimitInputInvalid();408 triggerEvent(dataLimitHeader, 'action');409 Settings.updateUI.restore();410 done();411 });412 Settings.initialize();413 });414 test('Too long', function(done) {415 setupPrepaidMode();416 sinon.stub(Settings, 'updateUI', function() {417 initDataLimitDialog();418 dataLimitInput.value = '12456';419 dataLimitInput.dispatchEvent(evtInput);420 assertDataLimitInputInvalid();421 triggerEvent(dataLimitHeader, 'action');422 Settings.updateUI.restore();423 done();424 });425 Settings.initialize();426 });427 });428 suite('Automatic input corrections >', function() {429 test('No action ', function(done) {430 setupPrepaidMode();431 sinon.stub(Settings, 'updateUI', function() {432 initDataLimitDialog();433 dataLimitInput.value = '12.34';434 dataLimitInput.dispatchEvent(evtInput);435 assert.equal(dataLimitInput.value, '12.34');436 dataLimitInput.value = '9912';437 dataLimitInput.dispatchEvent(evtInput);438 assert.equal(dataLimitInput.value, '9912');439 triggerEvent(dataLimitHeader, 'action');440 Settings.updateUI.restore();441 done();442 });443 Settings.initialize();444 });445 test('No corrections with invalid entries', function(done) {446 setupPrepaidMode();447 this.sinon.stub(Settings, 'updateUI', function() {448 initDataLimitDialog();449 dataLimitInput.value = '0';450 dataLimitInput.dispatchEvent(evtInput);451 assert.equal(dataLimitInput.value, '0');452 assertDataLimitInputInvalid();453 dataLimitInput.value = '0.';454 dataLimitInput.dispatchEvent(evtInput);455 assert.equal(dataLimitInput.value, '0.');456 assertDataLimitInputInvalid();457 dataLimitInput.value = '0.0';458 dataLimitInput.dispatchEvent(evtInput);459 assert.equal(dataLimitInput.value, '0.0');460 assertDataLimitInputInvalid();461 dataLimitInput.value = '.';462 dataLimitInput.dispatchEvent(evtInput);463 assert.equal(dataLimitInput.value, '.');464 assertDataLimitInputInvalid();465 dataLimitInput.value = '.0';466 dataLimitInput.dispatchEvent(evtInput);467 assert.equal(dataLimitInput.value, '.0');468 assertDataLimitInputInvalid();469 triggerEvent(dataLimitHeader, 'action');470 done();471 });472 Settings.initialize();473 });474 test('Removing left zeros ', function(done) {475 setupPrepaidMode();476 sinon.stub(Settings, 'updateUI', function() {477 initDataLimitDialog();478 dataLimitInput.value = '02.04';479 dataLimitInput.dispatchEvent(evtInput);480 assert.equal(dataLimitInput.value, '2.04');481 dataLimitInput.value = '007';482 dataLimitInput.dispatchEvent(evtInput);483 assert.equal(dataLimitInput.value, '7');484 dataLimitInput.value = '000012.31';485 dataLimitInput.dispatchEvent(evtInput);486 assert.equal(dataLimitInput.value, '12.31');487 triggerEvent(dataLimitHeader, 'action');488 Settings.updateUI.restore();489 done();490 });491 Settings.initialize();492 });493 test('Removing right zeros ', function(done) {494 setupPrepaidMode();495 sinon.stub(Settings, 'updateUI', function() {496 initDataLimitDialog();497 dataLimitInput.value = '77.60';498 dataLimitInput.dispatchEvent(evtInput);499 assert.equal(dataLimitInput.value, '77.6');500 dataLimitInput.value = '442.01000';501 dataLimitInput.dispatchEvent(evtInput);502 assert.equal(dataLimitInput.value, '442.01');503 triggerEvent(dataLimitHeader, 'action');504 Settings.updateUI.restore();505 done();506 });507 Settings.initialize();508 });509 test('Removing both sides ', function(done) {510 setupPrepaidMode();511 sinon.stub(Settings, 'updateUI', function() {512 initDataLimitDialog();513 dataLimitInput.value = '012.010';514 dataLimitInput.dispatchEvent(evtInput);515 assert.equal(dataLimitInput.value, '12.01');516 dataLimitInput.value = '0000062.1000';517 dataLimitInput.dispatchEvent(evtInput);518 assert.equal(dataLimitInput.value, '62.1');519 triggerEvent(dataLimitHeader, 'action');520 Settings.updateUI.restore();521 done();522 });523 Settings.initialize();524 });525 test('Fill with left zero ', function(done) {526 setupPrepaidMode();527 sinon.stub(Settings, 'updateUI', function() {528 initDataLimitDialog();529 dataLimitInput.value = '.31';530 dataLimitInput.dispatchEvent(evtInput);531 assert.equal(dataLimitInput.value, '0.31');532 triggerEvent(dataLimitHeader, 'action');533 Settings.updateUI.restore();534 done();535 });536 Settings.initialize();537 });538 });539 test('dataLimitConfigurer Cancel button behaviour', function(done) {540 setupPrepaidMode();541 sinon.stub(Settings, 'updateUI', function() {542 initDataLimitDialog();543 dataLimitInput.value = '124.56';544 dataLimitInput.dispatchEvent(evtInput);545 // Cancel not update the Config values546 assert.equal(ConfigManager.option('dataLimitUnit'), 'MB');547 assert.equal(ConfigManager.option('dataLimitValue'), '40');548 Settings.updateUI.restore();549 done();550 });551 Settings.initialize();552 });553 test('dataLimitConfigurer OK button behaviour', function(done) {554 setupPrepaidMode();555 sinon.stub(Settings, 'updateUI', function() {556 initDataLimitDialog();557 assert.equal(ConfigManager.option('dataLimitUnit'), 'MB');558 assert.equal(ConfigManager.option('dataLimitValue'), '40');559 // Update the dataLimit560 dataLimitInput.value = '124.56';561 dataLimitInput.dispatchEvent(evtInput);562 assert.equal(dataLimitSwitchUnitButton.getAttribute('data-l10n-id'),563 'unit-MB');564 assert.equal(limitUnitValue.getAttribute('data-l10n-id'), 'MB');565 triggerEvent(dataLimitSwitchUnitButton, 'click');566 assert.equal(dataLimitSwitchUnitButton.getAttribute('data-l10n-id'),567 'unit-GB');568 assert.equal(limitUnitValue.getAttribute('data-l10n-id'), 'GB');569 sinon.stub(SimManager, 'requestDataSimIcc', function() {});570 triggerEvent(dataLimitOkButton, 'click');571 assert.equal(ConfigManager.option('dataLimitUnit'), 'GB');572 assert.equal(ConfigManager.option('dataLimitValue'), '124.56');573 SimManager.requestDataSimIcc.restore();574 Settings.updateUI.restore();575 done();576 });577 Settings.initialize();578 });579 });...

Full Screen

Full Screen

jquery.notify-better.js

Source:jquery.notify-better.js Github

copy

Full Screen

1/* ===========================================================2 * jquery-notify-better.js v13 * ===========================================================4 * Copyright 2013 Pete Rojwongsuriya.5 * http://www.thepetedesign.com6 *7 * An all in one jQuery plugin that let you 8 * change your favicon and browser title to reflect new notifications9 * Note: Works on Firefox and Chrome only.10 *11 * Credit: Remy Sharp for the Dynamic Favicon, Jeff B from StackOverflow for AbbrNum function12 * https://github.com/peachananr/notify-better13 *14 * ========================================================== */15!function($){16 17 var defaults = {18 url: false,19 interval: 5000,20 overrideAjax: false,21 updateTitle: false,22 updateFavicon: {23 id: "favicon",24 textColor: "#fff",25 backgroundColor: "#e74c3c",26 location: "full",27 shape: "square"28 },29 done: function(){}30 };31 32 function abbrNum(number, decPlaces) {33 decPlaces = Math.pow(10,decPlaces);34 var abbrev = [ "k", "m", "b", "t" ];35 for (var i=abbrev.length-1; i>=0; i--) {36 var size = Math.pow(10,(i+1)*3);37 if(size <= number) {38 number = Math.round(number*decPlaces/size)/decPlaces;39 if((number == 1000) && (i < abbrev.length - 1)) {40 number = 1;41 i++;42 }43 number += abbrev[i];44 break;45 }46 }47 return number;48 }49 50 $.fn.notify_better = function(options){51 var settings = $.extend({}, defaults, options),52 el = $(this);53 54 titleclear = function() {55 var matches, regex;56 regex = /\(([0-9]+)\)/;57 matches = document.title;58 if (matches !== null) {59 document.title = document.title.replace(regex, '');60 }61 }62 63 $.fn.clear = function(){64 titleclear();65 if ($("#" + settings.updateFavicon.id).data("initial")){66 init = $("#" + settings.updateFavicon.id).attr("data-initial")67 }else {68 init = $("#" + settings.updateFavicon.id).attr("href")69 }70 $("#" + settings.updateFavicon.id).attr("href", init)71 $("#new-favicon").remove()72 $("<link id='new-favicon' type='image/x-icon' href='" + init + "' rel='shortcut icon'>").appendTo("head")73 $(this).hide().html("")74 }75 76 changeFavicon = function(fx) {77 if (fx > 0) {78 var canvas = document.createElement('canvas'),79 ctx,80 img = document.createElement('img'),81 link = document.getElementById(settings.updateFavicon.id).cloneNode(true);82 if (fx > 99) fx = 9983 if (canvas.getContext) {84 canvas.height = canvas.width = 16;85 ctx = canvas.getContext('2d');86 img.onload = function () { 87 ctx.drawImage(this, 0, 0);88 switch (settings.updateFavicon.location) {89 case "full":90 if(settings.updateFavicon.shape == "square") {91 ctx.fillStyle = settings.updateFavicon.backgroundColor;92 ctx.fillRect(0, 0, 16, 16);93 }else {94 var centerX = canvas.width / 2;95 var centerY = canvas.height / 2;96 var radius = 8;97 ctx.beginPath();98 ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);99 ctx.fillStyle = settings.updateFavicon.backgroundColor;100 ctx.fill();101 }102 ctx.textAlign = "center";103 ctx.font = 'bold 10px "helvetica", sans-serif';104 ctx.fillStyle = settings.updateFavicon.textColor;105 ctx.fillText(fx, 8, 12);106 break;107 case "se":108 if(settings.updateFavicon.shape == "square") {109 ctx.fillStyle = settings.updateFavicon.backgroundColor;110 ctx.fillRect(5, 5, 16, 16);111 }else {112 var radius = 6;113 ctx.beginPath();114 ctx.arc(12, 12, radius, 0, 2 * Math.PI, false);115 ctx.fillStyle = settings.updateFavicon.backgroundColor;116 ctx.fill();117 }118 ctx.font = 'bold 8px "helvetica", sans-serif';119 ctx.textAlign = "right";120 ctx.fillStyle = settings.updateFavicon.textColor;121 ctx.fillText(fx, 15, 15);122 break;123 case "ne":124 if(settings.updateFavicon.shape == "square") {125 ctx.fillStyle = settings.updateFavicon.backgroundColor;126 ctx.fillRect(5, 0, 11, 10);127 }else {128 var radius = 6;129 ctx.beginPath();130 ctx.arc(12, 3, radius, 0, 2 * Math.PI, false);131 ctx.fillStyle = settings.updateFavicon.backgroundColor;132 ctx.fill();133 }134 ctx.font = 'bold 8px "helvetica", sans-serif';135 ctx.textAlign = "right";136 ctx.fillStyle = settings.updateFavicon.textColor;137 ctx.fillText(fx, 15, 7);138 break;139 case "nw":140 if(settings.updateFavicon.shape == "square") {141 ctx.fillStyle = settings.updateFavicon.backgroundColor;142 ctx.fillRect(0, 0, 11, 10);143 }else {144 var radius = 6;145 ctx.beginPath();146 ctx.arc(5, 3, radius, 0, 2 * Math.PI, false);147 ctx.fillStyle = settings.updateFavicon.backgroundColor;148 ctx.fill();149 }150 ctx.font = 'bold 8px "helvetica", sans-serif';151 ctx.textAlign = "left";152 ctx.fillStyle = settings.updateFavicon.textColor;153 ctx.fillText(fx, 1, 7);154 break;155 case "sw":156 if(settings.updateFavicon.shape == "square") {157 ctx.fillStyle = settings.updateFavicon.backgroundColor;158 ctx.fillRect(0, 5, 11, 11);159 }else {160 var radius = 6;161 ctx.beginPath();162 ctx.arc(5, 12, radius, 0, 2 * Math.PI, false);163 ctx.fillStyle = settings.updateFavicon.backgroundColor;164 ctx.fill();165 }166 ctx.font = 'bold 8px "helvetica", sans-serif';167 ctx.textAlign = "left";168 ctx.fillStyle = settings.updateFavicon.textColor;169 ctx.fillText(fx, 1, 14);170 break;171 }172 var init = $("#" + settings.updateFavicon.id).attr("href")173 174 if ($("#" + settings.updateFavicon.id).data("initial")){175 $("#" + settings.updateFavicon.id).attr("href", canvas.toDataURL('image/png'));176 }else {177 $("#" + settings.updateFavicon.id).attr("data-initial", init).attr("href", canvas.toDataURL('image/png'));178 }179 180 $("#new-favicon").remove()181 $("<link id='new-favicon' type='image/x-icon' href='" + canvas.toDataURL('image/png') + "' rel='shortcut icon'>").appendTo("head")182 183 };184 img.src = 'favicon.png';185 }186 }187 };188 189 190 getNotification = function() {191 if (settings.overrideAjax != false) {192 settings.overrideAjax()193 }else {194 $.ajax({195 url: settings.url,196 }).done(function(data, textStatus, jqXHR) {197 titleclear();198 notif = eval(data)199 el.hide().html(notif).fadeIn("slow");200 if (settings.updateTitle == true) {201 document.title = "(" + notif + ") " + document.title 202 }203 if(settings.updateFavicon != false ) changeFavicon(notif)204 settings.done()205 });206 }207 }208 if(settings.interval == 0 || settings.interval == false) {209 getNotification();210 }else{211 setInterval(function() {212 getNotification()213 }, settings.interval);214 }215 }216 ...

Full Screen

Full Screen

_settings.js

Source:_settings.js Github

copy

Full Screen

1import { updateLanguage } from '../languages';2import {3 getLanguage,4 getNativeCurrency,5 saveLanguage,6 saveNativeCurrency,7} from '../handlers/commonStorage';8import { getNetworkFromChainId, getChainIdFromNetwork } from '../helpers/utilities';9import { web3SetHttpProvider } from '../handlers/web3_ethers';10// -- Constants ------------------------------------------------------------- //11const SETTINGS_UPDATE_NETWORK = 'settings/SETTINGS_UPDATE_NETWORK';12const SETTINGS_UPDATE_CHAIN_ID = 'settings/SETTINGS_UPDATE_CHAIN_ID';13const SETTINGS_UPDATE_SETTINGS_ADDRESS = 'settings/SETTINGS_UPDATE_SETTINGS_ADDRESS';14const SETTINGS_UPDATE_NATIVE_CURRENCY_SUCCESS = 'settings/SETTINGS_UPDATE_NATIVE_CURRENCY_SUCCESS';15const SETTINGS_UPDATE_NATIVE_CURRENCY_FAILURE = 'settings/SETTINGS_UPDATE_NATIVE_CURRENCY_FAILURE';16const SETTINGS_UPDATE_LANGUAGE_SUCCESS = 'settings/SETTINGS_UPDATE_LANGUAGE_SUCCESS';17const SETTINGS_UPDATE_LANGUAGE_FAILURE = 'settings/SETTINGS_UPDATE_LANGUAGE_FAILURE';18// -- Actions --------------------------------------------------------------- //19export const settingsInitializeState = () => dispatch => {20 getLanguage().then(language => {21 dispatch({22 type: SETTINGS_UPDATE_LANGUAGE_SUCCESS,23 payload: language24 });25 }).catch(error => {26 dispatch({27 type: SETTINGS_UPDATE_LANGUAGE_FAILURE28 });29 });30 getNativeCurrency().then(nativeCurrency => {31 dispatch({32 type: SETTINGS_UPDATE_NATIVE_CURRENCY_SUCCESS,33 payload: nativeCurrency,34 });35 }).catch(error => {36 dispatch({37 type: SETTINGS_UPDATE_NATIVE_CURRENCY_FAILURE38 });39 });40};41export const settingsUpdateAccountAddress = (accountAddress, accountType) => (42 dispatch,43 getState,44) => {45 dispatch({46 type: SETTINGS_UPDATE_SETTINGS_ADDRESS,47 payload: { accountAddress, accountType },48 });49};50export const settingsUpdateNetwork = network => dispatch => {51 const chainId = getChainIdFromNetwork(network);52 web3SetHttpProvider(network);53 dispatch({54 payload: { chainId, network },55 type: SETTINGS_UPDATE_NETWORK,56 });57};58export const settingsUpdateChainId = chainId => dispatch => {59 const network = getNetworkFromChainId(chainId);60 web3SetHttpProvider(network);61 dispatch({62 payload: { chainId, network },63 type: SETTINGS_UPDATE_CHAIN_ID,64 });65};66export const settingsChangeLanguage = language => dispatch => {67 updateLanguage(language);68 saveLanguage(language).then( () => {69 dispatch({70 type: SETTINGS_UPDATE_LANGUAGE_SUCCESS,71 payload: language,72 });73 }).catch(error => {74 dispatch({75 type: SETTINGS_UPDATE_LANGUAGE_FAILURE,76 });77 });78};79export const settingsChangeNativeCurrency = nativeCurrency => (80 dispatch,81) => {82 saveNativeCurrency(nativeCurrency).then(() => {83 dispatch({84 type: SETTINGS_UPDATE_NATIVE_CURRENCY_SUCCESS,85 payload: nativeCurrency,86 });87 }).catch(error => {88 dispatch({89 type: SETTINGS_UPDATE_NATIVE_CURRENCY_FAILURE,90 });91 });92};93// -- Reducer --------------------------------------------------------------- //94export const INITIAL_STATE = {95 accountType: '',96 accountAddress: '',97 language: 'en',98 nativeCurrency: 'USD',99 chainId: 1,100 network: 'mainnet',101};102export default (state = INITIAL_STATE, action) => {103 switch (action.type) {104 case SETTINGS_UPDATE_SETTINGS_ADDRESS:105 return {106 ...state,107 accountType: action.payload.accountType,108 accountAddress: action.payload.accountAddress,109 };110 case SETTINGS_UPDATE_NATIVE_CURRENCY_SUCCESS:111 return {112 ...state,113 nativeCurrency: action.payload,114 };115 case SETTINGS_UPDATE_NATIVE_CURRENCY_FAILURE:116 return {117 ...state,118 };119 case SETTINGS_UPDATE_NETWORK:120 return {121 ...state,122 network: action.payload.network,123 chainId: action.payload.chainId124 };125 case SETTINGS_UPDATE_CHAIN_ID:126 return {127 ...state,128 network: action.payload.network,129 chainId: action.payload.chainId130 };131 case SETTINGS_UPDATE_LANGUAGE_SUCCESS:132 return {133 ...state,134 language: action.payload,135 };136 case SETTINGS_UPDATE_LANGUAGE_FAILURE:137 return {138 ...state,139 };140 default:141 return state;142 }...

Full Screen

Full Screen

SettingsActions.js

Source:SettingsActions.js Github

copy

Full Screen

1import { action, axiosReq, dispatchBasicReq } from '../util';2import { validateString, validatePassword } from '../../common/Validator';3export const SettingsActionType = {4 SETTINGS_LOADING: 'SETTINGS_LOADING',5 SETTINGS_GET_SUCCESS: 'SETTINGS_GET_SUCCESS',6 SETTINGS_GET_FAILURE: 'SETTINGS_GET_FAILURE',7 SETTINGS_UPDATE_SUCCESS: 'SETTINGS_UPDATE_SUCCESS',8 SETTINGS_UPDATE_FAILURE: 'SETTINGS_UPDATE_FAILURE',9};10export function settingsLoading() {11 return action(SettingsActionType.SETTINGS_LOADING);12}13export function settingsGetSuccess(settings) {14 return action(SettingsActionType.SETTINGS_GET_SUCCESS, {15 settings,16 });17}18export function settingsGetFailure(error) {19 return action(SettingsActionType.SETTINGS_GET_FAILURE, {20 error,21 });22}23export function settingsGet(id) {24 return dispatchBasicReq(25 axiosReq().get(`/api/user/${id}`),26 settingsLoading,27 settingsGetSuccess,28 settingsGetFailure29 );30}31export function settingsUpdate(signature, old_password, new_password) {32 let validationError;33 if (!validateString(signature, 0, 512, true)) {34 validationError = `Invalid Signature. Must be 0-512 characters: ${signature}`;35 }36 if (old_password) {37 if (!validatePassword(old_password)) {38 validationError = 'Invalid old password format. Must be 6-36 characters.';39 } else if (!validatePassword(new_password)) {40 validationError = 'Invalid new password format. Must be 6-36 characters.';41 }42 if (validationError) {43 return settingsUpdateFailure(validationError);44 }45 }46 return dispatchBasicReq(47 axiosReq().post('/api/settings', {48 signature,49 old_password,50 new_password,51 }),52 settingsLoading,53 settingsUpdateSuccess,54 settingsUpdateFailure55 );56}57export function settingsUpdateSuccess(settings) {58 return action(SettingsActionType.SETTINGS_UPDATE_SUCCESS, {59 settings,60 });61}62export function settingsUpdateFailure(error) {63 return action(SettingsActionType.SETTINGS_UPDATE_FAILURE, {64 error,65 });...

Full Screen

Full Screen

v069.js

Source:v069.js Github

copy

Full Screen

1RocketChat.Migrations.add({2 version: 69,3 up: function() {4 RocketChat.models.Settings.update({5 '_id': 'theme-color-custom-scrollbar-color',6 'value': 'rgba(255, 255, 255, 0.05)'7 }, {8 $set: {9 'editor': 'expression',10 'value': '@transparent-darker'11 }12 });13 RocketChat.models.Settings.update({14 '_id': 'theme-color-info-font-color',15 'value': '#aaaaaa'16 }, {17 $set: {18 'editor': 'expression',19 'value': '@secondary-font-color'20 }21 });22 RocketChat.models.Settings.update({23 '_id': 'theme-color-link-font-color',24 'value': '#008ce3'25 }, {26 $set: {27 'editor': 'expression',28 'value': '@primary-action-color'29 }30 });31 RocketChat.models.Settings.update({32 '_id': 'theme-color-status-away',33 'value': '#fcb316'34 }, {35 $set: {36 'editor': 'expression',37 'value': '@pending-color'38 }39 });40 RocketChat.models.Settings.update({41 '_id': 'theme-color-status-busy',42 'value': '#d30230'43 }, {44 $set: {45 'editor': 'expression',46 'value': '@error-color'47 }48 });49 RocketChat.models.Settings.update({50 '_id': 'theme-color-status-offline',51 'value': 'rgba(150, 150, 150, 0.50)'52 }, {53 $set: {54 'editor': 'expression',55 'value': '@transparent-darker'56 }57 });58 RocketChat.models.Settings.update({59 '_id': 'theme-color-status-online',60 'value': '#35ac19'61 }, {62 $set: {63 'editor': 'expression',64 'value': '@success-color'65 }66 });67 RocketChat.models.Settings.update({68 '_id': 'theme-color-tertiary-background-color',69 'value': '#eaeaea'70 }, {71 $set: {72 'editor': 'expression',73 'value': '@component-color'74 }75 });76 return RocketChat.models.Settings.update({77 '_id': 'theme-color-tertiary-font-color',78 'value': 'rgba(255, 255, 255, 0.6)'79 }, {80 $set: {81 'editor': 'expression',82 'value': '@transparent-lightest'83 }84 });85 }...

Full Screen

Full Screen

types.js

Source:types.js Github

copy

Full Screen

1const namespace = 'settings::';2const updateNamespace = '${namespace}update::';3export const SETTINGS_UPDATE_USERNAME = `${updateNamespace}::update`;4export const SETTINGS_UPDATE_THEME = `${updateNamespace}::theme`;5export const SETTINGS_UPDATE_CLOCK = `${updateNamespace}::clock`;6export const SETTINGS_UPDATE_LOCALE = `${updateNamespace}::locale`;7export const SETTINGS_UPDATE_LISTEN_KEYS = `${updateNamespace}::listenKeys`;8export const SETTINGS_RESTORE = `${namespace}restore`;9export const settingsKeysMap = {10 userName: SETTINGS_UPDATE_USERNAME,11 theme: SETTINGS_UPDATE_THEME,12 clockDisplay: SETTINGS_UPDATE_CLOCK,13 locale: SETTINGS_UPDATE_LOCALE,14 listenSendKeys: SETTINGS_UPDATE_LISTEN_KEYS15};16export default {17 SETTINGS_UPDATE_USERNAME,18 SETTINGS_UPDATE_THEME,19 SETTINGS_UPDATE_CLOCK,20 SETTINGS_UPDATE_LOCALE,21 SETTINGS_UPDATE_LISTEN_KEYS,22 settingsKeysMap,23 SETTINGS_RESTORE...

Full Screen

Full Screen

update.router.js

Source:update.router.js Github

copy

Full Screen

1(function() {2 'use strict';3 angular4 .module('fdmobile.settingsUpdate')5 .config(settingsUpdate);6 settingsUpdate.$inject = ['$stateProvider'];7 function settingsUpdate($stateProvider) {8 $stateProvider9 .state('settings-update', {10 url: '/settings/update',11 templateUrl: 'settings/update/update.html',12 controller: 'SettingsUpdateController as vm',13 cache: false14 });15 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 }5};6(async () => {7 const client = await wdio.remote(opts);8 await client.settings.update({ignoreUnimportantViews: true});9 await client.deleteSession();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desired)7 .setImplicitWaitTimeout(5000)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { BaseDriver } = require('appium-base-driver');2const { settings } = require('appium-base-driver/lib/basedriver/settings');3const { server, routeConfiguringFunction } = require('appium-express');4const { startServer } = require('appium');5const { getNonDefaultArgs } = require('appium/lib/parser');6const { createSession } = require('appium/lib/driver-cli');7const { SubProcess } = require('teen_process');8const path = require('path');9async function main () {10 const args = getNonDefaultArgs();11 const server = await startServer(args, false);12 const port = server.address().port;13 const driver = await createSession({14 desiredCapabilities: {15 app: path.resolve(__dirname, '../apps/TestApp.app.zip'),16 },17 });18 console.log(driver);19 await driver.updateSettings({20 'ignoreUnimportantViews': true,21 });22 await driver.deleteSession();23 await server.close();24}25main();26const { BaseDriver } = require('appium-base-driver');27const { settings } = require('appium-base-driver/lib/basedriver/settings');28const { server, routeConfiguringFunction } = require('appium-express');29const { startServer } = require('appium');30const { getNonDefaultArgs } = require('appium/lib/parser');31const { createSession } = require('appium/lib/driver-cli');32const { SubProcess } = require('teen_process');33const path = require('path');34async function main () {35 const args = getNonDefaultArgs();36 const server = await startServer(args, false);37 const port = server.address().port;38 const driver = await createSession({39 desiredCapabilities: {40 app: path.resolve(__dirname, '../apps/TestApp.app

Full Screen

Using AI Code Generation

copy

Full Screen

1 .init({ "app": "com.example.android.contactmanager/.ContactManager" })2 .settings.update({ "ignoreUnimportantViews": true })3 .quit();4{5}6{7 "value": {8 }9}10driver.setSetting(Setting.IGNORE_UNIMPORTANT_VIEWS, true);11driver.setSetting(Setting.IGNORE_UNIMPORTANT_VIEWS, true);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful