Add field application

Add asset dependencies

Add field model

Add field tests

Add field app

Add JS build

Add end file blank line

Adjust asset dependencies version

Remove assets test libraries from build

Remove unecessary comments

Add end file blank line

Fix indent
This commit is contained in:
Nicolas Le Goff
2013-05-03 11:15:11 +02:00
committed by Romain Neutron
parent d0431248ce
commit 1ff4e4060b
19 changed files with 340 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ before_script:
- rm -f config/services.yml config/connexions.yml config/config.yml config/config.inc config/connexion.inc config/_GV.php config/_GV.php.old - rm -f config/services.yml config/connexions.yml config/config.yml config/config.inc config/connexion.inc config/_GV.php config/_GV.php.old
- cp -f hudson/connexion.inc config/ - cp -f hudson/connexion.inc config/
- cp -f hudson/_GV.php config/ - cp -f hudson/_GV.php config/
- npm install bower mocha-phantomjs -g
- bower install
- composer self-update - composer self-update
- composer install --dev --prefer-source - composer install --dev --prefer-source
- sudo apt-get update - sudo apt-get update
@@ -55,3 +57,7 @@ php:
matrix: matrix:
allow_failures: allow_failures:
- php: 5.5 - php: 5.5
script:
- mocha-phantomjs www/scripts/tests/index.html
- phpunit

View File

@@ -75,6 +75,8 @@ $finder
->name('.svn') ->name('.svn')
->name('.git') ->name('.git')
->name('flash') ->name('flash')
->name('chai')
->name('mocha')
->ignoreDotFiles(false) ->ignoreDotFiles(false)
->ignoreVCS(false) ->ignoreVCS(false)
->in(__DIR__); ->in(__DIR__);

View File

@@ -2,5 +2,10 @@
"name": "Phraseanet", "name": "Phraseanet",
"version": "3.8.0", "version": "3.8.0",
"dependencies": { "dependencies": {
"requirejs" : "~2.1",
"backbone-amd": "~1.0",
"underscore-amd": "~1.4",
"mocha": "~1.9",
"chai" : "~1.6"
} }
} }

View File

@@ -16,6 +16,7 @@
"gedmo/doctrine-extensions" : "~2.3.0", "gedmo/doctrine-extensions" : "~2.3.0",
"imagine/imagine" : "dev-ColorSpaces@dev", "imagine/imagine" : "dev-ColorSpaces@dev",
"jms/serializer" : "~0.10", "jms/serializer" : "~0.10",
"jms/twig-js" : "dev-master",
"mediavorus/mediavorus" : "~0.3", "mediavorus/mediavorus" : "~0.3",
"media-alchemyst/media-alchemyst" : "~0.2, >=0.2.3", "media-alchemyst/media-alchemyst" : "~0.2, >=0.2.3",
"monolog/monolog" : "~1.3.0", "monolog/monolog" : "~1.3.0",

47
composer.lock generated
View File

