Skip to content

Commit

Permalink
changed cardinaility setting for checkbox, changed attribue add metho…
Browse files Browse the repository at this point in the history
…d to allow more variability, changed display of checkboxes on post edit to ensure displayed properly
  • Loading branch information
willdoran committed Jan 26, 2016
1 parent 3f69529 commit fa4e945
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
2 changes: 2 additions & 0 deletions app/post/directives/post-editor-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ function (
if (!$scope.post.values[attr.key]) {
if (attr.input === 'location') {
$scope.post.values[attr.key] = [null];
} else if (attr.input === 'checkbox') {
$scope.post.values[attr.key] = [];
} else {
$scope.post.values[attr.key] = [attr.default];
}
Expand Down
22 changes: 10 additions & 12 deletions app/setting/directives/setting-form-editor-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function (
$scope.openNewAttribute = function () {
$scope.isNewAttributeOpen = true;
};
$scope.addNewAttribute = function (type, input, label) {
$scope.addNewAttribute = function (attribute) {
//have to copy as reverse() changes in place
var cloneAttributes = _.clone($scope.form.attributes);
var count = _.countBy($scope.form.attributes, function (attribute) {
Expand All @@ -178,16 +178,13 @@ function (

newAttrCount++;
$scope.isNewAttributeOpen = false;
var attribute = {
type: type,
input: input,
label: 'New ' + label.toLowerCase() + ' field',
required: false,
options: [],
config: {},
priority: lastPriority + 1,
form_stage_id: $scope.visibleStage
};

attribute.label = 'New ' + attribute.label.toLowerCase() + ' field';
attribute.required = false;
attribute.options = [];
attribute.config = {};
attribute.priority = lastPriority + 1;
attribute.form_stage_id = $scope.visibleStage

$scope.form.attributes.push(attribute);
$scope.form.grouped_attributes = _.sortBy($scope.form.attributes, 'form_stage_id');
Expand Down Expand Up @@ -343,7 +340,8 @@ function (
{
label: 'Checkbox',
type: 'varchar',
input: 'checkbox'
input: 'checkbox',
cardinality: 0
},
{
label: 'Related Post',
Expand Down
29 changes: 15 additions & 14 deletions server/www/templates/posts/post-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,22 @@ <h1 class="page-title"><span class="icon-left fa-pencil" translate translate-val
>
{{attribute.label}}
</label>
<!-- type: checkbox -->
<div class="form-field checkbox" ng-if="isCheckbox(attribute)" ng-repeat="option in attribute.options">
<input
type="checkbox"
checklist-model="post.values[attribute.key]"
ng-required="attribute.required"
checklist-value="option"
value="option"
ng-class="{ 'error': form['values_' + attribute.key].$invalid && form['values_' + attribute.key].$dirty }">
<label>
{{option}}
</label>
</div>

<div ng-repeat="(key, value) in post.values[attribute.key] track by key">
<div ng-class="{ 'input-inline' : canRemoveValue(attribute, key) }">
<div ng-if="!isCheckbox(attribute)">
<!-- type: date -->
<div class="input-inline" ng-if="isDate(attribute)">
<input
Expand Down Expand Up @@ -195,11 +209,6 @@ <h1 class="page-title"><span class="icon-left fa-pencil" translate translate-val
<option ng-repeat="opt in attribute.options" value="{{opt}}">{{opt}}</option>
</select>

<!-- type: checkbox -->
<div class="input-group" ng-if="isCheckbox(attribute)">
<label class="checkbox-label">{{attribute.label}} <input name="values_{{attribute.key}}" type="checkbox" ng-model="post.values[attribute.key][key]" ng-required="attribute.required" value="1" ng-class="{ 'error': form['values_' + attribute.key].$invalid && form['values_' + attribute.key].$dirty }"></label>
</div>

<!-- type: radio -->
<div class="input-group" ng-if="isRadio(attribute)">
<label class="radio-label" ng-repeat="opt in attribute.options">{{opt}}
Expand Down Expand Up @@ -257,11 +266,6 @@ <h1 class="page-title"><span class="icon-left fa-pencil" translate translate-val
ng-required="attribute.required"
ng-class="{ 'error': form['values_' + attribute.key].$invalid && form['values_' + attribute.key].$dirty }"></textarea>

<button
type="button"
class="button-secondary icon-only alt trash"
ng-if="canRemoveValue(attribute, key)"
ng-click="removeValue(attribute, key)"></button>
</div>
</div>

Expand All @@ -270,9 +274,6 @@ <h1 class="page-title"><span class="icon-left fa-pencil" translate translate-val
class="alert error"
translate="{{'post.valid.values.' + error}}"
translate-values="{ label : attribute.label }"></p>

<button type="button" class="plus" ng-if="canAddValue(attribute)" ng-click="addValue(attribute)">Add</button>

</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion server/www/templates/settings/forms/form-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ <h2 class="delta-alt">Fields</h2>
<modal title="form.add_field" visible="isNewAttributeOpen">
<div class="cards-select">
<div class="selection-card" ng-repeat="type in availableAttrTypes">
<a ng-click="addNewAttribute(type.type, type.input, type.label)" >
<a ng-click="addNewAttribute(type)" >
<h3>{{ type.label }}</h3>
</a>
</div>
Expand Down

0 comments on commit fa4e945

Please sign in to comment.