update: (element, valueAccessor) => {
        const arg = valueAccessor();
        const userTid = ko.unwrap(arg[0]);
        const userTids = ko.unwrap(arg[1]);

        // Hide if not multi team or not loaded yet
        if (userTids.length <= 1 || g.teamRegionsCache === undefined) {
            return ko.bindingHandlers.visible.update(element, () => false);
        }

        ko.bindingHandlers.visible.update(element, () => true);

        const teamNames = userTids.map(tid => `${g.teamRegionsCache[tid]} ${g.teamNamesCache[tid]}`);

        let options = "";
        for (let i = 0; i < userTids.length; i++) {
            if (userTid === userTids[i]) {
                options += `<option value="${userTids[i]}" selected>${teamNames[i]}</option>`;
            } else {
                options += `<option value="${userTids[i]}">${teamNames[i]}</option>`;
            }
        }

        // Menu is triggered by jQuery code in ui.js
        return ko.bindingHandlers.html.update(element, () => {
            return `<label for="multi-team-select">Currently controlling:</label><br><select class="form-control" id="multi-team-select">${options}</select>`;
        });
    },
Example #2
0
                .always(() => {
                  if (
                    !self.database() ||
                    self.availableDatabases().indexOf(self.database()) === -1
                  ) {
                    const lastSelectedDb = apiHelper.getFromTotalStorage(
                      'assist_' +
                        ko.unwrap(self.sourceType) +
                        '_' +
                        self[TYPES_INDEX.namespace.name]().id,
                      'lastSelectedDb',
                      'default'
                    );
                    if (
                      self.availableDatabases().length === 0 ||
                      self.availableDatabases().indexOf(lastSelectedDb) !== -1
                    ) {
                      self.database(lastSelectedDb);
                    } else {
                      self.database(self.availableDatabases()[0]);
                    }
                  }
                  self.loadingDatabases(false);

                  huePubSub.publish('assist.set.database', {
                    source: ko.unwrap(self.sourceType),
                    namespace: self[TYPES_INDEX.namespace.name](),
                    name: self.database()
                  });
                });
    update: function (element, valueAccessor) {
        var arg, i, options, teamNames, userTid, userTids;
        arg = valueAccessor();
        userTid = ko.unwrap(arg[0]);
        userTids = ko.unwrap(arg[1]);

        // Hide if not multi team or not loaded yet
        if (userTids.length <= 1 || g.teamRegionsCache === undefined) {
            return ko.bindingHandlers.visible.update(element, function () {
                return false;
            });
        }

        ko.bindingHandlers.visible.update(element, function () {
            return true;
        });

        teamNames = userTids.map(function (t) {
            return g.teamRegionsCache[t] + " " + g.teamNamesCache[t];
        });

        options = "";
        for (i = 0; i < userTids.length; i++) {
            if (userTid === userTids[i]) {
                options += '<option value="' + userTids[i] + '" selected>' + teamNames[i] + '</option>';
            } else {
                options += '<option value="' + userTids[i] + '">' + teamNames[i] + '</option>';
            }
        }

        // Menu is triggered by jQuery code in ui.js
        return ko.bindingHandlers.html.update(element, function () {
            return '<label for="multi-team-select">Currently controlling:</label><br><select class="form-control" id="multi-team-select">' + options + '</select>';
        });
    }
Example #4
0
		    update: function(element, valueAccessor) {
		    	// clear marker
		    	markers.map((marker) => marker.setMap(null));

		    	var value = ko.unwrap(valueAccessor()),
		        	locations = ko.unwrap(value.locations),
		        	center = ko.unwrap(value.center);

		        // create marker
		        ko.utils.arrayForEach(locations, 
		        	location => markers.push(new Marker({
		            	position: new google.maps.LatLng(
		            		ko.unwrap(location.latitude), 
		            		ko.unwrap(location.longitude)),
		            	map_icon_label: getIconLabel(ko.unwrap(location.type)),
						icon: getIcon(ko.unwrap(location.type)),
		            	map: map
		          	}))
		        )

		        // update center
		         var newCenter = new google.maps.LatLng(
		        		ko.unwrap(center.latitude), ko.unwrap(center.longitude))
				 map.panTo(newCenter);
	    	}
