Commit 09a1e5c2 authored by gijs's avatar gijs

Transformed effectif into a rangefield, also a migration. Only show the...

Transformed effectif into a rangefield, also a migration. Only show the performance author is score_type is translation or transcription
parent c31dcffb
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-01-30 12:15
from __future__ import unicode_literals
import django.contrib.postgres.fields.jsonb
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('playground', '0011_auto_20180129_2000'),
]
operations = [
migrations.RemoveField(
model_name='score',
name='effectif'
),
migrations.AddField(
model_name='score',
name='effectif',
field=django.contrib.postgres.fields.jsonb.JSONField(default={}),
preserve_default=False,
),
]
......@@ -23,7 +23,7 @@ class Score(models.Model):
score_author = models.TextField(blank=True)
performance_author = models.TextField(blank=True)
presentation = models.TextField(blank=True)
effectif = models.CharField(blank=True, max_length=255)
effectif = JSONField(blank=True)
stage_set = models.TextField(blank=True)
duration = models.TextField(blank=True)
genre = models.TextField(blank=True)
......
......@@ -462,17 +462,6 @@ section.hidden {
display: none;
}
.score-actions {
margin-top: 2em;
margin-bottom: 1em;
padding-top: 1em;
border-top: 2px solid black;
}
.score-actions button {
margin: .25em;
}
.score-form {
position: absolute;
top: 0;
......
......@@ -818,6 +818,12 @@ window.W = window.W || {};
});
W.EffectifField = W.RangeField.extend({
template: '#field-effectif-template',
enabled: function () { return true },
});
W.ScoreForm = Backbone.Marionette.View.extend({
template: '#score-template-form',
......@@ -830,26 +836,37 @@ window.W = window.W || {};
'close': '[data-name="close"]',
},
regions: {
effectif: {
el: '[data-name="effectif"]',
replaceElement: true
},
},
events: {
'click @ui.submit': 'submit'
'click @ui.submit': 'submit',
'change [name="score_type"]': 'onChangeScoreType'
},
triggers: {
'click @ui.close': 'form:close'
},
templateContext: function () {
return { rangeType: rangeType };
},
/**
* Return input field with name
*/
field: function (name) {
return this.$el.find('[name="' + name + '"]');
},
/**
* Return value for field with name.
* Integer fields are converted to numbers
* All other fields are trimmed.
*/
* Return value for field with name.
* Integer fields are converted to numbers
* All other fields are trimmed.
*/
fieldVal: function (name) {
const field = this.field(name);
......@@ -868,14 +885,31 @@ window.W = window.W || {};
}
}
return null;
return "";
},
onRender: function () {
const effectifField = new W.EffectifField({
label: 'effectif',
value: this.model.get('effectif')
});
this.showChildView('effectif', effectifField);
},
onChangeScoreType: function (e) {
if (parseInt(this.fieldVal('score_type')) === 1) {
this.field('performance_author').prop('disabled', true);
} else {
this.field('performance_author').prop('disabled', false);
}
},
submit: function (e) {
e.stopImmediatePropagation();
e.preventDefault();
console.log(this.fieldVal("performance_author"));
console.log(this.getChildView('effectif').value());
const data = {
title: this.fieldVal('title'),
......@@ -883,7 +917,7 @@ window.W = window.W || {};
score_author: this.fieldVal('score_author'),
performance_author: this.fieldVal('performance_author'),
presentation: this.fieldVal('presentation'),
effectif: this.fieldVal('effectif'),
effectif: this.getChildView('effectif').value(),
stage_set: this.fieldVal('stage_set'),
duration: this.fieldVal('duration'),
genre: this.fieldVal('genre'),
......@@ -944,7 +978,8 @@ window.W = window.W || {};
templateContext: function () {
return {
hasChanges: this.hasChanges,
depth: this.model.getDepth()
depth: this.model.getDepth(),
rangeType: rangeType
};
},
......
......@@ -27,6 +27,10 @@
{% include "playground/underscore/score-vue.mtpl" %}
</script>
<script id="field-effectif-template" type="text/template">
{% include "playground/underscore/field-effectif.mtpl" %}
</script>
<script id="score-template-form" type="text/template">
{% include "playground/underscore/score-form.mtpl" %}
</script>
......
<label>
Effectif: <br />
<select name="type">
<option value="<%= rangeType.undetermined %>" <% if (!type || type == rangeType.undetermined) { %>selected<% } %>>
indeterminé
</option>
<option value="<%= rangeType.exact %>" <% if (type == rangeType.exact) { %>selected<% } %>>
exactement
</option>
<option value="<%= rangeType.minimal %>" <% if (type == rangeType.minimal) {%>selected<% } %>>
au moins
</option>
<option value="<%= rangeType.range %>" <% if (type == rangeType.range){ %>selected<% } %>>
entre
</option>
</select>
<section data-range-type="<%= rangeType.exact %>" class="type-fields inline">
<input type="number" name="exact" min="2" class="small-number" value="<%= (type == rangeType.exact) ? value : 2 %>" />
</section>
<section data-range-type="<%= rangeType.minimal %>" class="type-fields inline">
<input type="number" name="minimal" min="2" class="small-number" value="<%= (type == rangeType.minimal) ? value : 2 %>" />
</section>
<section data-range-type="<%= rangeType.range %>" class="type-fields inline">
<input type="number" name="range-min" min="2" class="small-number" value="<%= (type == rangeType.range) ? value[0] : 2 %>" /> et
<input type="number" name="range-max" min="3" class="small-number" value="<%= (type == rangeType.range) ? value[1] : 3 %>" />
</section>
performeurs
</label>
\ No newline at end of file
......@@ -24,7 +24,7 @@
<!-- Performance author -->
<label>
<span class="label-text">Auteur de la perfomance:</span>
<input type="text" name="performance_author" value="<%= performance_author %>">
<input type="text" name="performance_author" value="<%= performance_author %>" <%= (score_type === 1) ? 'disabled' : '' %>>
</label>
<!-- description -->
......@@ -34,10 +34,7 @@
</label>
<!-- effectif = models.CharField(blank=True, max_length=255) -->
<label>
<span class="label-text">Effectif:</span>
<input type="text" name="effectif" value="<%= effectif %>">
</label>
<label data-name="effectif">Effectif</label>
<!-- Setting -->
<label>
......
......@@ -37,7 +37,7 @@
<dt>Auteur de la performance</dt>
<dd><%= performance_author %></dd>
<% } %>
<% if (score_author) { %>
<% if (score_author && (score_type === 2 || score_type === 3)) { %>
<dt>Auteur de la partition</dt>
<dd><%= score_author %></dd>
<% } %>
......@@ -45,10 +45,19 @@
<dt>Présentation</dt>
<dd><%= presentation %></dd>
<% } %>
<% if (effectif) { %>
<dt>Effectif</dt>
<dd><%= effectif %></dd>
<% } %>
<dd>
<% if (effectif && effectif.type === rangeType.exact) { %>
<%= effectif.value %>
<% } else if (effectif && effectif.type === rangeType.minimal) { %>
au moins <%= effectif.value %>
<% } else if (effectif && effectif.type === rangeType.range) { %>
entre <%= effectif.value[0] %> ét <%= effectif.value[1] %>
<% } else { %>
indeterminé nombre de
<% } %>
performeurs
</dd>
<% if (stage_set) { %>
<dt>Mise</dt>
<dd><%= stage_set %></dd>
......@@ -63,11 +72,6 @@
<% } %>
</dl>
<div class="score-actions">
<button class="unfold">Tout déplier</button>
<button class="fold">Tout plier</button><br /><br />
</div>
<form></form>
</header>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment