Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions Sequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
});

Expand All @@ -269,25 +295,35 @@ 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;

};

/**
* serialize the state of this instance into a json object, which can later be restored using the method fromJS.
* @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();
}),

};
};
18 changes: 14 additions & 4 deletions event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down Expand Up @@ -226,7 +233,9 @@ ExpEvent.prototype.fromJS = function (data) {
if (data.requirement) {
this.requirementConverter(data);
}

if (data.hasOwnProperty('isGlobal')) {
this.isGlobal(data.isGlobal);
}



Expand Down Expand Up @@ -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(),
};
};

Expand Down
7 changes: 6 additions & 1 deletion eventActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -1838,6 +1839,9 @@ ActionJumpTo.prototype.fromJS = function (data) {
this.checkRequired(data.checkRequired);
}

if (data.hasOwnProperty('jumpTrailType')) {
this.jumpTrailType(data.jumpTrailType);
}

return this;
};
Expand All @@ -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()

};
};
Expand Down
1 change: 1 addition & 0 deletions eventTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 5 additions & 1 deletion frameData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(); }),
Expand Down