fdebc3d1 by Adam Heath

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

1 parent 31f6715f
{
"directory": "src/lib"
}
.*.swp
.tmp/
bin/coverage/
dist/
node_modules/
src/lib/
......
This diff is collapsed. Click to expand it.
{
"name": "ofbiz-shared",
"version": "0.0.0",
"authors": [
"Adam Heath <doogie@brainfood.com>"
],
"private": true,
"ignore": [
"**/.*",
"node_modules",
"src/lib",
"test"
],
"dependencies": {
"backbone": "~1.1.0",
"backbone-validation": "0.9.1",
"requirejs": "~2.1.10"
}
}
{
"name": "ofbiz-shared",
"version": "0.0.0",
"_main": [
"dist/scripts/bundles/ofbiz-Base.js",
"dist/scripts/bundles/ofbiz-Party.js",
"dist/scripts/bundles/ofbiz-ContactMechs.js"
],
"dependencies": {
"backbone": "~1.1.0",
"backbone-validation": "0.9.1",
"requirejs": "~2.1.10"
},
"devDependencies": {
"bower-requirejs": "~0.9.2",
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-jshint": "~0.7.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-bower-install": "~0.7.0",
"grunt-contrib-imagemin": "~0.2.0",
"grunt-contrib-watch": "~0.5.2",
"grunt-rev": "~0.1.0",
"grunt-autoprefixer": "~0.5.0",
"grunt-usemin": "~0.1.10",
"grunt-mocha": "~0.4.0",
"grunt-newer": "~0.6.0",
"grunt-svgmin": "~0.2.0",
"grunt-concurrent": "~0.4.0",
"load-grunt-tasks": "~0.2.0",
"time-grunt": "~0.2.0",
"jshint-stylish": "~0.1.3",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-bower-requirejs": "~0.8.4",
"grunt-template-jasmine-istanbul": "~0.2.6",
"grunt-template-jasmine-requirejs": "~0.1.10",
"grunt-contrib-jasmine": "~0.5.3"
},
"engines": {
"node": ">=0.8.0"
}
}
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title>ofbiz shared</title>
<meta name="description" content="">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css({src, .tmp}) styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
</head>
<body>
<script src="scripts/config.js"></script>
<!-- build:js({src,.tmp}) scripts/require.js -->
<script src="scripts/bundles.js"></script>
<script src="lib/requirejs/require.js"></script>
<!-- endbuild -->
<script src="scripts/main.js"></script>
</body>
</html>
/* global require:true */
var require;
require = (function() {
'use strict';
var require = {
shim: {
},
paths: {
underscore: '../lib/underscore/underscore',
'backbone-validation': '../lib/backbone-validation/dist/backbone-validation-amd',
backbone: '../lib/backbone/backbone'
}
};
return require;
})();
define([], {});
/* global require */
require(
[
'backbone',
],
function(
Backbone
) {
'use strict';
Backbone.emulateHTTP = true;
Backbone.emulateJSON = true;
}
);
define(
[],
function() {
/* global console */
'use strict';
console.log('ofbiz/model/Base: loaded');
var Base = {
createRequiredChecker: function(label) {
return function() {
console.log(label + ':required');
return this._isRequired;
};
},
createRequiredValidator: function(label) {
return {
required: Base.createRequiredChecker(),
};
},
};
return Base;
}
);
/* global console */
define(
[
'backbone',
],
function(
Backbone
) {
'use strict';
console.log('ofbiz/model/ContactMech: loaded');
return Backbone.Model.extend({
defaults: {
contactMechId: null,
},
validation: {
contactMechId: null,
},
});
}
);
/* global console */
define(
[
'underscore',
'ofbiz/model/Base',
'ofbiz/model/ContactMech',
],
function(
_,
Base,
ContactMech
) {
'use strict';
console.log('ofbiz/model/EmailAddress: loaded');
return ContactMech.extend({
defaults: {
emailAddress: null,
},
validation: {
emailAddress: [
{
pattern: 'email',
required: Base.createRequiredChecker('ofbiz/model/EmailAddress.emailAddress'),
},
]
},
parse: function(data) {
if (data.infoString !== undefined) {
data = _.clone(data);
if (data.emailAddress === undefined) {
data.emailAddress = data.infoString;
}
delete data.infoString;
}
return data;
},
});
}
);
/* global console */
define(
[
'backbone',
],
function(
Backbone
) {
'use strict';
console.log('ofbiz/model/Party: loaded');
return Backbone.Model.extend({
idAttribute: 'partyId',
defaults: {
partyId: null,
},
validation: {
partyId: null,
}
});
}
);
/* global console */
define(
[
'ofbiz/model/Base',
'ofbiz/model/Party',
],
function(
Base,
Party
) {
'use strict';
console.log('ofbiz/model/PartyGroup: loaded');
return Party.extend({
defaults: {
groupName: null,
},
validation: {
groupName: [
Base.createRequiredValidator('ofbiz/model/PartyGroup.groupName'),
],
},
});
}
);
/* global console */
define(
[
'ofbiz/model/Base',
'ofbiz/model/Party',
],
function(
Base,
Party
) {
'use strict';
console.log('ofbiz/model/Person: loaded');
return Party.extend({
defaults: {
firstName: null,
lastName: null,
},
validation: {
firstName: [
Base.createRequiredValidator('ofbiz/model/Person.firstName'),
],
lastName: [
Base.createRequiredValidator('ofbiz/model/Person.lastName'),
],
},
});
}
);
/* global console */
define(
[
'ofbiz/model/Base',
'ofbiz/model/ContactMech',
],
function(
Base,
ContactMech
) {
'use strict';
console.log('ofbiz/model/PostalAddress: loaded');
return ContactMech.extend({
defaults: {
address1: null,
city: null,
postalCode: null,
},
validation: {
address1: [
Base.createRequiredValidator('ofbiz/model/PostalAddress.address1'),
],
city: [
Base.createRequiredValidator('ofbiz/model/PostalAddress.city'),
],
postalCode: [
Base.createRequiredValidator('ofbiz/model/PostalAddress.postalCode'),
],
}
});
}
);
/* global console */
define(
[
'ofbiz/model/Base',
'ofbiz/model/ContactMech',
],
function(
Base,
ContactMech
) {
'use strict';
console.log('ofbiz/model/TelecomNumber: loaded');
return ContactMech.extend({
defaults: {
contactNumber: null,
},
validation: {
contactNumber: [
Base.createRequiredValidator('ofbiz/model/TelecomNumber.contactNumber'),
]
}
});
}
);
File mode changed
define(function(require) {
'use strict';
var Base = require('ofbiz/model/Base');
var Backbone = require('backbone');
describe('Base', function() {
it('exists', function() {
expect(Base).toBeTruthy();
});
});
describe('Base', function() {
it('_createRequiredValidator', function() {
var TestModel = Backbone.Model.extend({
required: function() {
return this.validators.all[0].required.call(this, arguments);
},
validators: {
all: [
Base.createRequiredValidator('jasmine test'),
],
},
});
var testModel = new TestModel();
expect(testModel.required()).toBe(undefined);
testModel._isRequired = false;
expect(testModel.required()).toBe(false);
testModel._isRequired = true;
expect(testModel.required()).toBe(true);
});
});
});
define(function(require) {
'use strict';
var EmailAddress= require('ofbiz/model/EmailAddress');
var _ = require('underscore');
var Backbone = require('backbone');
require('backbone-validation');
describe('EmailAddress', function() {
it('exists', function() {
expect(EmailAddress).toBeTruthy();
});
});
describe('EmailAddress', function() {
beforeEach(function() {
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
});
it('validation', function() {
var result, emailAddress;
emailAddress = new EmailAddress();
expect(emailAddress.validate()).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
emailAddress._isRequired = true;
// changing _isRequired doesn't have an effect until validate is called
expect(emailAddress.isValid()).toBe(true);
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress.set('emailAddress', 'foo');
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress.set('emailAddress', 'name@example.com');
result = emailAddress.validate();
expect(result).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
emailAddress.set('emailAddress', null);
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress._isRequired = false;
expect(emailAddress.isValid()).toBe(false);
expect(emailAddress.validate()).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
});
it('parse', function() {
var result, emailAddress;
emailAddress = new EmailAddress({infoString: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
emailAddress = new EmailAddress({emailAddress: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
emailAddress = new EmailAddress({infoString: 'foo', emailAddress: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
});
});
});
define(function(require) {
'use strict';
var PostalAddress= require('ofbiz/model/PostalAddress');
var _ = require('underscore');
var Backbone = require('backbone');
require('backbone-validation');
describe('PostalAddress', function() {
it('exists', function() {
expect(PostalAddress).toBeTruthy();
});
});
if (true) describe('PostalAddress', function() {
beforeEach(function() {
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
});
it('validation', function() {
var result, postalAddress;
postalAddress = new PostalAddress();
expect(postalAddress.validate()).toBeUndefined();
expect(postalAddress.isValid()).toBe(true);
postalAddress._isRequired = true;
// changing _isRequired doesn't have an effect until validate is called
expect(postalAddress.isValid()).toBe(true);
result = postalAddress.validate()
expect(result).not.toBeUndefined();
expect(postalAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['address1', 'city', 'postalCode']);
expect(result['address1']).toEqual(jasmine.any(String));
expect(result['city']).toEqual(jasmine.any(String));
expect(result['postalCode']).toEqual(jasmine.any(String));
postalAddress.set('city', 'Anytown');
result = postalAddress.validate()
expect(result).not.toBeUndefined();
expect(postalAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['address1', 'postalCode']);
expect(result['address1']).toEqual(jasmine.any(String));
expect(result['postalCode']).toEqual(jasmine.any(String));
postalAddress._isRequired = false;
expect(postalAddress.isValid()).toBe(false);
expect(postalAddress.validate()).toBeUndefined();
expect(postalAddress.isValid()).toBe(true);
});
});
});
define(function(require) {
'use strict';
var TelecomNumber = require('ofbiz/model/TelecomNumber');
var _ = require('underscore');
var Backbone = require('backbone');
require('backbone-validation');
describe('TelecomNumber', function() {
it('exists', function() {
expect(TelecomNumber).toBeTruthy();
});
});
if (true) describe('TelecomNumber', function() {
beforeEach(function() {
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
});
it('validation', function() {
var result, telecomNumber;
telecomNumber = new TelecomNumber();
expect(telecomNumber.validate()).toBeUndefined();
expect(telecomNumber.isValid()).toBe(true);
telecomNumber._isRequired = true;
// changing _isRequired doesn't have an effect until validate is called
expect(telecomNumber.isValid()).toBe(true);
result = telecomNumber.validate()
expect(result).not.toBeUndefined();
expect(telecomNumber.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['contactNumber']);
expect(result['contactNumber']).toEqual(jasmine.any(String));
telecomNumber.set('contactNumber', '123-456-7890');
result = telecomNumber.validate()
expect(result).toBeUndefined();
expect(telecomNumber.isValid()).toBe(true);
telecomNumber._isRequired = false;
expect(telecomNumber.isValid()).toBe(true);
expect(telecomNumber.validate()).toBeUndefined();
expect(telecomNumber.isValid()).toBe(true);
});
});
});