function formatDate(date: PartialDateT | null): string {
  if (!date) {
    return '';
  }

  const y: number = ko.unwrap(date.year);
  const m: number = ko.unwrap(date.month);
  const d: number = ko.unwrap(date.day);

  let result = '';

  if (nonEmpty(y)) {
    if (y < 0) {
      result += '-' + padStart(String(-y), 3, '0');
    } else {
      result += padStart(String(y), 4, '0');
    }
  } else if (m || d) {
    result = '????';
  }

  if (m) {
    result += '-' + padStart(String(m), 2, '0');
  } else if (d) {
    result += '-??';
  }

  if (d) {
    result += '-' + padStart(String(d), 2, '0');
  }

  return result;
}
Example #6
0
function onNewNode(node, item, key) {
  //console.log('onNewNode():', node.label() ); // parents.length > 0 ? _.last(parents).key : ''); //node, item, key, parents);
  
  if (!node.parent) {
    console.log('root node');
    node.addChildNode('Size', [item.width, 'x', item.height], { valueTemplateName: 'tmplRow', leaf: true });
  }
  else {
    // Immediate child of root node ?
    if (!node.parent.parent) { 
      if (!_.isObject(ko.unwrap(item))) { console.log(key+':', item); return false; }
    }
    // Adjustments are tabular data that we want to edit
    else if (key === 'adjustments') {
      node.open(false);
      node.onCreateNewChild = function(parent, options) {
      	var index = options.index || 0;
        var _parent = ko.unwrap(parent);
        var subitem = { set: 0, actual: 0 };
        if (index > 0 && index < _parent.length) {
          subitem.set    = interpolate(ko.unwrap(_parent[index-1].set   ), ko.unwrap(_parent[index].set   ));
          subitem.actual = interpolate(ko.unwrap(_parent[index-1].actual), ko.unwrap(_parent[index].actual));
        }
        return ko.mapping.fromJS(subitem);
        //-------
        function interpolate(v1, v2) { return v1 + (v2 - v1) / 2; }
      };
    }
    // Labels
    // TODO: is it wise to have string indices (=keys) wrapped as observables ?
    if (ko.unwrap(node.parent.index) === 'adjustments') {
      //console.log('adding to adjustments');
      node.label = ko.computed(adjustmentLabelFunc, node);
      node.open(false);
    }
    else {
      // Capitalize label
      // TODO: make this a feature of TreeView ?
      if (typeof ko.unwrap(node.label) === 'string' && !ko.isComputed(node.label)) {
        if (typeof node.label() !== 'string') debugger;
        node.label( node.label()[0].toUpperCase() + node.label().slice(1) ); //+ '-' + node.label() + node.label() );
      }
    }
  }

  // How to display "value" cell
  var unwrapped = ko.unwrap(item);
  if (!_.isObject(unwrapped)) {
    if      (_.isNumber (unwrapped)) node.valueTemplateName('tmplNumericField');
    else if (_.isBoolean(unwrapped)) node.valueTemplateName('tmplBooleanField');
    else if (_.isString (unwrapped)) node.valueTemplateName('tmplStringField' );
    else throw new Error('unsupported type for "value" of node');
    node.hasValue(true);
  }
  
  //--------
  
  function adjustmentLabelFunc() { return this.data.set().toString() + ': ' + this.data.actual().toString(); }
}
Example #7
0
function initDisplayOptions(data) {
	var options = data.displayOptions ? data.displayOptions : {};

	options.showCountry = ko.unwrap(options.showCountry) === false ? false : true;
	options.inputSize = "input-" + (ko.unwrap(options.inputSize) || "");

	return options;
}
Example #8
0
		        	location => markers.push(new Marker({
		            	position: new google.maps.LatLng(
		            		ko.unwrap(location.latitude), 
		            		ko.unwrap(location.longitude)),
		            	map_icon_label: getIconLabel(ko.unwrap(location.type)),
						icon: getIcon(ko.unwrap(location.type)),
		            	map: map
		          	}))
Example #9
0
    update: function (
        element,
        valueAccessor
    ) {
        const isDisabled = ko.unwrap(valueAccessor());

        $(element).tokenInput('toggleDisabled', ko.unwrap(isDisabled) || false);
    }
Example #10
0
exports.prototype.calcIsEmployeeInEditMode = function () {
	var tmpVwmUserProfile = ko.unwrap(this.vwmUserProfile);
	if (tmpVwmUserProfile) {
		var tmpEmployee = ko.unwrap(tmpVwmUserProfile.slcVwmChild);
		if (tmpEmployee) {
			return ko.unwrap(tmpEmployee.isEditMode);
		}
	}
};
    update: (element, valueAccessor) => {
        const args = valueAccessor();
        const injury = ko.unwrap(args[2]);
        injury.type = ko.unwrap(injury.type);
        injury.gamesRemaining = ko.unwrap(injury.gamesRemaining);

        return ko.bindingHandlers.html.update(element, () => {
            return helpers.playerNameLabels(ko.unwrap(args[0]), ko.unwrap(args[1]), injury, ko.unwrap(args[3]), ko.unwrap(args[4]));
        });
    },
    update: (element, valueAccessor) => {
        const arg = valueAccessor();
        const plusminus = ko.unwrap(arg[0]);
        const round = ko.unwrap(arg[1]);

        return ko.bindingHandlers.html.update(element, () => {
            const val = helpers.plusMinus(plusminus, round);
            return (val !== val ? "" : val);
        });
    },
