Skip to content

Commit

Permalink
Add input field (not complete)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximesangoi authored and maximesangoi committed Jan 8, 2015
1 parent 62eca78 commit 795cd66
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 43 deletions.
7 changes: 3 additions & 4 deletions www/base/src/app/common/directives/fields/checkbox.tpl.jade
@@ -1,4 +1,3 @@
div
label
input(type="checkbox", ng-model="data.value", ng-change="changeSettings(data.name, data.value)", ng-value="data.value")
| {{ data.name }}
label
input(type="checkbox", ng-model="data.value", ng-change="changeSettings(data.name, data.value)", ng-value="data.value" ng-disabled="isDisabled")
| {{ data.name }}
18 changes: 15 additions & 3 deletions www/base/src/app/common/directives/fields/fields.directive.coffee
Expand Up @@ -3,7 +3,7 @@ class bbcheckbox extends Directive('common')
return {
restrict: 'E'
transclude: true
scope: {data:'='}
scope: {data:'=', isDisabled:'='}
templateUrl: 'views/checkbox.html'
controller: '_fieldController'
}
Expand All @@ -13,11 +13,23 @@ class bbradio extends Directive('common')
return {
restrict: 'E'
transclude: true
scope: {data:'='}
scope: {data:'=', isDisabled:'='}
templateUrl: 'views/radio.html'
controller: '_fieldController'
}

class bbinput extends Directive('common')
constructor: (RecursionHelper) ->
return {
restrict: 'E'
replace: true
transclude: true
scope: {data:'=', isDisabled:'='}
templateUrl: 'views/input.html'
controller: '_fieldController'
}

class _field extends Controller('common')
constructor: ($scope) ->
$scope.changeSettings = (settings, value) -> localStorage.setItem(settings, value)
$scope.changeSettings = (settings, value) ->
localStorage.setItem(settings, value)
8 changes: 4 additions & 4 deletions www/base/src/app/common/directives/fields/radio.tpl.jade
@@ -1,4 +1,4 @@
div
label(ng-repeat="(key,answer) in data.answers")
input(type="radio", ng-model="data.value", ng-change="changeSettings(data.name, answer)", ng-value="answer")
| {{ key }}
div(ng-repeat="(key,answer) in data.answers")
label(class="bbradio" class="radio-inline")
input(type="radio" name="{{data.name}}" ng-model="data.value" ng-change="changeSettings(data.name, answer)" ng-value="answer" class="bbradio")
| {{ answer }}
66 changes: 41 additions & 25 deletions www/base/src/app/common/services/fields/fields.service.coffee
Expand Up @@ -2,31 +2,47 @@ class fieldsService extends Factory('common')
constructor: ->
return {

checkbox: (name) ->
if localStorage.getItem(name) isnt undefined
initial_value = localStorage.getItem(name) is "true"
checkbox: (name, model) ->
if localStorage.getItem("#{name}")?
initial_value = localStorage.getItem("#{name}") is "true"
else
initial_value = model

field =
type: 'checkbox'
name: "#{name}"
value: initial_value
return field

radio: (name, model, specific_answers...) ->
default_answers = ["yes", "no"]
answers = default_answers
if specific_answers.length > 0
answers = specific_answers

if localStorage.getItem("#{name}")?
initial_value = localStorage.getItem("#{name}")
else
initial_value = model

field =
name: "#{name}"
type: 'radio'
value: initial_value
answers: answers
return field

input: (name, model) ->
if localStorage.getItem("#{name}")?
initial_value = localStorage.getItem("#{name}")
else
initial_value = model

field =
name: "#{name}"
type: 'text'
value: initial_value
return field

ret =
type: 'checkbox'
name: name
value: initial_value

return ret

radio: (name, answers...) ->
default_answers =
"yes": "yes"
"no" : "no"

if localStorage.getItem(name) isnt undefined
initial_value = localStorage.getItem(name)

ret =
name: name
type: 'radio'
value: initial_value
answers: default_answers

return ret
}

10 changes: 8 additions & 2 deletions www/base/src/app/settings/settings.controller.coffee
Expand Up @@ -3,7 +3,13 @@ class Settings extends Controller
# All settings definition
#

$scope.settings1 = true
$scope.settings5 = "Here is a test"
$scope.val = "First choice"
$scope.settings =
settings1: fieldsService.checkbox("Settings 1")
settings1: fieldsService.checkbox("Settings 1", $scope.settings1)
settings2: fieldsService.checkbox("Settings 2")
settings3: fieldsService.radio("Settings 3")
settings3: fieldsService.radio("Settings 3", $scope.val, "First choice", "Second choice", "Third choice")
settings4: fieldsService.radio("Settings 4", true, "First choice", "Second choice")
settings5: fieldsService.input("Settings 5", $scope.settings5)

23 changes: 18 additions & 5 deletions www/base/src/app/settings/settings.tpl.jade
@@ -1,9 +1,22 @@
.container
.row
.well
h2 About this buildbot
h2 Settings
.row
div
bbcheckbox(data="settings.settings1")
bbcheckbox(data="settings.settings2")
bbradio(data="settings.settings3")
h3 First Settings
form(name="settings1")
div(class="checkbox")
bbcheckbox(data="settings.settings1")
div(class="checkbox")
bbcheckbox(data="settings.settings2")
span(class="help-block" ng-show="settings.settings1.value") Warning : {{ settings.settings1.name }} is checked
h3 Second Settings
form
div(class="radio")
bbradio(data="settings.settings3")
div(class="radio")
bbradio(data="settings.settings4")
h3 Third Settings
form(class="form-horizontal")
div(class="form-group")
bbinput(data="settings.settings5")
4 changes: 4 additions & 0 deletions www/base/src/styles/styles.less
Expand Up @@ -102,3 +102,7 @@
background-color: #ccc
}
}

.bbradio {
margin-right: 20px;
}

0 comments on commit 795cd66

Please sign in to comment.