Skip to content

Commit 4c391f9

Browse files
author
Mike White
committed
major refactoring
Use RequireJS, eliminate the formdesigner singleton with controller, model, and ui having tangled inter-references including a bunch of event soup, in favor of well-defined coponents using events only for loose coupling. See https://gist.github.com/mwhite/10e42de5b24b3437a610 for additional explanation. This removes the recently added duplicate ID renaming on save, in favor of, when the nodeID property is changed via a widget change, short-circuiting the change if a sibling has the same nodeID, and then behaving similarly to when the XPath editor has unsaved changes until you've finished entering a valid nodeID. In service of this, the "unsaved changes" short-circuiting now fires on several other events besides selecting a node: - adding a question - saving the form - selecting any tools menu item - moving a question Currently these are all done explicitly, although it might be possible to have fewer locations where the check is called by putting it in e.g. beforeSerialize(). This also manages all of the media uploader dependencies using RequireJS. Fixes: - #59: use RequireJS - #84: choice icon in tree should change when moving from single to multiple answer or vice versa
1 parent 23c7cd0 commit 4c391f9

File tree

151 files changed

+44438
-11368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+44438
-11368
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/bower_components
2-
/dist/*.map
3-
/dist/*.tmp.css
4-
/dist/vellum.css
5-
/dist/vellum.js
6-
/js/node_modules
72
/node_modules
8-
/src/less/*.css
3+
/dist/*
94

105
npm-debug.log
116
*~

Gruntfile.js

Lines changed: 12 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,24 @@
1-
var fs = require('fs'),
2-
exec = require('child_process').exec,
3-
_ = require('underscore');
4-
51
module.exports = function (grunt) {
6-
_.each([
7-
'grunt-contrib-concat',
8-
'grunt-contrib-cssmin',
9-
'grunt-contrib-less',
10-
'grunt-contrib-uglify',
11-
'grunt-image-embed',
12-
], grunt.loadNpmTasks);
2+
grunt.loadNpmTasks('grunt-exec');
133

144
grunt.registerTask('dist', [
15-
'less',
16-
'imageEmbed',
17-
'concat:css',
18-
'cssmin',
19-
'concat:js',
20-
'uglify'
5+
'exec:dist'
6+
]);
7+
8+
grunt.registerTask('dist-min', [
9+
'exec:dist-min'
2110
]);
2211

2312
grunt.initConfig({
24-
less: {
25-
main: {
26-
files: {
27-
"src/less/main.css": "src/less/main.less"
28-
}
29-
}
30-
},
31-
imageEmbed: {
13+
exec: {
3214
dist: {
33-
src: [
34-
"src/js/lib/jstree/default/style.css",
35-
"src/css/redmond/jquery-ui-1.8.14.custom.css"
36-
],
37-
dest: "dist/image-embedded.tmp.css"
38-
}
39-
},
40-
concat: {
41-
css: {
42-
nonull: true,
43-
src: [
44-
'src/js/lib/codemirror/codemirror.css',
45-
'src/js/lib/fancybox/jquery.fancybox-1.3.4.css',
46-
'dist/image-embedded.tmp.css',
47-
'src/less/main.css'
48-
],
49-
dest: 'dist/vellum.css'
50-
},
51-
js: {
52-
nonull: true,
53-
options: {
54-
separator: ';'
55-
},
56-
src: [
57-
'bower_components/xpath/lib/biginteger.js',
58-
'bower_components/xpath/lib/schemeNumber.js',
59-
'bower_components/xpath/models.js',
60-
'bower_components/xpath/xpath.js',
61-
62-
'src/js/lib/jstree/jquery.jstree.js',
63-
'bower_components/bootstrap-better-typeahead/js/bootstrap-better-typeahead.js',
64-
'src/js/lib/fancybox/jquery.fancybox-1.3.4.js',
65-
'src/js/lib/sha1.js',
66-
'src/js/lib/diff_match_patch.js',
67-
'bower_components/XMLWriter/XMLWriter.js',
68-
'src/js/lib/codemirror/codemirror.js',
69-
'src/js/lib/codemirror/xml.js',
70-
'node_modules/classy/classy.js',
71-
'src/js/formdesigner.javarosa.js',
72-
'src/js/formdesigner.ignoreButRetain.js',
73-
'src/js/formdesigner.lock.js',
74-
'src/js/window.js',
75-
'src/js/util.js',
76-
'src/js/multimedia.js',
77-
'src/js/widgets.js',
78-
'src/js/model.js',
79-
'src/js/controller.js',
80-
'src/js/ui.js',
81-
'src/js/itemset.js'
82-
],
83-
dest: 'dist/vellum.js'
84-
}
85-
},
86-
cssmin: {
87-
combine: {
88-
files: {
89-
'dist/vellum.min.css': ['dist/vellum.css']
15+
cmd: function () {
16+
return 'r.js -o build.js';
9017
}
91-
}
92-
},
93-
uglify: {
94-
options: {
95-
// the banner is inserted at the top of the output
96-
banner: '/*! Vellum <%= grunt.template.today("dd-mm-yyyy") %> \n' +
97-
' Copyright 2009-2014, Dimagi Inc., and individual contributors \n' +
98-
' Released under the MIT License \n' +
99-
' http://github.com/dimagi/Vellum */\n',
100-
sourceMap: true,
101-
preserveComments: false,
102-
mangle: false
10318
},
104-
dist: {
105-
files: {
106-
'dist/vellum.min.js': ['dist/vellum.js']
19+
"dist-min": {
20+
cmd: function () {
21+
return 'r.js -o build-min.js';
10722
}
10823
}
10924
}

LICENSE.TXT renamed to LICENSE.txt

File renamed without changes.

README.md

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,69 @@ Vellum is a JavaRosa [XForm](http://en.wikipedia.org/wiki/XForms) designer built
1111
Usage
1212
-----
1313

14-
Vellum depends on jQuery, Underscore.js, and Bootstrap. Other dependencies are
15-
bundled and included in `dist/vellum.js` and `dist/vellum.css`, but some
16-
additional dependencies that are part of [CommCare
17-
HQ](http://github.com/dimagi/commcare-hq) aren't well-defined yet.
18-
19-
For an example of a minimal setup and usage of Vellum, including all known
20-
dependencies, see `tests/index.html`.
21-
22-
For some additional configuration options, see
23-
[`form_designer.html`](https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/app_manager/templates/app_manager/form_designer.html)
24-
in CommCare HQ.
25-
26-
27-
Contributing
28-
------------
29-
3014
### Setup
3115

3216
Install dependencies:
3317
```
34-
$ npm install -g bower
18+
$ npm install -g bower requirejs
3519
$ npm install
3620
```
3721

38-
Create build artifacts for each commit:
22+
There are three ways to load Vellum, depending on whether you want asychronous
23+
module loading, and whether jQuery, jQueryUI, and Bootstrap are already loaded
24+
on the page.
25+
26+
Asynchronous, will use existing jQuery, jQueryUI, Boostrap (V2) plugins if present:
27+
```html
28+
<script src="bower_components/requirejs/require.js"></script>
29+
<script>
30+
require.config({
31+
baseUrl: '/path/to/vellum/src'
32+
});
33+
</script>
34+
```
35+
36+
Bundled with all dependencies:
3937
```
4038
$ grunt dist
4139
```
4240

41+
```html
42+
<script src="dist/main.min.js"></script>
43+
<script>
44+
</script>
45+
```
46+
47+
Bundled with all dependencies except jQuery, jQuery UI, and Bootstrap plugins,
48+
expects them already to be loaded:
49+
```
50+
$ grunt dist-min
51+
```
52+
53+
```html
54+
<script src="dist/main.no-jquery.min.js"></script>
55+
<script>
56+
</script>
57+
```
58+
59+
Finally, for all three:
60+
```javascript
61+
require(["main"], function ($) {
62+
$("#formdesigner").vellum(options)
63+
});
64+
```
65+
66+
67+
### Options
68+
69+
Todo
70+
71+
72+
Contributing
73+
------------
74+
75+
### Tests
76+
4377
Run tests in a browser:
4478
```
4579
$ python -m SimpleHTTPServer
@@ -65,20 +99,3 @@ master always contains the latest stable version.
6599
[release](http://vellum-release.herokuapp.com), and
66100
[develop](http://vellum-develop.herokuapp.com) are automatically deployed for
67101
testing.
68-
69-
70-
Event Tracking
71-
--------------
72-
73-
If you have Google Analytics installed, Vellum will track events.
74-
75-
76-
Changelog
77-
---------
78-
79-
### 1.5.0
80-
81-
- Added Ignore-but-retain and question locking plugins
82-
- Fixed ability to Ctrl-F within source XML editor
83-
- Added testing infrastructure
84-
- Added Grunt build to generate JS and CSS

bower.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@
2121
"tests"
2222
],
2323
"dependencies": {
24+
"almond": "~0.2.9",
2425
"underscore": "~1.5.2",
2526
"jquery": "==1.7",
2627
"jquery.ui": "1.8.16",
28+
"requirejs": "~2.1.11",
29+
"requirejs-text": "~2.0.12",
30+
"require-less": "*",
31+
"require-css": "*",
32+
"requirejs-tpl": "jfparadis/requirejs-tpl",
2733

28-
"XMLWriter": "alexandern/XMLWriter#314f56f53bdc3cb76bd12a7db837be6710e0236f",
34+
"langcodes": "dimagi/langcodes",
35+
"XMLWriter": "dimagi/XMLWriter",
2936
"classy": "mitsuhiko/classy#1.4",
3037
"xpath": "dimagi/js-xpath",
3138
"bootstrap-better-typeahead": "ptnplanet/Bootstrap-Better-Typeahead"
3239
},
3340
"devDependencies": {
34-
"equivalent-xml-js": "theozaurus/equivalent-xml-js",
35-
"less.js": "~1.3.3",
41+
"equivalent-xml-js": "mwhite/equivalent-xml-js",
3642
"sinonjs": ">=1.6.0",
3743
"when": "~2.8.0",
3844
"chai": ">=1.5.0"

dist/.gitkeep

Whitespace-only changes.

dist/vellum.min.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/vellum.min.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

index.html

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1-
<html>
2-
<head>
3-
<meta http-equiv="refresh" content="0; url=tests/" />
4-
</head>
1+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
2+
<head>
3+
<title>Vellum Test</title>
4+
5+
<!-- Mocha and test-only dependencies -->
6+
<link href="node_modules/mocha/mocha.css" type="text/css" rel="stylesheet"></link>
7+
<script src="node_modules/mocha/mocha.js"></script>
8+
<script src="bower_components/chai/chai.js"></script>
9+
<script src="bower_components/sinonjs/sinon.js"></script>
10+
11+
<script src="bower_components/equivalent-xml-js/src/equivalent-xml.js"></script>
12+
<script src="bower_components/jquery.ui/tests/jquery.simulate.js"></script>
13+
<script src="tests/utils.js"></script>
14+
15+
16+
<!-- Runtime Dependencies -->
17+
<link href="tests/lib/hqstyle-core.css" type="text/css" rel="stylesheet"></link>
18+
<!--<script src="../src/js/saveButton.js"></script>-->
19+
20+
<script data-main="tests/main" src="bower_components/requirejs/require.js"></script>
21+
</head>
22+
23+
<body>
24+
25+
<div id="matrix">
26+
</div>
27+
28+
<!-- Tests and running -->
29+
<script src="tests/formdesigner.ignoreButRetain.js"></script>
30+
<script src="tests/formdesigner.lock.js"></script>
31+
<script src="tests/itemset.js"></script>
32+
</body>
533
</html>

lib/MediaUploader/README.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YUI files contain the uploader and node-core modules from
2+
http://yuilibrary.com/yui/configurator/.

0 commit comments

Comments
 (0)