Skip to content

Commit

Permalink
v 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanaelle committed Dec 19, 2014
1 parent b804bfd commit ed3591b
Show file tree
Hide file tree
Showing 60 changed files with 22,039 additions and 2,499 deletions.
25 changes: 18 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ module.exports = function(grunt) {
banner: '/*! JStion — <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
'build/JStion-<%= pkg.version %>.js' :[ '_src/core/*.js' ],
'build/JStion.Plans-<%= pkg.version %>.js' :[ '_src/plan/*.js' ],
'build/JStion.Exts-<%= pkg.version %>.js' :[ '_src/ext/*.js' ],
'build/JStion.UI-backbone-<%= pkg.version %>.js':[ '_src/backbone/*.js' ]
},

uglify: {
'build/JStion.min.js': 'build/JStion-<%= pkg.version %>.js',
'build/JStion.UI-backbone.min.js': 'build/JStion.UI-backbone-<%= pkg.version %>.js'
'build/JStion.min.js' : 'build/JStion-<%= pkg.version %>.js',
'build/JStion.Plans.min.js' : 'build/JStion.Plans-<%= pkg.version %>.js',
'build/JStion.Exts.min.js' :'build/JStion.Exts-<%= pkg.version %>.js',
'build/JStion.UI-backbone.min.js' : 'build/JStion.UI-backbone-<%= pkg.version %>.js'
},

jshint: {
files:[ 'build/JStion-<%= pkg.version %>.js', 'build/JStion.UI-backbone-<%= pkg.version %>.js' ]
files:[
'build/JStion-<%= pkg.version %>.js',
'build/JStion.Plans-<%= pkg.version %>.js',
'build/JStion.Exts-<%= pkg.version %>.js',
'build/JStion.UI-backbone-<%= pkg.version %>.js'
]
},

karma: {
Expand All @@ -31,13 +40,15 @@ module.exports = function(grunt) {
autoWatch: false,
captureTimeout: 60000
},
JStion:{
JStion_behaviours:{
src: [],
files: [ '_dep/rollups/hmac-sha1.js', 'build/JStion.min.js', '_t/core/*.js' ],
files: [ '_dep/rollups/hmac-sha1.js', '_t/bind.js', 'build/JStion-<%= pkg.version %>.js', 'build/JStion.Plans-<%= pkg.version %>.js', 'build/JStion.Exts-<%= pkg.version %>.js', '_t/behaviours/*.js' ],
},
JStion_internals:{
src: [],
files: [ '_dep/rollups/hmac-sha1.js', '_t/bind.js', 'build/JStion-<%= pkg.version %>.js', 'build/JStion.Plans-<%= pkg.version %>.js', '_t/internals/*.js' ],
}

}

});

