Commit 8a767f04 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Implemented Checkbox.js. Use concat-in-order in Gruntfile, required by JavaScript Elements.

parent a0ee2962
var path = require('path');
module.exports = function (grunt) {
var typo3_css = 'extension/Resources/Public/Css/';
var typo3_js = 'extension/Resources/Public/JavaScript/';
......@@ -181,14 +182,50 @@ module.exports = function (grunt) {
'javascript/src/*.js'
]
},
concat: {
concat_in_order: {
debug_standalone: {
src: js_sources,
dest: 'js/<%= pkg.name %>.debug.js'
options: {
extractRequired: function (filepath, filecontent) {
var workingdir = path.normalize(filepath).split(path.sep);
workingdir.pop();
var deps = this.getMatches(/\*\s*@depend\s(.*\.js)/g, filecontent);
deps.forEach(function (dep, i) {
var dependency = workingdir.concat([dep]);
deps[i] = path.join.apply(null, dependency);
});
return deps;
},
extractDeclared: function (filepath) {
return [filepath];
},
onlyConcatRequiredFiles: false
},
files: {
'js/<%= pkg.name %>.debug.js': js_sources
}
},
debug_extension: {
src: js_sources,
dest: typo3_js + '<%= pkg.name %>.debug.js'
options: {
extractRequired: function (filepath, filecontent) {
var workingdir = path.normalize(filepath).split(path.sep);
workingdir.pop();
var deps = this.getMatches(/\*\s*@depend\s(.*\.js)/g, filecontent);
deps.forEach(function (dep, i) {
var dependency = workingdir.concat([dep]);
deps[i] = path.join.apply(null, dependency);
});
return deps;
},
extractDeclared: function (filepath) {
return [filepath];
},
onlyConcatRequiredFiles: false
},
files: {
'extension/Resources/Public/JavaScript/<%= pkg.name %>.debug.js': js_sources
}
}
},
less: {
......@@ -234,7 +271,7 @@ module.exports = function (grunt) {
'javascript/src/Element/*.js',
'less/qfq-bs.css.less'
],
tasks: [ 'default' ],
tasks: ['default'],
options: {
spawn: true
}
......@@ -247,14 +284,15 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-concat-in-order');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-jasmine');
// Default task(s).
grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'copy', 'less']);
grunt.registerTask('default', ['jshint', 'concat_in_order', 'uglify', 'copy', 'less']);
grunt.registerTask('run-jasmine', ['jshint', 'concat', 'jasmine']);
grunt.registerTask('run-jasmine', ['jshint', 'concat_in_order', 'jasmine']);
};
\ No newline at end of file
/**
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
/* @depend Element.js */
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
(function (n) {
'use strict';
/**
*
* @param $element
* @constructor
*/
function Checkbox($element) {
n.Element.call(this, $element);
if (!this.isType("checkbox")) {
throw new Error("$element is not of type 'checkbox'");
}
}
Checkbox.prototype = Object.create(n.Element.prototype);
Checkbox.prototype.constructor = Checkbox;
Checkbox.prototype.setValue = function (val) {
this.formGroup.$element.prop('checked', val);
};
Checkbox.prototype.getValue = function () {
return this.formGroup.$element.prop('checked');
};
n.Checkbox = Checkbox;
})(QfqNS.Element);
......@@ -27,6 +27,7 @@
<script src="spec/ElementTextSpec.js"></script>
<script src="spec/ElementRadioSpec.js"></script>
<script src="spec/ElementSelectSpec.js"></script>
<script src="spec/ElementCheckboxSpec.js"></script>
<script src="spec/BSTabsSpec.js"></script>
<script src="spec/PageTitleSpec.js"></script>
<script src="spec/FormSpec.js"></script>
......@@ -277,7 +278,27 @@
<div class="col-md-6">
<div class="checkbox">
<label>
<input type="checkbox">
<input name='reminder' type="checkbox">
</label>
</div>
</div>
<div class="col-md-4">
<p class="help-block">Empfängt 'Reminder'-Mails für Veranstaltungen.</p>
</div>
</div>
<div class="form-group">
<div class="col-md-2">
<b class="control-label">
Checkbox 2 test
</b>
</div>
<div class="col-md-6">
<div class="checkbox">
<label>
<input name='checkbox2' type="checkbox" value="reminder_value" checked>
</label>
</div>
......
/**
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
/* global describe */
/* global it */
/* global expect */
/* global QfqNS */
/* global beforeAll */
/* global beforeEach */
/* global jasmine */
/* global $ */
describe("Element Checkbox", function () {
'use strict';
var reminderCheckbox, checkbox2;
var $reminderCheckbox, $checkbox2;
beforeAll(function () {
$reminderCheckbox = $('input[name=reminder]');
$checkbox2 = $('input[name=checkbox2]');
reminderCheckbox = new QfqNS.Element.Checkbox($reminderCheckbox);
checkbox2 = new QfqNS.Element.Checkbox($checkbox2);
});
beforeEach(function () {
$('#myForm')[0].reset();
});
it('should get the initial checked value', function () {
expect(reminderCheckbox.getValue()).toBe(false);
expect(checkbox2.getValue()).toBe(true);
});
it('should reflect dynamically changed values', function () {
$reminderCheckbox.prop('checked', true);
$checkbox2.prop('checked', false);
expect(reminderCheckbox.getValue()).toBe(true);
expect(checkbox2.getValue()).toBe(false);
});
it('should set value properly', function () {
reminderCheckbox.setValue(true);
checkbox2.setValue(false);
expect($reminderCheckbox.prop('checked')).toBe(true);
expect($checkbox2.prop('checked')).toBe(false);
});
});
\ No newline at end of file
Supports Markdown
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