Skip to content

Commit

Permalink
Adds as-yet untested MIDI selectbox widget.
Browse files Browse the repository at this point in the history
Updates Infusion to the 1.5 release.
  • Loading branch information
colinbdclark committed Jul 25, 2014
1 parent ff90e60 commit 607a177
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 5 deletions.
6 changes: 6 additions & 0 deletions demos/interactive/html/playground.html
Expand Up @@ -15,8 +15,14 @@

<script src="../../../third-party/jquery/js/jquery-2.0.0.js"></script>
<script src="../../../third-party/infusion/js/Fluid.js"></script>
<script src="../../../third-party/infusion/js/FluidDocument.js"></script>
<script src="../../../third-party/infusion/js/FluidDOMUtilities.js"></script>
<script src="../../../third-party/infusion/js/FluidDebugging.js"></script>
<script src="../../../third-party/infusion/js/FluidIoC.js"></script>
<script src="../../../third-party/infusion/js/DataBinding.js"></script>
<script src="../../../third-party/infusion/js/ModelTransformation.js"></script>
<script src="../../../third-party/infusion/js/ModelTransformationTransforms.js"></script>
<script src="../../../third-party/infusion/js/FluidView.js"></script>
<script src="../../../third-party/dspapi/js/dspapi.js"></script>
<script src="../../../third-party/simjs/js/random-0.26.js"></script>

Expand Down
4 changes: 2 additions & 2 deletions dist/flocking-all.js
Expand Up @@ -14512,7 +14512,7 @@ var fluid_1_5 = fluid_1_5 || {};
var sourceListener = function (newValue, oldValue, path, changeRequest, trans, applier) {
var transId = trans.id;
var transRec = fluid.getModelTransactionRec(instantiator, transId);
if (applier && trans) {
if (applier && trans && !transRec[applier.applierId]) { // don't trash existing record which may contain "options" (FLUID-5397)
transRec[applier.applierId] = {transaction: trans}; // enlist the outer user's original transaction
}
var existing = transRec[applierId];
Expand Down Expand Up @@ -14730,6 +14730,7 @@ var fluid_1_5 = fluid_1_5 || {};
var change = allChanges[i];
change.listener.apply(null, change.args);
}
fluid.clearLinkCounts(transRec, true); // "options" structures for relayCount are aliased
};

fluid.model.commitRelays = function (instantiator, transactionId) {
Expand All @@ -14741,7 +14742,6 @@ var fluid_1_5 = fluid_1_5 || {};
transEl.transaction.reset();
}
});
fluid.clearLinkCounts(transRec, true); // "options" structures for relayCount are aliased
};

fluid.model.updateRelays = function (instantiator, transactionId) {
Expand Down
2 changes: 1 addition & 1 deletion dist/flocking-all.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions third-party/infusion/js/DataBinding.js 100644 → 100755
Expand Up @@ -456,7 +456,7 @@ var fluid_1_5 = fluid_1_5 || {};
var sourceListener = function (newValue, oldValue, path, changeRequest, trans, applier) {
var transId = trans.id;
var transRec = fluid.getModelTransactionRec(instantiator, transId);
if (applier && trans) {
if (applier && trans && !transRec[applier.applierId]) { // don't trash existing record which may contain "options" (FLUID-5397)
transRec[applier.applierId] = {transaction: trans}; // enlist the outer user's original transaction
}
var existing = transRec[applierId];
Expand Down Expand Up @@ -674,6 +674,7 @@ var fluid_1_5 = fluid_1_5 || {};
var change = allChanges[i];
change.listener.apply(null, change.args);
}
fluid.clearLinkCounts(transRec, true); // "options" structures for relayCount are aliased
};

fluid.model.commitRelays = function (instantiator, transactionId) {
Expand All @@ -685,7 +686,6 @@ var fluid_1_5 = fluid_1_5 || {};
transEl.transaction.reset();
}
});
fluid.clearLinkCounts(transRec, true); // "options" structures for relayCount are aliased
};