Example #13
0
    update: function (element, valueAccessor) {
        var arg, plusminus, round;
        arg = valueAccessor();
        plusminus = ko.unwrap(arg[0]);
        round = ko.unwrap(arg[1]);

        return ko.bindingHandlers.html.update(element, function () {
            var val = helpers.plusMinus(plusminus, round);
            return (val !== val ? "" : val);
        });
    }
Example #14
0
        knockout.computed(function() {
            var widget = knockout.unwrap(valueAccessor());
            if (isString(widget)) {
                var widgets = findWidgets(bindingContext);
                widget = widgets[widget];
            }
            
            var options = knockout.unwrap(allBindingsAccessor().widgetOptions);

            widget(element, options);
        });
Example #15
0
 node.onCreateNewChild = function(parent, options) {
 	var index = options.index || 0;
   var _parent = ko.unwrap(parent);
   var subitem = { set: 0, actual: 0 };
   if (index > 0 && index < _parent.length) {
     subitem.set    = interpolate(ko.unwrap(_parent[index-1].set   ), ko.unwrap(_parent[index].set   ));
     subitem.actual = interpolate(ko.unwrap(_parent[index-1].actual), ko.unwrap(_parent[index].actual));
   }
   return ko.mapping.fromJS(subitem);
   //-------
   function interpolate(v1, v2) { return v1 + (v2 - v1) / 2; }
 };
Example #16
0
    update: function (element, valueAccessor) {
        var args, injury;

        args = valueAccessor();
        injury = ko.unwrap(args[2]);
        injury.type = ko.unwrap(injury.type);
        injury.gamesRemaining = ko.unwrap(injury.gamesRemaining);

        return ko.bindingHandlers.html.update(element, function () {
            return helpers.playerNameLabels(ko.unwrap(args[0]), ko.unwrap(args[1]), injury, ko.unwrap(args[3]), ko.unwrap(args[4]));
        });
    }
Example #17
0
		listOfVwmWellMarker.forEach(function (elem) {
			var tmpCoords = ko.unwrap(elem.mdlWellMarker.coords);
			mapHelper.drawWellMarker(
				tmpCoords[0] * widthCoefVgToPx,
				tmpCoords[1] * heightCoefVgToPx,
				ko.unwrap(elem.isSlc) ? 'well-marker_selected' : ko.unwrap(elem.mdlWellMarker.markerStyle),
				d3GroupWrap,
				wellMarkerRadius,
				function (endCoordX, endCoordY) {
				elem.mdlWellMarker.coords([
						appHelper.toFloatDec(endCoordX / widthCoefVgToPx, 1),
						appHelper.toFloatDec(endCoordY / heightCoefVgToPx, 1)]);
			});
		});
Example #18
0
		    init: function (element, valueAccessor) {
		    	var value = ko.unwrap(valueAccessor()),
		        	zoom = ko.unwrap(value.zoom),
		        	center = ko.unwrap(value.center);
      
		        var mapOptions = {
		        	zoom: zoom,
		        	center:  new google.maps.LatLng(
		        		ko.unwrap(center.latitude), ko.unwrap(center.longitude)),
		        	mapTypeId: google.maps.MapTypeId.ROADMAP
		        };
		        //create map
		        map = new google.maps.Map(element, mapOptions);
		    },
 static getDerivedStateFromProps(nextProps, prevState) {
   const artistCredit = ko.unwrap(nextProps.entity.artistCredit);
   if (!artistCreditsAreEqual(prevState.artistCredit, artistCredit)) {
     return {artistCredit};
   }
   return null;
 }
Example #20
0
 update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
     var value = valueAccessor();
     var valueUnwrapped = ko.unwrap(value);
     var map = valueUnwrapped.map || function(item) {return item;};
     var data = valueUnwrapped.data || [];
     var keys = [];
     if (!Array.isArray(data)) {
         keys = Object.keys(data);
     }
     else {
         keys = data;
     }
     var list = ko.utils.arrayMap(keys, function(key, index) {
         var ret;
         if (index === 0){
             ret = '';
         }
         else if (index === 1){
             if (valueUnwrapped.length === 2) {
                 ret = ' and ';
             }
             else {
                 ret = ', ';
             }
         }
         else {
             ret = ', and ';
         }
         ret += map(key, data[key]);
         return ret;
     }).join('');
     $(element).text(list);
 }
Example #21
0
	update : function (element, valueAccessor) {
		var tmpAxis = ko.unwrap(valueAccessor());
		if (tmpAxis) {
			d3.select(element).call(tmpAxis);
			// alternative: tmpAxis($(element));
		}
	}
