diff --git a/Sequence.js b/Sequence.js index 883d7c4..61b7d4d 100644 --- a/Sequence.js +++ b/Sequence.js @@ -17,6 +17,7 @@ var Sequence = function (expData) { this.type = "Sequence"; this.name = ko.observable("Sequence"); this.workspaceVars = ko.observableArray([]).extend({ sortById: null }); + this.globalEvents = ko.observableArray([]); // sub-Structures (serialized below) this.elements = ko.observableArray().extend({ sortById: null }); @@ -29,6 +30,17 @@ Sequence.prototype.dispose = function () { }); }; +Sequence.prototype.deleteChildEntity = function (entity) { + if (entity instanceof ExpEvent) { + this.globalEvents.remove(entity); + } + + // if this element was selected, set selection to null + if (entity === this.currSelectedElement()) { + this.currSelectedElement(null); + } +}; + /** * Select a specific or multiple trial types. * @@ -198,18 +210,21 @@ Sequence.prototype.setPointers = function (entitiesArr) { return entitiesArr.byId[id]; })); + jQuery.each(this.globalEvents(), function (idx, event) { + event.setPointers(entitiesArr); + }); + // converter to add all old existing factors to workspace only in editor //if(window.uc!==undefined){ // this.addAllRemainingFactorToWorkspace(); //} - - }; Sequence.prototype.onFinishedLoading = function () { this.addAllRemainingFactorToWorkspace(); }; + Sequence.prototype.addVariableToWorkspace = function (variable) { var isExisting = this.workspaceVars.byId[variable.id()]; if (!isExisting) { @@ -250,12 +265,23 @@ Sequence.prototype.reAddEntities = function (entitiesArr) { entitiesArr.insertIfNotExist(elem); // recursively make sure that all deep tree nodes are in the entities list: - if (elem.reAddEntities) + if (elem.reAddEntities) { elem.reAddEntities(entitiesArr); + } + }); + // add the direct child nodes: + jQuery.each(this.globalEvents(), function (index, evt) { + // recursively make sure that all deep tree nodes are in the entities list: + if (evt.reAddEntities) { + evt.reAddEntities(entitiesArr); + } }); - // add the direct child nodes: jQuery.each(this.workspaceVars(), function (index, elem) { + // check if they are not already in the list: + if (!entitiesArr.byId.hasOwnProperty(elem.id())) { + entitiesArr.push(elem); + } entitiesArr.insertIfNotExist(elem); }); @@ -269,13 +295,18 @@ Sequence.prototype.reAddEntities = function (entitiesArr) { * @returns {Sequence} */ Sequence.prototype.fromJS = function (data) { + var self = this; this.id(data.id); this.name(data.name); this.elements(data.elements); if (data.hasOwnProperty("workspaceVars")) { this.workspaceVars(data.workspaceVars); } + this.globalEvents(jQuery.map(data.globalEvents, function (eventData) { + return (new ExpEvent(self)).fromJS(eventData); + })); return this; + }; /** @@ -283,11 +314,16 @@ Sequence.prototype.fromJS = function (data) { * @returns {object} */ Sequence.prototype.toJS = function () { + var globalEvents = this.globalEvents(); return { id: this.id(), type: this.type, name: this.name(), elements: jQuery.map(this.elements(), function (elem) { return elem.id(); }), - workspaceVars: jQuery.map(this.workspaceVars(), function (variable) { return variable.id(); }) + workspaceVars: jQuery.map(this.workspaceVars(), function (variable) { return variable.id(); }), + globalEvents: jQuery.map(globalEvents, function (event) { + return event.toJS(); + }), + }; }; diff --git a/event.js b/event.js index 2537737..5077b7c 100644 --- a/event.js +++ b/event.js @@ -17,7 +17,6 @@ var ExpEvent = function (parent) { this.actions = ko.observableArray([]); this.name = ko.observable(null); this.description = ko.observable('event description'); - this.shortName = ko.computed(function () { if (self.name()) { return (self.name().length > 13 ? self.name().substring(0, 12) + '...' : self.name()); @@ -27,9 +26,17 @@ var ExpEvent = function (parent) { // not serialized: this.isPaused = false; - + this.isGlobal = ko.observable(this.parent.constructor.name === 'Sequence' ? true : false); }; + +ExpEvent.prototype.getSequence = function () { + if (this.isGlobal()) { + return this.parent; + } + return this.parent.parent; +} + /** * delete the action at the specified index. * @param {number} index @@ -226,7 +233,9 @@ ExpEvent.prototype.fromJS = function (data) { if (data.requirement) { this.requirementConverter(data); } - + if (data.hasOwnProperty('isGlobal')) { + this.isGlobal(data.isGlobal); + } @@ -264,7 +273,8 @@ ExpEvent.prototype.toJS = function () { type: this.type, trigger: this.trigger().toJS(), actions: actionData, - description: this.description() + description: this.description(), + isGlobal: this.isGlobal(), }; }; diff --git a/eventActions.js b/eventActions.js index 5c56caf..8fec700 100644 --- a/eventActions.js +++ b/eventActions.js @@ -1655,6 +1655,7 @@ var ActionJumpTo = function (event) { this.blockToJumpId = ko.observable(null); this.conditionGroupIdx = ko.observable(null); this.checkRequired = ko.observable(null); + this.jumpTrailType = ko.observable('id'); this.alreadyTriggered = false; }; @@ -1838,6 +1839,9 @@ ActionJumpTo.prototype.fromJS = function (data) { this.checkRequired(data.checkRequired); } + if (data.hasOwnProperty('jumpTrailType')) { + this.jumpTrailType(data.jumpTrailType); + } return this; }; @@ -1864,7 +1868,8 @@ ActionJumpTo.prototype.toJS = function () { trialToJumpId: this.trialToJumpId(), conditionGroupIdx: this.conditionGroupIdx(), blockToJumpId: this.blockToJumpId(), - checkRequired: this.checkRequired() + checkRequired: this.checkRequired(), + jumpTrailType: this.jumpTrailType() }; }; diff --git a/eventTrigger.js b/eventTrigger.js index 7bfa89c..c6fb4b1 100644 --- a/eventTrigger.js +++ b/eventTrigger.js @@ -975,6 +975,7 @@ var TriggerOnFrameStart = function (event) { TriggerOnFrameStart.prototype.type = "TriggerOnFrameStart"; TriggerOnFrameStart.prototype.label = "On Frame Start Trigger"; +TriggerOnFrameStart.prototype.iconPath = "/resources/icons/events/onChangeEvent.svg"; /** * returns true if all settings are valid (used in the editor). diff --git a/frameData.js b/frameData.js index 58ba433..1412393 100644 --- a/frameData.js +++ b/frameData.js @@ -293,6 +293,10 @@ FrameData.prototype.fromJS = function (data) { * @returns {object} */ FrameData.prototype.toJS = function () { + var events = this.events(); + events = events.filter(function (element) { + return !element.isGlobal(); + }); return { id: this.id(), type: this.type, @@ -308,7 +312,7 @@ FrameData.prototype.toJS = function () { syncFrame: this.syncFrame(), emotionFeedbackEnabled: this.emotionFeedbackEnabled(), emotionOffset: this.emotionOffset(), - events: jQuery.map(this.events(), function (event) { + events: jQuery.map(events, function (event) { return event.toJS(); }), elements: jQuery.map(this.elements(), function (elem) { return elem.id(); }),