fdebc3d1 by Adam Heath

First set of sharable backbone models; they don't do a whole lot yet.

1 parent 31f6715f
1 {
2 "directory": "src/lib"
3 }
1 .*.swp 1 .*.swp
2 .tmp/
3 bin/coverage/
4 dist/
5 node_modules/
6 src/lib/
......
1 // Generated on 2014-02-06 using generator-webapp 0.4.7
2 /* global module */
3
4 // # Globbing
5 // for performance reasons we're only matching one level down:
6 // 'test/spec/{,*/}*.js'
7 // use this if you want to recursively match all subfolders:
8 // 'test/spec/**/*.js'
9
10 module.exports = function (grunt) {
11 /* global require */
12 'use strict';
13
14 var jasmineRequirejsTemplateOptions = function(withInstanbul) {
15 /* global requirejs */
16 var callback;
17 if (withInstanbul) {
18 callback = function() {
19 var oldLoad = requirejs.load;
20 requirejs.load = function (context, moduleName, url) {
21 //console.log('context=' + JSON.stringify(arguments), 'moduleName=' + moduleName, 'url=' + url);
22 var parts = url.split('/');
23 for (var i = 0; i < parts.length; ) {
24 var part = parts[i];
25 if (part === '.') {
26 parts.splice(i, 1);
27 } else if (part === '') {
28 parts.splice(i, 1);
29 } else if (part === '..') {
30 if (i > 0) {
31 i--;
32 parts.splice(i, 2);
33 } else {
34 parts.splice(i, 1);
35 }
36 } else {
37 i++;
38 }
39 }
40 url = parts.join('/');
41 if (url.indexOf('src/scripts/') === 0) {
42 url = './.grunt/grunt-contrib-jasmine/' + url;
43 }
44 //console.log('url=' + url);
45 return oldLoad.apply(this, [context, moduleName, url]);
46 };
47 };
48 }
49 return {
50 requireConfigFile: '<%= yeoman.src %>/scripts/config.js',
51 requireConfig: {
52 baseUrl: '<%= yeoman.src %>/scripts',
53 callback: callback
54 }
55 };
56 };
57
58 var jasmineInstanbulTemplateOptions = function(nestedTemplate, nestedOptions) {
59 return {
60 coverage: 'bin/coverage/coverage.json',
61 report: 'bin/coverage',
62 replace: false,
63 template: require(nestedTemplate),
64 templateOptions: nestedOptions
65 };
66 };
67
68 // Load grunt tasks automatically
69 require('load-grunt-tasks')(grunt);
70
71 // Time how long tasks take. Can help when optimizing build times
72 require('time-grunt')(grunt);
73
74 // Define the configuration for all the tasks
75 grunt.initConfig({
76 bower: {
77 target: {
78 options: {
79 exclude: [
80 'requirejs',
81 ]
82 },
83 rjsConfig: '<%= yeoman.src %>/scripts/config.js'
84 }
85 },
86
87 // Project settings
88 yeoman: {
89 // Configurable paths
90 app: 'app',
91 dist: 'dist',
92 src: 'src',
93 },
94
95 // Watches files for changes and runs tasks based on the changed files
96 watch: {
97 js: {
98 files: ['<%= yeoman.src %>/scripts/{,*/}*.js'],
99 tasks: ['jshint'],
100 },
101 jstest: {
102 files: ['test/spec/{,*/}*.js'],
103 tasks: ['test:watch']
104 },
105 gruntfile: {
106 files: ['Gruntfile.js']
107 },
108 styles: {
109 files: ['<%= yeoman.src %>/styles/{,*/}*.css'],
110 tasks: ['newer:copy:styles', 'autoprefixer']
111 }
112 },
113
114 // The actual grunt server settings
115 connect: {
116 options: {
117 port: 9000,
118 // Change this to '0.0.0.0' to access the server from outside
119 hostname: 'localhost'
120 },
121 app: {
122 options: {
123 open: false,
124 base: [
125 '.tmp',
126 '<%= yeoman.src %>'
127 ]
128 }
129 },
130 test: {
131 options: {
132 port: 9001,
133 base: [
134 '.tmp',
135 'test',
136 '<%= yeoman.src %>'
137 ]
138 }
139 },
140 dist: {
141 options: {
142 open: false,
143 base: '<%= yeoman.dist %>',
144 }
145 }
146 },
147
148 // Empties folders to start fresh
149 clean: {
150 dist: {
151 files: [{
152 dot: true,
153 src: [
154 '.tmp',
155 '<%= yeoman.dist %>/*',
156 '!<%= yeoman.dist %>/.git*'
157 ]
158 }]
159 },
160 server: '.tmp'
161 },
162
163 // Make sure code styles are up to par and there are no obvious mistakes
164 jshint: {
165 options: {
166 browser: true,
167 esnext: true,
168 bitwise: true,
169 camelcase: true,
170 curly: true,
171 eqeqeq: true,
172 immed: true,
173 indent: 4,
174 latedef: true,
175 newcap: true,
176 noarg: true,
177 quotmark: 'single',
178 undef: true,
179 unused: true,
180 strict: true,
181 trailing: true,
182 smarttabs: true,
183 jquery: true,
184 reporter: require('jshint-stylish')
185 },
186 all: [
187 'Gruntfile.js',
188 ],
189 scripts: {
190 options: {
191 globals: {
192 define: false,
193 }
194 },
195 files: {
196 src: [
197 '<%= yeoman.src %>/scripts/**/*.js',
198 '!<%= yeoman.src %>/scripts/vendor/*',
199 ]
200 }
201 },
202 specs: {
203 options: {
204 globals: {
205 define: false,
206 describe: false,
207 expect: false,
208 it: false,
209 }
210 },
211 files: {
212 src: [
213 'test/specs/**/*.spec.js'
214 ]
215 }
216 }
217 },
218
219 jasmine: {
220 all: {
221 src: '<%= yeoman.src %>/scripts/{,**/}*.js',
222 options: {
223 specs: 'test/specs/**/*.spec.js',
224 template: require('grunt-template-jasmine-istanbul'),
225 templateOptions: jasmineInstanbulTemplateOptions('grunt-template-jasmine-requirejs', jasmineRequirejsTemplateOptions(true))
226 }
227 }
228 },
229
230 // Mocha testing framework configuration options
231 mocha: {
232 all: {
233 options: {
234 run: true,
235 urls: ['http://<%= connect.test.options.hostname %>:<%= connect.test.options.port %>/index.html']
236 }
237 }
238 },
239
240 // Add vendor prefixed styles
241 autoprefixer: {
242 options: {
243 browsers: ['last 1 version']
244 },
245 dist: {
246 files: [{
247 expand: true,
248 cwd: '.tmp/styles/',
249 src: '{,*/}*.css',
250 dest: '.tmp/styles/'
251 }]
252 }
253 },
254
255 // Automatically inject Bower components into the HTML file
256 'bower-install': {
257 app: {
258 html: '<%= yeoman.src %>/index.html',
259 ignorePath: '<%= yeoman.src %>/'
260 }
261 },
262
263 // Renames files for browser caching purposes
264 rev: {
265 dist: {
266 files: {
267 src: [
268 '<%= yeoman.dist %>/scripts/*/**/*.js',
269 '<%= yeoman.dist %>/scripts/!(config)*.js',
270 '<%= yeoman.dist %>/styles/{,*/}*.css',
271 '<%= yeoman.dist %>/images/{,*/}*.{gif,jpeg,jpg,png,webp}',
272 '<%= yeoman.dist %>/styles/fonts/{,*/}*.*'
273 ]
274 }
275 },
276 requireconfig: {
277 files: {
278 src: [
279 '<%= yeoman.dist %>/scripts/config.js'
280 ]
281 }
282 }
283 },
284
285 requirejs: {
286 dist: {
287 options: {
288 done: function(done) {
289 var requireModules = grunt.config('requireModules') || {};
290 var lines = [
291 'require.bundles = (function(bundles) {',
292 ];
293 for (var key in requireModules) {
294 var keyS = JSON.stringify(key);
295 var value = requireModules[key];
296 var included = [];
297 for (var i = 0; i < value.included.length; i++) {
298 var file = value.included[i];
299 if (file.match(/\.js$/)) {
300 included.push(file.substring(0, file.length - 3));
301 }
302 }
303 lines.push('bundles[' + keyS + '] = ' + JSON.stringify(included) + ';');
304 }
305 lines.push('return bundles;');
306 lines.push('})(require.bundles || {});');
307 grunt.file.write('.tmp/scripts/bundles.js', lines.join('\n'));
308 done();
309 },
310 baseUrl: '<%= yeoman.src %>/scripts',
311 mainConfigFile: '<%= yeoman.src %>/scripts/config.js',
312 wrapShim: true,
313 dir: '<%= yeoman.dist %>/scripts',
314 optimize: 'none',
315 removeCombined: true,
316 onModuleBundleComplete: function(data) {
317 if (data.name.slice(0, 'bundles/'.length) === 'bundles/') {
318 var requireModules = grunt.config('requireModules') || {};
319 requireModules[data.name] = data;
320 grunt.config('requireModules', requireModules);
321 }
322 },
323 modules: [
324 {
325 name: 'main',
326 include: [
327 'jquery',
328 'underscore',
329 'backbone',
330 'backbone-validation',
331 ],
332 },
333 {
334 name: 'bundles/ofbiz-Base',
335 create: true,
336 exclude: [
337 'main',
338 ],
339 include: [
340 'ofbiz/model/Base',
341 ],
342 },
343 {
344 name: 'bundles/ofbiz-ContactMechs',
345 create: true,
346 exclude: [
347 'main',
348 'bundles/ofbiz-Party',
349 ],
350 include: [
351 'ofbiz/model/EmailAddress',
352 'ofbiz/model/TelecomNumber',
353 'ofbiz/model/PostalAddress',
354 ],
355 },
356 {
357 name: 'bundles/ofbiz-Party',
358 create: true,
359 exclude: [
360 'main',
361 'bundles/ofbiz-Base',
362 'bundles/ofbiz-ContactMechs',
363 ],
364 include: [
365 'ofbiz/model/Party',
366 'ofbiz/model/Person',
367 'ofbiz/model/PartyGroup',
368 ],
369 },
370 ],
371 }
372 },
373 },
374
375 // Reads HTML for usemin blocks to enable smart builds that automatically
376 // concat, minify and revision files. Creates configurations in memory so
377 // additional tasks can operate on them
378 useminPrepare: {
379 options: {
380 dest: '<%= yeoman.dist %>'
381 },
382 html: '<%= yeoman.src %>/index.html'
383 },
384
385 // Performs rewrites based on rev and the useminPrepare configuration
386 usemin: {
387 options: {
388 assetsDirs: ['<%= yeoman.dist %>']
389 },
390 html: ['<%= yeoman.dist %>/{,*/}*.html'],
391 css: ['<%= yeoman.dist %>/styles/{,*/}*.css']
392 },
393
394 // The following *-min tasks produce minified files in the dist folder
395 imagemin: {
396 dist: {
397 files: [{
398 expand: true,
399 cwd: '<%= yeoman.src %>/images',
400 src: '{,*/}*.{gif,jpeg,jpg,png}',
401 dest: '<%= yeoman.dist %>/images'
402 }]
403 }
404 },
405 svgmin: {
406 dist: {
407 files: [{
408 expand: true,
409 cwd: '<%= yeoman.src %>/images',
410 src: '{,*/}*.svg',
411 dest: '<%= yeoman.dist %>/images'
412 }]
413 }
414 },
415 htmlmin: {
416 dist: {
417 options: {
418 collapseBooleanAttributes: true,
419 collapseWhitespace: true,
420 removeAttributeQuotes: true,
421 removeCommentsFromCDATA: true,
422 removeEmptyAttributes: true,
423 removeOptionalTags: true,
424 removeRedundantAttributes: true,
425 useShortDoctype: true
426 },
427 files: [{
428 expand: true,
429 cwd: '<%= yeoman.dist %>',
430 src: '{,*/}*.html',
431 dest: '<%= yeoman.dist %>'
432 }]
433 }
434 },
435
436 // By default, your `index.html`'s <!-- Usemin block --> will take care of
437 // minification. These next options are pre-configured if you do not wish
438 // to use the Usemin blocks.
439 // cssmin: {
440 // dist: {
441 // files: {
442 // '<%= yeoman.dist %>/styles/main.css': [
443 // '.tmp/styles/{,*/}*.css',
444 // '<%= yeoman.src %>/styles/{,*/}*.css'
445 // ]
446 // }
447 // }
448 // },
449 // uglify: {
450 // dist: {
451 // files: {
452 // '<%= yeoman.dist %>/scripts/scripts.js': [
453 // '<%= yeoman.dist %>/scripts/scripts.js'
454 // ]
455 // }
456 // }
457 // },
458 // concat: {
459 // dist: {}
460 // },
461
462 concat: {
463 requireconfig: {
464 }
465 },
466
467 uglify: {
468 dist: {
469 },
470 requireconfig: {
471 files: {
472 '<%= yeoman.dist %>/scripts/config.js': [
473 '<%= yeoman.dist %>/scripts/config.js',
474 '.tmp/scripts/config.js',
475 ],
476 }
477 }
478 },
479
480 // Copies remaining files to places other tasks can use
481 copy: {
482 dist: {
483 files: [{
484 expand: true,
485 dot: true,
486 cwd: '<%= yeoman.src %>',
487 dest: '<%= yeoman.dist %>',
488 src: [
489 '*.{ico,png,txt}',
490 '.htaccess',
491 'images/{,*/}*.webp',
492 '{,*/}*.html',
493 'styles/fonts/{,*/}*.*'
494 ]
495 }]
496 },
497 styles: {
498 expand: true,
499 dot: true,
500 cwd: '<%= yeoman.src %>/styles',
501 dest: '.tmp/styles/',
502 src: '{,*/}*.css'
503 }
504 },
505
506
507 // Run some tasks in parallel to speed up build process
508 concurrent: {
509 server: [
510 'copy:styles'
511 ],
512 test: [
513 'copy:styles'
514 ],
515 dist: [
516 'copy:styles',
517 'imagemin',
518 'svgmin'
519 ]
520 }
521 });
522
523 grunt.loadNpmTasks('grunt-bower-requirejs');
524
525 grunt.registerTask('revconfig', function () {
526 var prefix = grunt.template.process('<%= yeoman.dist %>/scripts/');
527 var pattern = prefix + '**/*.{js,html}';
528 var files = grunt.file.expand(pattern);
529 var lines = [];
530 grunt.util._.each(files, function(file) {
531 file = file.substring(prefix.length);
532 var res = file.match(/^(.*\/)?([0-9a-f]+)\.([^\/]+)\.([^\.]+)$/);
533 if (!res) {
534 return;
535 }
536 //grunt.log.oklns(JSON.stringify(res));
537 var dir = res[1] || '';
538 //var hash = res[2];
539 var base = res[3];
540 var ext = res[4];
541 var id;
542 if (ext === 'js') {
543 id = dir + base;
544 file = file.substring(0, file.length - ext.length - 1);
545 } else if (ext === 'html') {
546 id = 'text!' + dir + base + '.' + ext;
547 }
548 grunt.log.oklns('map: ' + id + ' -> ' + file);
549 lines.push('require.paths[' + JSON.stringify(id) + ']=' + JSON.stringify(file) + ';\n');
550 });
551 grunt.file.write('.tmp/scripts/config.js', lines.join(''));
552 });
553
554 grunt.registerTask('serve', function (target) {
555 if (target === 'dist') {
556 return grunt.task.run(['build', 'connect:dist:keepalive']);
557 }
558
559 grunt.task.run([
560 'clean:server',
561 'concurrent:server',
562 'autoprefixer',
563 'connect:app',
564 'watch'
565 ]);
566 });
567
568 grunt.registerTask('server', function () {
569 grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
570 grunt.task.run(['serve']);
571 });
572
573 grunt.registerTask('test', function(target) {
574 if (target !== 'watch') {
575 grunt.task.run([
576 'clean:server',
577 'concurrent:test',
578 'autoprefixer',
579 ]);
580 }
581
582 grunt.task.run([
583 'connect:test',
584 'mocha'
585 ]);
586 });
587
588 grunt.registerTask('build', [
589 'clean:dist',
590 'useminPrepare',
591 'requirejs',
592 'concurrent:dist',
593 'autoprefixer',
594 'concat',
595 'cssmin',
596 'uglify:dist',
597 'copy:dist',
598 // 'rev:dist',
599 'revconfig',
600 'uglify:requireconfig',
601 // 'rev:requireconfig',
602 'usemin',
603 'htmlmin'
604 ]);
605
606 grunt.registerTask('dist', [
607 'bower',
608 'newer:jshint',
609 // 'test',
610 'build'
611 ]);
612 grunt.registerTask('default', []);
613 };
1 {
2 "name": "ofbiz-shared",
3 "version": "0.0.0",
4 "authors": [
5 "Adam Heath <doogie@brainfood.com>"
6 ],
7 "private": true,
8 "ignore": [
9 "**/.*",
10 "node_modules",
11 "src/lib",
12 "test"
13 ],
14 "dependencies": {
15 "backbone": "~1.1.0",
16 "backbone-validation": "0.9.1",
17 "requirejs": "~2.1.10"
18 }
19 }
1 {
2 "name": "ofbiz-shared",
3 "version": "0.0.0",
4 "_main": [
5 "dist/scripts/bundles/ofbiz-Base.js",
6 "dist/scripts/bundles/ofbiz-Party.js",
7 "dist/scripts/bundles/ofbiz-ContactMechs.js"
8 ],
9 "dependencies": {
10 "backbone": "~1.1.0",
11 "backbone-validation": "0.9.1",
12 "requirejs": "~2.1.10"
13 },
14 "devDependencies": {
15 "bower-requirejs": "~0.9.2",
16 "grunt": "~0.4.1",
17 "grunt-contrib-copy": "~0.4.1",
18 "grunt-contrib-concat": "~0.3.0",
19 "grunt-contrib-uglify": "~0.2.0",
20 "grunt-contrib-jshint": "~0.7.0",
21 "grunt-contrib-cssmin": "~0.7.0",
22 "grunt-contrib-connect": "~0.5.0",
23 "grunt-contrib-clean": "~0.5.0",
24 "grunt-contrib-htmlmin": "~0.1.3",
25 "grunt-bower-install": "~0.7.0",
26 "grunt-contrib-imagemin": "~0.2.0",
27 "grunt-contrib-watch": "~0.5.2",
28 "grunt-rev": "~0.1.0",
29 "grunt-autoprefixer": "~0.5.0",
30 "grunt-usemin": "~0.1.10",
31 "grunt-mocha": "~0.4.0",
32 "grunt-newer": "~0.6.0",
33 "grunt-svgmin": "~0.2.0",
34 "grunt-concurrent": "~0.4.0",
35 "load-grunt-tasks": "~0.2.0",
36 "time-grunt": "~0.2.0",
37 "jshint-stylish": "~0.1.3",
38 "grunt-contrib-requirejs": "~0.4.0",
39 "grunt-bower-requirejs": "~0.8.4",
40 "grunt-template-jasmine-istanbul": "~0.2.6",
41 "grunt-template-jasmine-requirejs": "~0.1.10",
42 "grunt-contrib-jasmine": "~0.5.3"
43 },
44 "engines": {
45 "node": ">=0.8.0"
46 }
47 }
48
1 <!doctype html>
2 <html class="no-js">
3 <head>
4 <meta charset="utf-8">
5 <title>ofbiz shared</title>
6 <meta name="description" content="">
7 <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
8
9 <!-- build:css({src, .tmp}) styles/main.css -->
10 <link rel="stylesheet" href="styles/main.css">
11 <!-- endbuild -->
12 </head>
13 <body>
14 <script src="scripts/config.js"></script>
15 <!-- build:js({src,.tmp}) scripts/require.js -->
16 <script src="scripts/bundles.js"></script>
17 <script src="lib/requirejs/require.js"></script>
18 <!-- endbuild -->
19 <script src="scripts/main.js"></script>
20 </body>
21 </html>
1 /* global require:true */
2 var require;
3 require = (function() {
4 'use strict';
5
6 var require = {
7 shim: {
8
9 },
10 paths: {
11 underscore: '../lib/underscore/underscore',
12 'backbone-validation': '../lib/backbone-validation/dist/backbone-validation-amd',
13 backbone: '../lib/backbone/backbone'
14 }
15 };
16
17 return require;
18 })();
1 define([], {});
1 /* global require */
2 require(
3 [
4 'backbone',
5 ],
6 function(
7 Backbone
8 ) {
9 'use strict';
10 Backbone.emulateHTTP = true;
11 Backbone.emulateJSON = true;
12 }
13 );
1 define(
2 [],
3 function() {
4 /* global console */
5 'use strict';
6 console.log('ofbiz/model/Base: loaded');
7 var Base = {
8 createRequiredChecker: function(label) {
9 return function() {
10 console.log(label + ':required');
11 return this._isRequired;
12 };
13 },
14 createRequiredValidator: function(label) {
15 return {
16 required: Base.createRequiredChecker(),
17 };
18 },
19 };
20 return Base;
21 }
22 );
1 /* global console */
2 define(
3 [
4 'backbone',
5 ],
6 function(
7 Backbone
8 ) {
9 'use strict';
10 console.log('ofbiz/model/ContactMech: loaded');
11 return Backbone.Model.extend({
12 defaults: {
13 contactMechId: null,
14 },
15 validation: {
16 contactMechId: null,
17 },
18 });
19 }
20 );
1 /* global console */
2 define(
3 [
4 'underscore',
5 'ofbiz/model/Base',
6 'ofbiz/model/ContactMech',
7 ],
8 function(
9 _,
10 Base,
11 ContactMech
12 ) {
13 'use strict';
14 console.log('ofbiz/model/EmailAddress: loaded');
15 return ContactMech.extend({
16 defaults: {
17 emailAddress: null,
18 },
19 validation: {
20 emailAddress: [
21 {
22 pattern: 'email',
23 required: Base.createRequiredChecker('ofbiz/model/EmailAddress.emailAddress'),
24 },
25 ]
26 },
27 parse: function(data) {
28 if (data.infoString !== undefined) {
29 data = _.clone(data);
30 if (data.emailAddress === undefined) {
31 data.emailAddress = data.infoString;
32 }
33 delete data.infoString;
34 }
35 return data;
36 },
37 });
38 }
39 );
1 /* global console */
2 define(
3 [
4 'backbone',
5 ],
6 function(
7 Backbone
8 ) {
9 'use strict';
10 console.log('ofbiz/model/Party: loaded');
11 return Backbone.Model.extend({
12 idAttribute: 'partyId',
13 defaults: {
14 partyId: null,
15 },
16 validation: {
17 partyId: null,
18 }
19 });
20 }
21 );
1 /* global console */
2 define(
3 [
4 'ofbiz/model/Base',
5 'ofbiz/model/Party',
6 ],
7 function(
8 Base,
9 Party
10 ) {
11 'use strict';
12 console.log('ofbiz/model/PartyGroup: loaded');
13 return Party.extend({
14 defaults: {
15 groupName: null,
16 },
17 validation: {
18 groupName: [
19 Base.createRequiredValidator('ofbiz/model/PartyGroup.groupName'),
20 ],
21 },
22 });
23 }
24 );
1 /* global console */
2 define(
3 [
4 'ofbiz/model/Base',
5 'ofbiz/model/Party',
6 ],
7 function(
8 Base,
9 Party
10 ) {
11 'use strict';
12 console.log('ofbiz/model/Person: loaded');
13 return Party.extend({
14 defaults: {
15 firstName: null,
16 lastName: null,
17 },
18 validation: {
19 firstName: [
20 Base.createRequiredValidator('ofbiz/model/Person.firstName'),
21 ],
22 lastName: [
23 Base.createRequiredValidator('ofbiz/model/Person.lastName'),
24 ],
25 },
26 });
27 }
28 );
1 /* global console */
2 define(
3 [
4 'ofbiz/model/Base',
5 'ofbiz/model/ContactMech',
6 ],
7 function(
8 Base,
9 ContactMech
10 ) {
11 'use strict';
12 console.log('ofbiz/model/PostalAddress: loaded');
13 return ContactMech.extend({
14 defaults: {
15 address1: null,
16 city: null,
17 postalCode: null,
18 },
19 validation: {
20 address1: [
21 Base.createRequiredValidator('ofbiz/model/PostalAddress.address1'),
22 ],
23 city: [
24 Base.createRequiredValidator('ofbiz/model/PostalAddress.city'),
25 ],
26 postalCode: [
27 Base.createRequiredValidator('ofbiz/model/PostalAddress.postalCode'),
28 ],
29 }
30 });
31 }
32 );
1 /* global console */
2 define(
3 [
4 'ofbiz/model/Base',
5 'ofbiz/model/ContactMech',
6 ],
7 function(
8 Base,
9 ContactMech
10 ) {
11 'use strict';
12 console.log('ofbiz/model/TelecomNumber: loaded');
13 return ContactMech.extend({
14 defaults: {
15 contactNumber: null,
16 },
17 validation: {
18 contactNumber: [
19 Base.createRequiredValidator('ofbiz/model/TelecomNumber.contactNumber'),
20 ]
21 }
22 });
23 }
24 );
File mode changed
1 define(function(require) {
2 'use strict';
3
4 var Base = require('ofbiz/model/Base');
5 var Backbone = require('backbone');
6
7 describe('Base', function() {
8 it('exists', function() {
9 expect(Base).toBeTruthy();
10 });
11 });
12 describe('Base', function() {
13 it('_createRequiredValidator', function() {
14 var TestModel = Backbone.Model.extend({
15 required: function() {
16 return this.validators.all[0].required.call(this, arguments);
17 },
18 validators: {
19 all: [
20 Base.createRequiredValidator('jasmine test'),
21 ],
22 },
23 });
24 var testModel = new TestModel();
25 expect(testModel.required()).toBe(undefined);
26 testModel._isRequired = false;
27 expect(testModel.required()).toBe(false);
28 testModel._isRequired = true;
29 expect(testModel.required()).toBe(true);
30 });
31 });
32 });
1 define(function(require) {
2 'use strict';
3
4 var EmailAddress= require('ofbiz/model/EmailAddress');
5 var _ = require('underscore');
6 var Backbone = require('backbone');
7 require('backbone-validation');
8
9 describe('EmailAddress', function() {
10 it('exists', function() {
11 expect(EmailAddress).toBeTruthy();
12 });
13 });
14 describe('EmailAddress', function() {
15 beforeEach(function() {
16 _.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
17 });
18 it('validation', function() {
19 var result, emailAddress;
20 emailAddress = new EmailAddress();
21 expect(emailAddress.validate()).toBeUndefined();
22 expect(emailAddress.isValid()).toBe(true);
23
24 emailAddress._isRequired = true;
25 // changing _isRequired doesn't have an effect until validate is called
26 expect(emailAddress.isValid()).toBe(true);
27 result = emailAddress.validate();
28 expect(result).not.toBeUndefined();
29 expect(emailAddress.isValid()).toBe(false);
30 expect(_.keys(result).sort()).toEqual(['emailAddress']);
31 expect(result['emailAddress']).toEqual(jasmine.any(String));
32
33 emailAddress.set('emailAddress', 'foo');
34 result = emailAddress.validate();
35 expect(result).not.toBeUndefined();
36 expect(emailAddress.isValid()).toBe(false);
37 expect(_.keys(result).sort()).toEqual(['emailAddress']);
38 expect(result['emailAddress']).toEqual(jasmine.any(String));
39
40 emailAddress.set('emailAddress', 'name@example.com');
41 result = emailAddress.validate();
42 expect(result).toBeUndefined();
43 expect(emailAddress.isValid()).toBe(true);
44
45
46 emailAddress.set('emailAddress', null);
47 result = emailAddress.validate();
48 expect(result).not.toBeUndefined();
49 expect(emailAddress.isValid()).toBe(false);
50 expect(_.keys(result).sort()).toEqual(['emailAddress']);
51 expect(result['emailAddress']).toEqual(jasmine.any(String));
52
53 emailAddress._isRequired = false;
54 expect(emailAddress.isValid()).toBe(false);
55 expect(emailAddress.validate()).toBeUndefined();
56 expect(emailAddress.isValid()).toBe(true);
57 });
58 it('parse', function() {
59 var result, emailAddress;
60 emailAddress = new EmailAddress({infoString: 'name@example.com'}, {parse: true});
61 expect(emailAddress.get('infoString')).toBeUndefined();
62 expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
63
64 emailAddress = new EmailAddress({emailAddress: 'name@example.com'}, {parse: true});
65 expect(emailAddress.get('infoString')).toBeUndefined();
66 expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
67
68 emailAddress = new EmailAddress({infoString: 'foo', emailAddress: 'name@example.com'}, {parse: true});
69 expect(emailAddress.get('infoString')).toBeUndefined();
70 expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
71 });
72 });
73 });
1 define(function(require) {
2 'use strict';
3
4 var PostalAddress= require('ofbiz/model/PostalAddress');
5 var _ = require('underscore');
6 var Backbone = require('backbone');
7 require('backbone-validation');
8
9 describe('PostalAddress', function() {
10 it('exists', function() {
11 expect(PostalAddress).toBeTruthy();
12 });
13 });
14 if (true) describe('PostalAddress', function() {
15 beforeEach(function() {
16 _.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
17 });
18 it('validation', function() {
19 var result, postalAddress;
20 postalAddress = new PostalAddress();
21 expect(postalAddress.validate()).toBeUndefined();
22 expect(postalAddress.isValid()).toBe(true);
23
24 postalAddress._isRequired = true;
25 // changing _isRequired doesn't have an effect until validate is called
26 expect(postalAddress.isValid()).toBe(true);
27 result = postalAddress.validate()
28 expect(result).not.toBeUndefined();
29 expect(postalAddress.isValid()).toBe(false);
30 expect(_.keys(result).sort()).toEqual(['address1', 'city', 'postalCode']);
31 expect(result['address1']).toEqual(jasmine.any(String));
32 expect(result['city']).toEqual(jasmine.any(String));
33 expect(result['postalCode']).toEqual(jasmine.any(String));
34
35 postalAddress.set('city', 'Anytown');
36 result = postalAddress.validate()
37 expect(result).not.toBeUndefined();
38 expect(postalAddress.isValid()).toBe(false);
39 expect(_.keys(result).sort()).toEqual(['address1', 'postalCode']);
40 expect(result['address1']).toEqual(jasmine.any(String));
41 expect(result['postalCode']).toEqual(jasmine.any(String));
42
43
44 postalAddress._isRequired = false;
45 expect(postalAddress.isValid()).toBe(false);
46 expect(postalAddress.validate()).toBeUndefined();
47 expect(postalAddress.isValid()).toBe(true);
48 });
49 });
50 });
1 define(function(require) {
2 'use strict';
3
4 var TelecomNumber = require('ofbiz/model/TelecomNumber');
5 var _ = require('underscore');
6 var Backbone = require('backbone');
7 require('backbone-validation');
8
9 describe('TelecomNumber', function() {
10 it('exists', function() {
11 expect(TelecomNumber).toBeTruthy();
12 });
13 });
14 if (true) describe('TelecomNumber', function() {
15 beforeEach(function() {
16 _.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
17 });
18 it('validation', function() {
19 var result, telecomNumber;
20 telecomNumber = new TelecomNumber();
21 expect(telecomNumber.validate()).toBeUndefined();
22 expect(telecomNumber.isValid()).toBe(true);
23
24 telecomNumber._isRequired = true;
25 // changing _isRequired doesn't have an effect until validate is called
26 expect(telecomNumber.isValid()).toBe(true);
27 result = telecomNumber.validate()
28 expect(result).not.toBeUndefined();
29 expect(telecomNumber.isValid()).toBe(false);
30 expect(_.keys(result).sort()).toEqual(['contactNumber']);
31 expect(result['contactNumber']).toEqual(jasmine.any(String));
32
33 telecomNumber.set('contactNumber', '123-456-7890');
34 result = telecomNumber.validate()
35 expect(result).toBeUndefined();
36 expect(telecomNumber.isValid()).toBe(true);
37
38 telecomNumber._isRequired = false;
39 expect(telecomNumber.isValid()).toBe(true);
40 expect(telecomNumber.validate()).toBeUndefined();
41 expect(telecomNumber.isValid()).toBe(true);
42 });
43 });
44 });