Example #22
0
	tmpListOfWell.forEach(function (tmpWell) {
		if (ko.unwrap(tmpWell.IsActive)) {
			activeCount += 1;
		} else {
			nonActiveCount += 1;
		}
	});
Example #23
0
  init: function(element, valueAccessor) {
    const $container = $(element);
    const options = ko.unwrap(valueAccessor());
    const panelDefinitions = options.panels;

    const checkForElements = function() {
      const $allPanels = $container.children('.assist-inner-panel');
      const $allExtras = $container.children('.assist-fixed-height');
      if (
        panelDefinitions().length === $allPanels.length &&
        ($allExtras.length > 0 || options.noFixedHeights)
      ) {
        ko.bindingHandlers.assistVerticalResizer.updateWhenRendered(element, valueAccessor);
      } else {
        timeout = window.setTimeout(checkForElements, 10);
      }
    };

    checkForElements();
    let timeout = -1;
    panelDefinitions.subscribe(() => {
      window.clearTimeout(timeout);
      timeout = window.setTimeout(checkForElements, 10);
    });
  },
			setTimeout(function () {
				var options = {};
				options.color = element.ownerDocument.defaultView.getComputedStyle(element, null).color;
				objectAssign(options, ko.bindingHandlers.spinner.defaultOptions, ko.unwrap(allBindings.get("spinnerOptions")));

				resolve(new Spinner(options));
			}, 30);
Example #25
0
exports.prototype.calcWellActivityData = function () {
	var tmpListOfWell = ko.unwrap(this.listOfWell);

	var activeCount = 0,
	nonActiveCount = 0;

	tmpListOfWell.forEach(function (tmpWell) {
		if (ko.unwrap(tmpWell.IsActive)) {
			activeCount += 1;
		} else {
			nonActiveCount += 1;
		}
	});

	return [{
			lbl : activeCount || '',
			val : activeCount,
			name : 'Active wells',
			color : '#79a0c1' // Color from main.css $brand-primary
		}, {
			lbl : nonActiveCount || '',
			val : nonActiveCount,
			name : 'Non-active wells',
			color : '#999'
		}
	];
};
Example #26
0
 huePubSub.subscribe('data.catalog.entry.refreshed', details => {
   if (details.entry.isSource()) {
     if (ko.unwrap(self.sourceType) === details.entry.getSourceType()) {
       self.reloadDatabases();
     }
   }
 });
Example #27
0
 onRequest: () =>
   api.ajax({
     url: 'documents/meta',
     data: Object.assign({}, ko.unwrap(params.requestParams), {q: this.coll.query}),
   }).done(metadata => {
     this.metadata = metadata.data;
   }),
Example #28
0
        relationship: function (relationship) {
            var data = {
                id:             number(relationship.id),
                linkTypeID:     number(relationship.linkTypeID),
                entities:       array(relationship.entities, this.relationshipEntity),
                entity0_credit: string(relationship.entity0_credit),
                entity1_credit: string(relationship.entity1_credit)
            };

            data.attributes = _(ko.unwrap(relationship.attributes))
                .invokeMap('toJS')
                .sortBy(function (a) { return a.type.id })
                .value();

            if (_.isNumber(data.linkTypeID)) {
                if (typeInfo.link_type.byId[data.linkTypeID].orderable_direction !== 0) {
                    data.linkOrder = number(relationship.linkOrder) || 0;
                }
            }

            if (relationship.hasDates()) {
                data.begin_date = fields.partialDate(relationship.begin_date);
                data.end_date = fields.partialDate(relationship.end_date);

                if (data.end_date && _(data.end_date).values().some(nonEmpty)) {
                    data.ended = true;
                } else {
                    data.ended = Boolean(value(relationship.ended));
                }
            }

            return data;
        },
    it('adapter getValue returns correct value of child', function (done) {
      let children = ko.unwrap(adapter.mappedChildNodes);
      children[0].setValue('Test');

      expect(children[0].context.getValue('A')).to.equal('Test');
      done();
    });
function entityHref(
  entity: LinkableEntity,
  subPath?: string,
) {
  const entityType = entity.entityType;
  const entityProps = ENTITIES[entityType];
  let href = '/' + entityProps.url + '/';
  let id: string;

  if (entityProps.mbid) {
    id = ko.unwrap((entity: any).gid);
  } else if (entityType === 'isrc' || entityType === 'iswc') {
    id = (entity: any)[entityType];
  } else if (entityType === 'cdstub') {
    id = (entity: any).discid;
  } else {
    id = (entity: any).name;
  }

  href += encodeURIComponent(id);

  if (nonEmpty(subPath)) {
    subPath = subPath.replace(leadingSlash, '$1');
    if (subPath) {
      href += '/' + subPath;
    }
  }

  return href;
}