grunt.loadNpmTasks('grunt-contrib-uglify');
Expand Down
1 change: 1 addition & 0 deletions _src/backbone/20-model-entite.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$fi.fn.m.Entite=
Backbone.Model.extend({
history:function( ){ return this.get('entite').history(); },
checkout:function(i ){ return this.get('entite').checkout(i); },
back: function(i ){ return this.get('entite').back(i); },
current:function( ){ return this.get('entite').back(0); },
nom: function( ){ return this.get('entite').nom; },
Expand Down
14 changes: 12 additions & 2 deletions _src/backbone/40-view-balance.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
$fi.fn.v.is_empty=function(v){
//console.log([v, Number(v)]);
return (Number(v) === 0);
};

$fi.fn.v.b2=
_.template('<tr><th><%=account%><td><%=debit%><td><%=credit%><td><%=solde_debit%><td><%=solde_credit%></tr><% _.each( subaccounts, function(c){%><%= window.$fi.v.b2(c) %><% }); %>');
_.template('<% if(_.filter(data, window.$fi.fn.v.is_empty).length != data.length ) { %>'+
'<tr><th><%=account%>' +
'<% _.each( data, function(f){%><td><%= (window.$fi.fn.v.is_empty(f))?"":f %></td><% }) %>'+
'<% _.each( solde, function(f){%><td><%= (window.$fi.fn.v.is_empty(f))?"":f %></td><% }) %>'+
'</tr>'+'<% } %>'+
'<% _.each( subaccounts, function(c){%><%= window.$fi.v.b2(c) %><% }); %>');

$fi.fn.v.Balance=
Backbone.View.extend({
el:'<table>',
template:_.template('<caption><%=nom%> — <%=message%></caption>'+
template:_.template('<caption><%=nom%> — <%=meta.message%></caption>'+
'<tr><th>compte<th>debit<th>credit<th>Solde débiteur<th>Solde créditeur</tr><% _.each( livre.accounts, function(c){ %><%= window.$fi.v.b2(c) %><% }); %>'),

render:function(ev){ $(this.el).html(this.template(this.model.toVSON())); return this; },
Expand Down
4 changes: 2 additions & 2 deletions _src/backbone/40-view-ecriture.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$fi.fn.v.Ecriture=
Backbone.View.extend({
el:'<table>',
template:_.template('<caption><%= message %></caption>'+
template:_.template('<caption><%= meta.message %></caption>'+
'<tr><th>compte</th><th>debit</th><th>credit</th></tr>'+
'<% _.each( mouvement, function(l){ %><tr><th><%= l[0] %></th><td><%= l[1]?l[1].toFixed(window.$fi.fix):"" %></td><td><%= l[2]?l[2].toFixed(window.$fi.fix):"" %></td></tr> <% }) %></table>' ),
'<% _.each( mouvement, function(l){ %><tr><th><%= l[0] %></th><td><%= (window.$fi.fn.v.is_empty(f))?"":f %></td><td><%= (window.$fi.fn.v.is_empty(f))?"":f %></td></tr> <% }) %></table>' ),

render:function(ev){ $(this.el).html(this.template(this.model.toVSON())); return this; },
});
4 changes: 3 additions & 1 deletion _src/backbone/40-view-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ $fi.fn.v.Fragment=
el:'<table>',
template:_.template(
'<tr><th>compte</th><th>debit</th><th>credit</th></tr>'+
'<% _.each( d, function(l){ %><tr><th><%= l[0] %></th><td><%= l[1] %></td><td><%= l[2] %></td></tr> <% }) %></table>' ),
'<% _.each( d, function(l){ %><tr><th><%= l[0] %></th>'+
'<% _.each( l[1], function(f){%><td><%= (window.$fi.fn.v.is_empty(f))?"":f %></td><% }) %>'+
'</tr> <% }) %></table>' ),

render:function(ev){ $(this.el).html(this.template({d:this.model.toVSON()})); return this; },
});
12 changes: 7 additions & 5 deletions _src/backbone/40-view-journal.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
$fi.fn.v.Journal=
Backbone.View.extend({
el:'<dl>',
template:_.template('<dt><%=message%><% if(mouvement.length){%><dd><table><tr><th>compte<th>debit<th>crédit</tr>'+
'<% _.each( mouvement, function(l){ %><tr><th><%= l[0] %></th><td><%= l[1]?l[1].toFixed(window.$fi.fix):"" %></td><td><%= l[2]?l[2].toFixed(window.$fi.fix):"" %></td></tr> <% }) %>'+
template:_.template('<dt><%= meta.date %> : <%= meta.message %><% if(mouvement.length){%><dd><table><tr><th>compte<th>debit<th>crédit</tr>'+
'<% _.each( mouvement, function(l){ %><tr><th><%= l[0] %></th>'+
'<% _.each( l[1], function(f){%><td><%= (window.$fi.fn.v.is_empty(f))?"":f %></td><% }) %>'+
'</tr> <% }) %>'+
'</table><% } %>'),

render:function(ev){
var view = this;
var model = this.model;
var livre = model.current();
var el = $(this.el);
_.each(model.history(),function(log){
_.each(model.history().slice().reverse(),function(log){
if(log.parents === undefined ) return;
var livre = model.checkout(log.id);
el.append(view.template( livre.diff( livre.back(1) ).toVSON() ));
livre = livre.back(1);
});
return this;
},
Expand Down
9 changes: 5 additions & 4 deletions _src/core/00-header.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
(function(window,undefined){

"use strict";

/**
* [instanciable description]
* @type {Object}
*/
var instanciable={};

var pcg={};

/**
* Handler for several kind of Storage
* @type {Object}
*/
var StorageEngine={
fake:(function(){
var f=function(){
var F=function(){
this.store={};
};
f.prototype={
F.prototype={
setItem: function(k,v){
this.store[k]=v;
},
Expand All @@ -31,7 +32,7 @@ var StorageEngine={
this.store={};
},
};
return new f();
return new F();
})(),
local:window.localStorage,
session:window.sessionStorage,
Expand Down
26 changes: 26 additions & 0 deletions _src/core/00-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function to_array(arg){
return [].slice.call( arg || [] );
}

function copy_array(arr){
return arr.slice();
}

function idem(e){
return e;
}

function filter_and_dispatch( filter, exact ) {
return function (set){
return set.filter( filter ).reduce(function(resp,e){
if(exact(e)) return {
exact: resp.exact.concat([e]),
sub: resp.sub
};
return {
exact: resp.exact,
sub: resp.sub.concat([e])
};
}, { exact:[], sub:[] } );
};
}
9 changes: 0 additions & 9 deletions _src/core/05-PGC.js

This file was deleted.

11 changes: 6 additions & 5 deletions _src/core/05-create_class.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* create a class
*
*
* @param {function|object} constructor function or default value
* @param {object} prototype
*
*
* @return {function} constructor
*/
var create_class=function(constructor,prototype,inheritance){
if(typeof constructor !== 'function')console.error('wrong parameter');
if(typeof constructor !== 'function') console.error('wrong parameter');

var f=function(){
constructor.apply(this,arguments);
Expand All @@ -16,8 +16,9 @@ var create_class=function(constructor,prototype,inheritance){

f.prototype = Object.create( inheritance===undefined ? Object.prototype: inheritance.prototype);

for (var k in prototype) f.prototype[k] = prototype[k];
if(prototype instanceof Function) prototype=prototype(f);

for(var k in prototype) f.prototype[k] = prototype[k];

return f;
};

15 changes: 13 additions & 2 deletions _src/core/05-create_monad.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
var create_monad=function(modifier){
var prototype = Object.create(null);
prototype.is_monad=true;

var unit = function (value){
var monad = Object.create(prototype);
monad.bind = function(func,args){
return func.apply( undefined, [value].concat(Array.prototype.slice.apply(args || [])) );
return func.apply( undefined, [ value ].concat(Array.prototype.slice.apply(args || [])) );
};
if(typeof modifier === 'function'){
value=modifier(monad,value);
}
return monad;
};

unit.method = function (name, func) {
prototype[name] = func;
return unit;
Expand All @@ -27,7 +29,7 @@ var create_monad=function(modifier){
return this.bind(func, arguments);
};
return unit;
};
};
unit.lift = function (name, func) {
prototype[name] = function () {
var result = this.bind(func, arguments);
Expand All @@ -37,3 +39,12 @@ var create_monad=function(modifier){
};
return unit;
};


var maybe_empty = function(empty_bind){
return create_monad(function(M,v){
if(v.length >0 ) return v;
M.bind = empty_bind;
return [];
});
};
120 changes: 57 additions & 63 deletions _src/core/10-ALO.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,67 @@
/**
* Accounting Large Object
*
*/
var ALO=create_class(
function(){
/**
* Accounting Large Object
*
*/
var ALO=create_class(
function(){

},
{
/**
* Load On Demand data
*
* @param {string} o [description]
* @param {string} k [description]
*
* @return {object} [description]
*/
lod:function(k){
// load on demand
var id = this.hasOwnProperty(k)? this[k] : k;
},
{
/**
* Load On Demand data
*
* @param {string} o [description]
* @param {string} k [description]
*
* @return {object} [description]
*/
lod:function(k){
// load on demand
var id = this.hasOwnProperty(k)? this[k] : k;

if( id=== undefined ) return undefined;
if(id.split === undefined ){
return new this.$.Comptes( id, this.$ );
}
var t = id.split(/:/);
t = $fi.fn[t[0]];
if( id === undefined ) return undefined;
if( id === false ) return undefined;

//return new t({ id: id });
return this.$.sync('read',{
id: id,
$: this.$
});
},
if(id.split === undefined ){
return new this.$.Comptes( id, this.$ );
}

return this.$.sync('read',{
id: id,
$: this.$
});
},

/**
* generate an ID for an object
*
* @return {string} ID of the object
*/
sign:function(){
this.id= ''+CryptoJS.SHA1( JSON.stringify(this) );
return this.id;
},

/**
* generate an ID for an object
*
* @return {string} ID of the object
*/
sign:function(){
this.id= ''+CryptoJS.SHA1( JSON.stringify(this) );
return this.id;
},

/**
* Initialize an object with given s non undefined values or d values
*
* @param {object} s [description]
* @param {object} d [description]
*/
set_or_default:function(s,d){
for( var i in d ){
this[i]= ( s[i]===undefined ? d[i] : s[i] );
}
},

save:function(o){
return this.$.sync('update',this,o);
},
/**
* Initialize an object with given s non undefined values or d values
*
* @param {object} s [description]
* @param {object} d [description]
*/
set_or_default:function(s,d){
for( var i in d ){
this[i]= ( s[i]===undefined ? d[i] : s[i] );
}
return this;
},

fetch:function(o){
var i = this;
o=o||{};
o.success=o.success||function(){};
var o_suc = o.success;
o.success = function(data){ i.set_or_default({},data); o_suc(data);};
return this.$.sync('read',this,o );
},

});
/**
* Save an object ... and attribut it an ID
*/
save:function(o){
return this.$.sync('update',this,o);
}
});
Loading

0 comments on commit ed3591b

Please # to comment.