fluid.model.updateRelays = function (instantiator, transactionId) {
Expand Down
Empty file modified third-party/infusion/js/Fluid.js 100644 → 100755
Empty file.
Empty file modified third-party/infusion/js/FluidDOMUtilities.js 100644 → 100755
Empty file.
Empty file modified third-party/infusion/js/FluidDebugging.js 100644 → 100755
Empty file.
Empty file modified third-party/infusion/js/FluidDocument.js 100644 → 100755
Empty file.
Empty file modified third-party/infusion/js/FluidIoC.js 100644 → 100755
Empty file.
Empty file modified third-party/infusion/js/FluidRequests.js 100644 → 100755
Empty file.
Empty file modified third-party/infusion/js/FluidView.js 100644 → 100755
Empty file.
Empty file modified third-party/infusion/js/ModelTransformation.js 100644 → 100755
Empty file.
Empty file modified third-party/infusion/js/ModelTransformationTransforms.js 100644 → 100755
Empty file.
263 changes: 263 additions & 0 deletions ui/selectbox/js/selectbox.js
@@ -0,0 +1,263 @@
/*
* Flocking UI Select Box
* Copyright 2014, Colin Clark
*
* Dual licensed under the MIT and GPL Version 2 licenses.
*/

/*global require*/

var fluid = fluid || require("infusion"),
flock = fluid.registerNamespace("flock");

(function () {
"use strict";

fluid.setLogging(true);

var $ = fluid.registerNamespace("jQuery");

/**************
* Select Box *
**************/

fluid.defaults("flock.ui.selectBox", {
gradeNames: ["fluid.viewComponent", "autoInit"],

model: {
/*
Example model for a selectBox instance:
groups: [
{
name: "Cats",
options: [
{
id: "hugo",
name: "Hugo"
},
{
id: "sirius",
name: "Sirius"
}
]
}
],
options: [
{
id: "doge",
name: "Doge"
}
],
selection: "hugo"
*/
},

markup: {
group: "<optgroup label='%label'></optgroup",
option: "<option value='%value'>%label</option>"
},

invokers: {
render: {
funcName: "flock.ui.selectBox.render",
args: [
"{that}.container",
"{that}.model",
"{that}.applier",
"{that}.options.markup",
"{that}.events.afterRender.fire"
]
},

select: {
funcName: "flock.ui.selectBox.select",
args: ["{that}", "{arguments}.0", "{that}.container"]
},

handleChange: {
funcName: "flock.ui.selectBox.handleChange",
args: ["{that}.container", "{that}.updateSelection"]
},

updateSelection: {
funcName: "flock.ui.selectBox.updateSelection",
args: ["{arguments}.0", "{that}.container", "{that}.applier", "{that}.events.onSelect.fire"]
}
},

events: {
onSelect: null,
afterRender: null
},

listeners: {
onCreate: [
{
"this": "{that}.container",
method: "change",
args: ["{that}.handleChange"]
},
{
funcName: "{that}.render"
}
]
}
});

flock.ui.selectBox.handleChange = function (container, updateSelection) {
var id = container.val();
updateSelection(id);
};

flock.ui.selectBox.updateSelection = function (id, container, applier, onSelect) {
var selectedEl = container.find("[value='" + id + "']").eq(0),
selectedDemo = selectedEl.data("flock-selectBox-model-binding");

applier.requestChange("selection", id);
onSelect(selectedDemo);
};

flock.ui.selectBox.select = function (that, id, container) {
var optionToSelect = container.find("[value='" + id + "']").eq(0);
container.find("option").removeAttr("selected");
optionToSelect.attr("selected", "selected");
that.updateSelection(id);
};

flock.ui.selectBox.render = function (container, model, applier, markup, afterRender) {
if (model.groups) {
flock.ui.selectBox.render.groups(container, model.groups, markup);
}

if (model.options) {
flock.ui.selectBox.render.options(container, model.options, markup);
}

if (!model.selection) {
var defaultSelection = (model.groups && model.groups.options) ? model.group.options[0] :
model.options ? model.options : undefined;

if (defaultSelection) {
applier.requestChange("selection", defaultSelection);
}
}

afterRender();
};

flock.ui.selectBox.render.groups = function (container, groups, markup) {
fluid.each(groups, function (group) {
flock.ui.selectBox.render.group(container, group, markup);
});
};

flock.ui.selectBox.render.group = function (container, group, markup) {
var renderedMarkup = fluid.stringTemplate(markup.group, {
label: group.name
});

var optGroupEl = $(renderedMarkup);
container.append(optGroupEl);
flock.ui.selectBox.render.options(optGroupEl, group.options, markup);
};

flock.ui.selectBox.render.options = function (container, options, markup) {
fluid.each(options, function (option) {
flock.ui.selectBox.render.option(container, option, markup);
});
};

flock.ui.selectBox.render.option = function (container, option, markup) {
var renderedMarkup = fluid.stringTemplate(markup.option, {
label: option.name,
value: option.id
});

var optionEl = $(renderedMarkup);
container.append(optionEl);
optionEl.data("flock-selectBox-model-binding", option);
};


fluid.defaults("flock.ui.midiPortSelector", {
gradeNames: ["flock.ui.selectBox", "autoInit"],

sysex: false,

model: {
options: [],
selection: null
},

invokers: {
refreshPorts: {
funcName: "flock.ui.midiPortSelector.refreshPorts",
args: ["{that}.applier", "{arguments}.0", "{that}.options.selectionDefaults"]
}
},

events: {
onAccessGranted: null,
onAccessError: null
},

modelListeners: {
"*": {
func: "{that}.render"
}
},

listeners: {
onCreate: {
funcName: "flock.midi.requestAccess",
args: [
"{that}.options.sysex",
"{that}.events.onAccessGranted.fire",
"{that}.events.onAccessError.fire"
]
},

onAccessGranted: {
func: "{that}.refreshPorts"
},

onAccessError: {
func: "fluid.log",
args: [fluid.logLevel.WARN, "{arguments}.0"]
}
},

selectionDefaults: {
prompt: {
id: "choose",
name: "Select a MIDI input..."
},

noPorts: {
id: "none",
name: "No MIDI inputs found."
}
}
});

flock.ui.midiPortSelector.refreshPorts = function (applier, access, selectionDefaults) {
var ports = flock.midi.getPorts(access);

var portsModel = fluid.transform(ports.inputs, function (port) {
return {
id: port.id,
name: port.manufacturer + " " + port.name
}
});

var firstOption = portsModel.length > 0 ? selectionDefaults.prompt : selectionDefaults.noPorts;
portsModel.unshift(firstOption);

// Update the model with the new options.
applier.change("options", []);
applier.change("options", portsModel);
};

}());

0 comments on commit 607a177

Please sign in to comment.