@@ -939,6 +939,53 @@
], ],
"time": "2013-03-28 16:41:24" "time": "2013-03-28 16:41:24"
}, },
{
"name": "jms/twig-js",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/twig.js.git",
"reference": "159542ed93a61801c1502497a65efbfd97628090"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/schmittjoh/twig.js/zipball/159542ed93a61801c1502497a65efbfd97628090",
"reference": "159542ed93a61801c1502497a65efbfd97628090",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"twig/twig": ">=1.8,<2.0-dev"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-0": {
"TwigJs": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache2"
],
"authors": [
{
"name": "Johannes M. Schmitt",
"email": "schmittjoh@gmail.com",
"homepage": "https://github.com/schmittjoh",
"role": "Developer of wrapped JMSSerializerBundle"
}
],
"description": "twig.js, flexible, secure, and high-performance templating engine for Javascript",
"keywords": [
"templating"
],
"time": "2013-03-26 10:59:54"
},
{ {
"name": "media-alchemyst/media-alchemyst", "name": "media-alchemyst/media-alchemyst",
"version": "0.2.5", "version": "0.2.5",

View File

@@ -0,0 +1,24 @@
{% twig_js name="fieldsEdit" %}
<div>
{{ field.name }}
</div>
<div>
{{ field.tag }}
</div>
<form>
<input type="checkbox" {{ field.multi ? "checked='checked'" : "" }} /> multivalué <br />
branche thesaurus <input type="text" value="{{ field.tbranch }}"/><br />
type de vocabulaire <select><option>utilisateur</option></select><br />
type <select><option>{{ field.type }}</option></select><br />
champ métier <input type="checkbox" {{ field.business ? "checked='checked'" : "" }} /><br />
vocabulaire restreint <input type="checkbox" {{ field["vocavulary-restricted"] ? "checked='checked'" : "" }} /><br />
séparateur <input type="text" value="{{ field.separator }}" /> <br />
obligatoire <input type="checkbox" {{ field.required ? "checked='checked'" : "" }} /><br />
indexable <input type="checkbox" {{ field.indexable ? "checked='checked'" : "" }} /><br />
lecture seule <input type="checkbox" {{ field.readonly ? "checked='checked'" : "" }} /><br />
report <input type="checkbox" {{ field.report ? "checked='checked'" : "" }} /><br />
</form>

View File

@@ -0,0 +1,6 @@
{% twig_js name="fieldsRow" %}
<li>
<a href="#field/{{ id }}" >{{ name }}</a>
<br />
{{ tag }}
</li>

View File

@@ -0,0 +1,14 @@
define([
'jquery',
'underscore',
'backbone',
'apps/admin/fields/router'
], function($, _, Backbone, Router) {
var initialize = function() {
Router.initialize();
};
return {
initialize: initialize
};
});

View File

@@ -0,0 +1,12 @@
define([
'underscore',
'backbone',
'models/admin/field'
], function(_, Backbone, FieldModel) {
var FieldCollection = Backbone.Collection.extend({
model: FieldModel,
url: '/admin/fields/1/fields'
});
return FieldCollection;
});

View File

@@ -0,0 +1,19 @@
require.config({
baseUrl: "/scripts",
paths: {
jquery: '../assets/jquery/jquery',
underscore: '../assets/underscore-amd/underscore',
backbone: '../assets/backbone-amd/backbone',
twig: '../assets/twig/twig',
i18n: '../assets/i18n/i18next.amd'
},
shim: {
twig: {
exports: 'Twig'
}
}
});
require(['apps/admin/fields/app'], function(App) {
App.initialize();
});

View File

@@ -0,0 +1,59 @@
define([
'jquery',
'underscore',
'backbone',
'models/admin/field',
'apps/admin/fields/views/edit',
'apps/admin/fields/views/list',
'apps/admin/fields/collections/fields'
], function($, _, Backbone, FieldModel, FieldEditView, FieldListView, FieldsCollection) {
var AppRouter = Backbone.Router.extend({
routes: {
'field/:id': "getField",
'fields': 'showFields',
'*actions': 'defaultAction'
}
});
var initialize = function() {
var app_router = new AppRouter();
app_router.on('route:getField', function (id) {
var field = new FieldModel({id: id});
field.fetch().done(function() {
var fieldEditView = new FieldEditView({
el: $('.right-block')[0],
model: field
});
fieldEditView.render();
});
});
app_router.on('route:showFields', function() {
var fieldsCollection = new FieldsCollection();
fieldsCollection.fetch().done(function() {
var fieldListView = new FieldListView({
collection: fieldsCollection,
el: $('ul#collection-fields')[0]
});
fieldListView.render();
});
});
app_router.on('route:defaultAction', function(actions) {
console.log('No route:', actions);
});
Backbone.history.start();
// Show fields on start up
app_router.navigate('fields', { trigger: true });
};
return {
initialize: initialize
};
});

View File

@@ -0,0 +1,21 @@
define([
'jquery',
'underscore',
'backbone',
'i18n'
], function($, _, Backbone, i18n) {
var FieldEditView = Backbone.View.extend({
tagName: "div",
className: "field-edit",
render: function() {
this.el.innerHTML = '';
this.el.innerHTML = Twig.render(fieldsEdit, {
field: this.model.attributes
});
return this;
}
});
return FieldEditView;
});

View File

@@ -0,0 +1,32 @@
define([
'jquery',
'underscore',
'backbone',
'apps/admin/fields/views/listRow'
], function($, _, Backbone, FieldListRowView) {
var FieldListView = Backbone.View.extend({
initialize: function() {
var that = this;
this._fieldViews = [];
this.collection.each(function(field) {
that._fieldViews.push(new FieldListRowView({
model: field
}));
});
},
render: function() {
var that = this;
$(this.el).empty();
// Render each sub-view and append it to the parent view's element.
_(this._fieldViews).each(function(singleView) {
$(that.el).append(singleView.render().el);
});
return this;
}
});
return FieldListView;
});

View File

@@ -0,0 +1,21 @@
define([
'jquery',
'underscore',
'backbone'
], function($, _, Backbone) {
var FieldListRowView = Backbone.View.extend({
tagName: "li",
className: "field-row",
render: function() {
this.el.innerHTML = Twig.render(fieldsRow, {
id: this.model.get('id'),
name: this.model.get('name'),
tag: this.model.get('tag')
});
return this;
}
});
return FieldListRowView;
});

View File

@@ -0,0 +1,11 @@
define([
'underscore',
'backbone'
], function(_, Backbone) {
var FieldModel = Backbone.Model.extend({
urlRoot: '/admin/fields/1/fields'
});
// Return the model for the module
return FieldModel;
});

View File

@@ -0,0 +1,4 @@
define(['chai'], function(shai) {
window.expect = shai.expect;
window.assert = shai.assert;
});

View File

@@ -0,0 +1,22 @@
<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Mocha Spec Runner</title>
<link rel="stylesheet" href="../../assets/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="../../assets/mocha/mocha.js"></script>
<script src="../../assets/chai/chai.js"></script>
<script>
window.expect = chai.expect;
window.assert = chai.assert;
</script>
<script src="../../assets/requirejs/require.js"></script>
<script src="../../scripts/tests/main.js"></script>
<script>
require(['tests/baseTest', 'specs/admin/fields'], runMocha);
</script>
</body>
</html>

29
www/scripts/tests/main.js Normal file
View File

@@ -0,0 +1,29 @@
require.config({
baseUrl: "../../scripts",
paths: {
specs: 'tests/specs',
chai: '../assets/chai/chai'
},
shim : {
shai: {
exports: "chai"
}
}
});
mocha.setup({
ui: 'bdd',
ignoreLeaks: true
});
console = window.console || function() {};
window.notrack = true;
var runMocha = function() {
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
mocha.run();
}
};

View File

@@ -0,0 +1,5 @@
define(function(require) {
it('should run', function () {
expect(true).to.equal(false);
});
});