[virtualcommons-developer] commit/vcweb: alllee: sendUpdateEvent needs to be embedded in the callba
Status: Beta
Brought to you by:
alllee
|
From: <com...@bi...> - 2013-03-21 07:40:13
|
1 new commit in vcweb: https://bitbucket.org/virtualcommons/vcweb/commits/7f7cd79155ad/ changeset: 7f7cd79155ad user: alllee date: 2013-03-21 08:39:53 summary: sendUpdateEvent needs to be embedded in the callback function. JS needs some refactoring, looks like we can merge the various confirmAction click bindings into a single confirmExperimentAction click binding and parameterize them at the DOM data-bind site create_round_data now get_or_creates participant ready parameters to avoid creating duplicates affected #: 4 files diff -r fda36cbf963bad78b3dfc3117af3dc0553ce1bee -r 7f7cd79155ad634a78404fa2a4f8ed2aa12576e1 vcweb/boundaries/templates/boundaries/participate.html --- a/vcweb/boundaries/templates/boundaries/participate.html +++ b/vcweb/boundaries/templates/boundaries/participate.html @@ -500,6 +500,7 @@ case 'update': $('#progress-modal').modal('show'); experimentModel.update(); + break; default: console.debug("unhandled json message:" + json); break; diff -r fda36cbf963bad78b3dfc3117af3dc0553ce1bee -r 7f7cd79155ad634a78404fa2a4f8ed2aa12576e1 vcweb/boundaries/views.py --- a/vcweb/boundaries/views.py +++ b/vcweb/boundaries/views.py @@ -55,6 +55,7 @@ def get_view_model(request, experiment_id=None): experiment = get_object_or_404(Experiment.objects.select_related('experiment_metadata', 'experiment_configuration'), pk=experiment_id) pgr = experiment.get_participant_group_relationship(request.user.participant) + logger.debug("getting view model for participant: %s", pgr) return JsonResponse(get_view_model_json(experiment, pgr)) # FIXME: need to distinguish between instructions / welcome rounds and practice/regular rounds diff -r fda36cbf963bad78b3dfc3117af3dc0553ce1bee -r 7f7cd79155ad634a78404fa2a4f8ed2aa12576e1 vcweb/core/models.py --- a/vcweb/core/models.py +++ b/vcweb/core/models.py @@ -12,7 +12,6 @@ from django.template.defaultfilters import slugify from django.template import Context from django.template.loader import select_template -from django.utils.html import escape from django.utils.translation import ugettext_lazy as _ from model_utils import Choices from model_utils.managers import InheritanceManager, PassThroughManager @@ -151,7 +150,6 @@ class Meta: abstract = True - class Experimenter(CommonsUser): approved = models.BooleanField(default=False) class Meta: @@ -760,8 +758,8 @@ # create participant ready data values for every round in experimenter driven experiments logger.debug("creating participant ready participant round data values") for pgr in self.participant_group_relationships: - ParticipantRoundDataValue.objects.create(participant_group_relationship=pgr, boolean_value=False, - parameter=get_participant_ready_parameter(), round_data=round_data) + ParticipantRoundDataValue.objects.get_or_create(participant_group_relationship=pgr, + parameter=get_participant_ready_parameter(), round_data=round_data, defaults={'boolean_value': False}) if not created: logger.debug("already created round data: %s", round_data) return round_data diff -r fda36cbf963bad78b3dfc3117af3dc0553ce1bee -r 7f7cd79155ad634a78404fa2a4f8ed2aa12576e1 vcweb/core/templates/experimenter/monitor.html --- a/vcweb/core/templates/experimenter/monitor.html +++ b/vcweb/core/templates/experimenter/monitor.html @@ -14,8 +14,8 @@ <div class='btn-group'><a class='btn btn-success' data-bind="click: confirmExperimentAction, css: { disabled: isRoundInProgress }" data-action='start_round' data-content='Starts the round.'><i class='icon-play'></i> start</a><a class='btn btn-success' data-bind='click: advanceToNextRound' data-action='advance_to_next_round' data-content='Advances to and starts the next round.'><i class='icon-step-forward'></i> next round</a> - <a class='btn btn-success' data-bind='click: refreshAllParticipants' data-content='Sends a page refresh to all connected participants.' ><i class='icon-exchange'></i> refresh participants</a> - <a class='btn btn-primary' data-bind='click: update' data-content='Refresh this page with the latest data from the server.' ><i class='icon-refresh'></i> update</a> + <a class='btn btn-success' data-bind='click: refreshAllParticipants' data-content='Sends a page refresh to all connected participants.' ><i class='icon-exchange'></i> refresh participants</a>--> + <a class='btn btn-primary' data-bind='click: update' data-content='Refresh this page with the latest data from the server.' ><i class='icon-refresh'></i></a><a class='btn btn-danger' data-bind='click: confirmExperimentAction' data-action='deactivate' data-content='Deactivates this experiment.'><i class='icon-off'></i></a></div></div> @@ -188,7 +188,6 @@ Dajaxice.vcweb.core.get_experiment_model(update(model), {pk: {{experiment.pk}}}); } model.confirmExperimentAction = function(experimentModel, evt) { - console.debug(evt.target); confirmExperimentControllerAction(evt.target, model); } model.advanceToNextRound = function(localModel, evt) { @@ -199,11 +198,11 @@ } }); }; - model.refreshAllParticipants = function(model, evt) { + model.refreshAllParticipants = function(localModel, evt) { confirmAction(evt.target, function(confirmed, action) { if (confirmed) { - console.debug("sending refresh event"); - sendRefreshEvent(); + console.debug("sending update event"); + sendUpdateEvent(); } }); } @@ -218,10 +217,13 @@ function confirmExperimentControllerAction(element, experimentModel, callback) { confirmAction(element, function(confirmed, action) { $('#progress-modal').modal('show'); - Dajaxice.vcweb.core.experiment_controller(update(experimentModel), {pk: {{experiment.pk}}, 'action':action}); - if (callback) { - callback(confirmed, action); - } + Dajaxice.vcweb.core.experiment_controller(function(data) { + ko.mapping.fromJS(data, experimentModel); + if (callback) { + callback(confirmed, action); + } + $('#progress-modal').modal('hide'); + }, {pk: {{experiment.pk}}, 'action':action}); }); } function confirmAction(element, callback) { @@ -240,8 +242,6 @@ } function update(experimentModel) { return function(data) { - ko.mapping.fromJS(data, experimentModel); - $('#progress-modal').modal('hide'); } } function initialize(experimentModelJson) { Repository URL: https://bitbucket.org/virtualcommons/vcweb/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |