Initial commit
Benjamin Renard

Benjamin Renard commited on 2014-01-06 00:46:22
Showing 7 changed files, with 908 additions and 0 deletions.

... ...
@@ -0,0 +1,2 @@
1
+*~
2
+*.swp
... ...
@@ -0,0 +1,6 @@
1
+//! moment.js
2
+//! version : 2.5.0
3
+//! authors : Tim Wood, Iskren Chernev, Moment.js contributors
4
+//! license : MIT
5
+//! momentjs.com
6
+(function(a){function b(a,b){return function(c){return i(a.call(this,c),b)}}function c(a,b){return function(c){return this.lang().ordinal(a.call(this,c),b)}}function d(){}function e(a){u(a),g(this,a)}function f(a){var b=o(a),c=b.year||0,d=b.month||0,e=b.week||0,f=b.day||0,g=b.hour||0,h=b.minute||0,i=b.second||0,j=b.millisecond||0;this._milliseconds=+j+1e3*i+6e4*h+36e5*g,this._days=+f+7*e,this._months=+d+12*c,this._data={},this._bubble()}function g(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return b.hasOwnProperty("toString")&&(a.toString=b.toString),b.hasOwnProperty("valueOf")&&(a.valueOf=b.valueOf),a}function h(a){return 0>a?Math.ceil(a):Math.floor(a)}function i(a,b,c){for(var d=Math.abs(a)+"",e=a>=0;d.length<b;)d="0"+d;return(e?c?"+":"":"-")+d}function j(a,b,c,d){var e,f,g=b._milliseconds,h=b._days,i=b._months;g&&a._d.setTime(+a._d+g*c),(h||i)&&(e=a.minute(),f=a.hour()),h&&a.date(a.date()+h*c),i&&a.month(a.month()+i*c),g&&!d&&cb.updateOffset(a),(h||i)&&(a.minute(e),a.hour(f))}function k(a){return"[object Array]"===Object.prototype.toString.call(a)}function l(a){return"[object Date]"===Object.prototype.toString.call(a)||a instanceof Date}function m(a,b,c){var d,e=Math.min(a.length,b.length),f=Math.abs(a.length-b.length),g=0;for(d=0;e>d;d++)(c&&a[d]!==b[d]||!c&&q(a[d])!==q(b[d]))&&g++;return g+f}function n(a){if(a){var b=a.toLowerCase().replace(/(.)s$/,"$1");a=Qb[a]||Rb[b]||b}return a}function o(a){var b,c,d={};for(c in a)a.hasOwnProperty(c)&&(b=n(c),b&&(d[b]=a[c]));return d}function p(b){var c,d;if(0===b.indexOf("week"))c=7,d="day";else{if(0!==b.indexOf("month"))return;c=12,d="month"}cb[b]=function(e,f){var g,h,i=cb.fn._lang[b],j=[];if("number"==typeof e&&(f=e,e=a),h=function(a){var b=cb().utc().set(d,a);return i.call(cb.fn._lang,b,e||"")},null!=f)return h(f);for(g=0;c>g;g++)j.push(h(g));return j}}function q(a){var b=+a,c=0;return 0!==b&&isFinite(b)&&(c=b>=0?Math.floor(b):Math.ceil(b)),c}function r(a,b){return new Date(Date.UTC(a,b+1,0)).getUTCDate()}function s(a){return t(a)?366:365}function t(a){return a%4===0&&a%100!==0||a%400===0}function u(a){var b;a._a&&-2===a._pf.overflow&&(b=a._a[ib]<0||a._a[ib]>11?ib:a._a[jb]<1||a._a[jb]>r(a._a[hb],a._a[ib])?jb:a._a[kb]<0||a._a[kb]>23?kb:a._a[lb]<0||a._a[lb]>59?lb:a._a[mb]<0||a._a[mb]>59?mb:a._a[nb]<0||a._a[nb]>999?nb:-1,a._pf._overflowDayOfYear&&(hb>b||b>jb)&&(b=jb),a._pf.overflow=b)}function v(a){a._pf={empty:!1,unusedTokens:[],unusedInput:[],overflow:-2,charsLeftOver:0,nullInput:!1,invalidMonth:null,invalidFormat:!1,userInvalidated:!1,iso:!1}}function w(a){return null==a._isValid&&(a._isValid=!isNaN(a._d.getTime())&&a._pf.overflow<0&&!a._pf.empty&&!a._pf.invalidMonth&&!a._pf.nullInput&&!a._pf.invalidFormat&&!a._pf.userInvalidated,a._strict&&(a._isValid=a._isValid&&0===a._pf.charsLeftOver&&0===a._pf.unusedTokens.length)),a._isValid}function x(a){return a?a.toLowerCase().replace("_","-"):a}function y(a,b){return b._isUTC?cb(a).zone(b._offset||0):cb(a).local()}function z(a,b){return b.abbr=a,ob[a]||(ob[a]=new d),ob[a].set(b),ob[a]}function A(a){delete ob[a]}function B(a){var b,c,d,e,f=0,g=function(a){if(!ob[a]&&pb)try{require("./lang/"+a)}catch(b){}return ob[a]};if(!a)return cb.fn._lang;if(!k(a)){if(c=g(a))return c;a=[a]}for(;f<a.length;){for(e=x(a[f]).split("-"),b=e.length,d=x(a[f+1]),d=d?d.split("-"):null;b>0;){if(c=g(e.slice(0,b).join("-")))return c;if(d&&d.length>=b&&m(e,d,!0)>=b-1)break;b--}f++}return cb.fn._lang}function C(a){return a.match(/\[[\s\S]/)?a.replace(/^\[|\]$/g,""):a.replace(/\\/g,"")}function D(a){var b,c,d=a.match(tb);for(b=0,c=d.length;c>b;b++)d[b]=Vb[d[b]]?Vb[d[b]]:C(d[b]);return function(e){var f="";for(b=0;c>b;b++)f+=d[b]instanceof Function?d[b].call(e,a):d[b];return f}}function E(a,b){return a.isValid()?(b=F(b,a.lang()),Sb[b]||(Sb[b]=D(b)),Sb[b](a)):a.lang().invalidDate()}function F(a,b){function c(a){return b.longDateFormat(a)||a}var d=5;for(ub.lastIndex=0;d>=0&&ub.test(a);)a=a.replace(ub,c),ub.lastIndex=0,d-=1;return a}function G(a,b){var c,d=b._strict;switch(a){case"DDDD":return Gb;case"YYYY":case"GGGG":case"gggg":return d?Hb:xb;case"YYYYYY":case"YYYYY":case"GGGGG":case"ggggg":return d?Ib:yb;case"S":if(d)return Eb;case"SS":if(d)return Fb;case"SSS":case"DDD":return d?Gb:wb;case"MMM":case"MMMM":case"dd":case"ddd":case"dddd":return Ab;case"a":case"A":return B(b._l)._meridiemParse;case"X":return Db;case"Z":case"ZZ":return Bb;case"T":return Cb;case"SSSS":return zb;case"MM":case"DD":case"YY":case"GG":case"gg":case"HH":case"hh":case"mm":case"ss":case"ww":case"WW":return d?Fb:vb;case"M":case"D":case"d":case"H":case"h":case"m":case"s":case"w":case"W":case"e":case"E":return d?Eb:vb;default:return c=new RegExp(O(N(a.replace("\\","")),"i"))}}function H(a){a=a||"";var b=a.match(Bb)||[],c=b[b.length-1]||[],d=(c+"").match(Nb)||["-",0,0],e=+(60*d[1])+q(d[2]);return"+"===d[0]?-e:e}function I(a,b,c){var d,e=c._a;switch(a){case"M":case"MM":null!=b&&(e[ib]=q(b)-1);break;case"MMM":case"MMMM":d=B(c._l).monthsParse(b),null!=d?e[ib]=d:c._pf.invalidMonth=b;break;case"D":case"DD":null!=b&&(e[jb]=q(b));break;case"DDD":case"DDDD":null!=b&&(c._dayOfYear=q(b));break;case"YY":e[hb]=q(b)+(q(b)>68?1900:2e3);break;case"YYYY":case"YYYYY":case"YYYYYY":e[hb]=q(b);break;case"a":case"A":c._isPm=B(c._l).isPM(b);break;case"H":case"HH":case"h":case"hh":e[kb]=q(b);break;case"m":case"mm":e[lb]=q(b);break;case"s":case"ss":e[mb]=q(b);break;case"S":case"SS":case"SSS":case"SSSS":e[nb]=q(1e3*("0."+b));break;case"X":c._d=new Date(1e3*parseFloat(b));break;case"Z":case"ZZ":c._useUTC=!0,c._tzm=H(b);break;case"w":case"ww":case"W":case"WW":case"d":case"dd":case"ddd":case"dddd":case"e":case"E":a=a.substr(0,1);case"gg":case"gggg":case"GG":case"GGGG":case"GGGGG":a=a.substr(0,2),b&&(c._w=c._w||{},c._w[a]=b)}}function J(a){var b,c,d,e,f,g,h,i,j,k,l=[];if(!a._d){for(d=L(a),a._w&&null==a._a[jb]&&null==a._a[ib]&&(f=function(b){var c=parseInt(b,10);return b?b.length<3?c>68?1900+c:2e3+c:c:null==a._a[hb]?cb().weekYear():a._a[hb]},g=a._w,null!=g.GG||null!=g.W||null!=g.E?h=Y(f(g.GG),g.W||1,g.E,4,1):(i=B(a._l),j=null!=g.d?U(g.d,i):null!=g.e?parseInt(g.e,10)+i._week.dow:0,k=parseInt(g.w,10)||1,null!=g.d&&j<i._week.dow&&k++,h=Y(f(g.gg),k,j,i._week.doy,i._week.dow)),a._a[hb]=h.year,a._dayOfYear=h.dayOfYear),a._dayOfYear&&(e=null==a._a[hb]?d[hb]:a._a[hb],a._dayOfYear>s(e)&&(a._pf._overflowDayOfYear=!0),c=T(e,0,a._dayOfYear),a._a[ib]=c.getUTCMonth(),a._a[jb]=c.getUTCDate()),b=0;3>b&&null==a._a[b];++b)a._a[b]=l[b]=d[b];for(;7>b;b++)a._a[b]=l[b]=null==a._a[b]?2===b?1:0:a._a[b];l[kb]+=q((a._tzm||0)/60),l[lb]+=q((a._tzm||0)%60),a._d=(a._useUTC?T:S).apply(null,l)}}function K(a){var b;a._d||(b=o(a._i),a._a=[b.year,b.month,b.day,b.hour,b.minute,b.second,b.millisecond],J(a))}function L(a){var b=new Date;return a._useUTC?[b.getUTCFullYear(),b.getUTCMonth(),b.getUTCDate()]:[b.getFullYear(),b.getMonth(),b.getDate()]}function M(a){a._a=[],a._pf.empty=!0;var b,c,d,e,f,g=B(a._l),h=""+a._i,i=h.length,j=0;for(d=F(a._f,g).match(tb)||[],b=0;b<d.length;b++)e=d[b],c=(h.match(G(e,a))||[])[0],c&&(f=h.substr(0,h.indexOf(c)),f.length>0&&a._pf.unusedInput.push(f),h=h.slice(h.indexOf(c)+c.length),j+=c.length),Vb[e]?(c?a._pf.empty=!1:a._pf.unusedTokens.push(e),I(e,c,a)):a._strict&&!c&&a._pf.unusedTokens.push(e);a._pf.charsLeftOver=i-j,h.length>0&&a._pf.unusedInput.push(h),a._isPm&&a._a[kb]<12&&(a._a[kb]+=12),a._isPm===!1&&12===a._a[kb]&&(a._a[kb]=0),J(a),u(a)}function N(a){return a.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(a,b,c,d,e){return b||c||d||e})}function O(a){return a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function P(a){var b,c,d,e,f;if(0===a._f.length)return a._pf.invalidFormat=!0,a._d=new Date(0/0),void 0;for(e=0;e<a._f.length;e++)f=0,b=g({},a),v(b),b._f=a._f[e],M(b),w(b)&&(f+=b._pf.charsLeftOver,f+=10*b._pf.unusedTokens.length,b._pf.score=f,(null==d||d>f)&&(d=f,c=b));g(a,c||b)}function Q(a){var b,c=a._i,d=Jb.exec(c);if(d){for(a._pf.iso=!0,b=4;b>0;b--)if(d[b]){a._f=Lb[b-1]+(d[6]||" ");break}for(b=0;4>b;b++)if(Mb[b][1].exec(c)){a._f+=Mb[b][0];break}c.match(Bb)&&(a._f+="Z"),M(a)}else a._d=new Date(c)}function R(b){var c=b._i,d=qb.exec(c);c===a?b._d=new Date:d?b._d=new Date(+d[1]):"string"==typeof c?Q(b):k(c)?(b._a=c.slice(0),J(b)):l(c)?b._d=new Date(+c):"object"==typeof c?K(b):b._d=new Date(c)}function S(a,b,c,d,e,f,g){var h=new Date(a,b,c,d,e,f,g);return 1970>a&&h.setFullYear(a),h}function T(a){var b=new Date(Date.UTC.apply(null,arguments));return 1970>a&&b.setUTCFullYear(a),b}function U(a,b){if("string"==typeof a)if(isNaN(a)){if(a=b.weekdaysParse(a),"number"!=typeof a)return null}else a=parseInt(a,10);return a}function V(a,b,c,d,e){return e.relativeTime(b||1,!!c,a,d)}function W(a,b,c){var d=gb(Math.abs(a)/1e3),e=gb(d/60),f=gb(e/60),g=gb(f/24),h=gb(g/365),i=45>d&&["s",d]||1===e&&["m"]||45>e&&["mm",e]||1===f&&["h"]||22>f&&["hh",f]||1===g&&["d"]||25>=g&&["dd",g]||45>=g&&["M"]||345>g&&["MM",gb(g/30)]||1===h&&["y"]||["yy",h];return i[2]=b,i[3]=a>0,i[4]=c,V.apply({},i)}function X(a,b,c){var d,e=c-b,f=c-a.day();return f>e&&(f-=7),e-7>f&&(f+=7),d=cb(a).add("d",f),{week:Math.ceil(d.dayOfYear()/7),year:d.year()}}function Y(a,b,c,d,e){var f,g,h=new Date(i(a,6,!0)+"-01-01").getUTCDay();return c=null!=c?c:e,f=e-h+(h>d?7:0),g=7*(b-1)+(c-e)+f+1,{year:g>0?a:a-1,dayOfYear:g>0?g:s(a-1)+g}}function Z(a){var b=a._i,c=a._f;return"undefined"==typeof a._pf&&v(a),null===b?cb.invalid({nullInput:!0}):("string"==typeof b&&(a._i=b=B().preparse(b)),cb.isMoment(b)?(a=g({},b),a._d=new Date(+b._d)):c?k(c)?P(a):M(a):R(a),new e(a))}function $(a,b){cb.fn[a]=cb.fn[a+"s"]=function(a){var c=this._isUTC?"UTC":"";return null!=a?(this._d["set"+c+b](a),cb.updateOffset(this),this):this._d["get"+c+b]()}}function _(a){cb.duration.fn[a]=function(){return this._data[a]}}function ab(a,b){cb.duration.fn["as"+a]=function(){return+this/b}}function bb(a){var b=!1,c=cb;"undefined"==typeof ender&&(a?(fb.moment=function(){return!b&&console&&console.warn&&(b=!0,console.warn("Accessing Moment through the global scope is deprecated, and will be removed in an upcoming release.")),c.apply(null,arguments)},g(fb.moment,c)):fb.moment=cb)}for(var cb,db,eb="2.5.0",fb=this,gb=Math.round,hb=0,ib=1,jb=2,kb=3,lb=4,mb=5,nb=6,ob={},pb="undefined"!=typeof module&&module.exports&&"undefined"!=typeof require,qb=/^\/?Date\((\-?\d+)/i,rb=/(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,sb=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,tb=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|X|zz?|ZZ?|.)/g,ub=/(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,vb=/\d\d?/,wb=/\d{1,3}/,xb=/\d{1,4}/,yb=/[+\-]?\d{1,6}/,zb=/\d+/,Ab=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,Bb=/Z|[\+\-]\d\d:?\d\d/gi,Cb=/T/i,Db=/[\+\-]?\d+(\.\d{1,3})?/,Eb=/\d/,Fb=/\d\d/,Gb=/\d{3}/,Hb=/\d{4}/,Ib=/[+\-]?\d{6}/,Jb=/^\s*\d{4}-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,Kb="YYYY-MM-DDTHH:mm:ssZ",Lb=["YYYY-MM-DD","GGGG-[W]WW","GGGG-[W]WW-E","YYYY-DDD"],Mb=[["HH:mm:ss.SSSS",/(T| )\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/(T| )\d\d:\d\d:\d\d/],["HH:mm",/(T| )\d\d:\d\d/],["HH",/(T| )\d\d/]],Nb=/([\+\-]|\d\d)/gi,Ob="Date|Hours|Minutes|Seconds|Milliseconds".split("|"),Pb={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6},Qb={ms:"millisecond",s:"second",m:"minute",h:"hour",d:"day",D:"date",w:"week",W:"isoWeek",M:"month",y:"year",DDD:"dayOfYear",e:"weekday",E:"isoWeekday",gg:"weekYear",GG:"isoWeekYear"},Rb={dayofyear:"dayOfYear",isoweekday:"isoWeekday",isoweek:"isoWeek",weekyear:"weekYear",isoweekyear:"isoWeekYear"},Sb={},Tb="DDD w W M D d".split(" "),Ub="M D H h m s w W".split(" "),Vb={M:function(){return this.month()+1},MMM:function(a){return this.lang().monthsShort(this,a)},MMMM:function(a){return this.lang().months(this,a)},D:function(){return this.date()},DDD:function(){return this.dayOfYear()},d:function(){return this.day()},dd:function(a){return this.lang().weekdaysMin(this,a)},ddd:function(a){return this.lang().weekdaysShort(this,a)},dddd:function(a){return this.lang().weekdays(this,a)},w:function(){return this.week()},W:function(){return this.isoWeek()},YY:function(){return i(this.year()%100,2)},YYYY:function(){return i(this.year(),4)},YYYYY:function(){return i(this.year(),5)},YYYYYY:function(){var a=this.year(),b=a>=0?"+":"-";return b+i(Math.abs(a),6)},gg:function(){return i(this.weekYear()%100,2)},gggg:function(){return this.weekYear()},ggggg:function(){return i(this.weekYear(),5)},GG:function(){return i(this.isoWeekYear()%100,2)},GGGG:function(){return this.isoWeekYear()},GGGGG:function(){return i(this.isoWeekYear(),5)},e:function(){return this.weekday()},E:function(){return this.isoWeekday()},a:function(){return this.lang().meridiem(this.hours(),this.minutes(),!0)},A:function(){return this.lang().meridiem(this.hours(),this.minutes(),!1)},H:function(){return this.hours()},h:function(){return this.hours()%12||12},m:function(){return this.minutes()},s:function(){return this.seconds()},S:function(){return q(this.milliseconds()/100)},SS:function(){return i(q(this.milliseconds()/10),2)},SSS:function(){return i(this.milliseconds(),3)},SSSS:function(){return i(this.milliseconds(),3)},Z:function(){var a=-this.zone(),b="+";return 0>a&&(a=-a,b="-"),b+i(q(a/60),2)+":"+i(q(a)%60,2)},ZZ:function(){var a=-this.zone(),b="+";return 0>a&&(a=-a,b="-"),b+i(q(a/60),2)+i(q(a)%60,2)},z:function(){return this.zoneAbbr()},zz:function(){return this.zoneName()},X:function(){return this.unix()},Q:function(){return this.quarter()}},Wb=["months","monthsShort","weekdays","weekdaysShort","weekdaysMin"];Tb.length;)db=Tb.pop(),Vb[db+"o"]=c(Vb[db],db);for(;Ub.length;)db=Ub.pop(),Vb[db+db]=b(Vb[db],2);for(Vb.DDDD=b(Vb.DDD,3),g(d.prototype,{set:function(a){var b,c;for(c in a)b=a[c],"function"==typeof b?this[c]=b:this["_"+c]=b},_months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),months:function(a){return this._months[a.month()]},_monthsShort:"Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),monthsShort:function(a){return this._monthsShort[a.month()]},monthsParse:function(a){var b,c,d;for(this._monthsParse||(this._monthsParse=[]),b=0;12>b;b++)if(this._monthsParse[b]||(c=cb.utc([2e3,b]),d="^"+this.months(c,"")+"|^"+this.monthsShort(c,""),this._monthsParse[b]=new RegExp(d.replace(".",""),"i")),this._monthsParse[b].test(a))return b},_weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),weekdays:function(a){return this._weekdays[a.day()]},_weekdaysShort:"Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),weekdaysShort:function(a){return this._weekdaysShort[a.day()]},_weekdaysMin:"Su_Mo_Tu_We_Th_Fr_Sa".split("_"),weekdaysMin:function(a){return this._weekdaysMin[a.day()]},weekdaysParse:function(a){var b,c,d;for(this._weekdaysParse||(this._weekdaysParse=[]),b=0;7>b;b++)if(this._weekdaysParse[b]||(c=cb([2e3,1]).day(b),d="^"+this.weekdays(c,"")+"|^"+this.weekdaysShort(c,"")+"|^"+this.weekdaysMin(c,""),this._weekdaysParse[b]=new RegExp(d.replace(".",""),"i")),this._weekdaysParse[b].test(a))return b},_longDateFormat:{LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D YYYY",LLL:"MMMM D YYYY LT",LLLL:"dddd, MMMM D YYYY LT"},longDateFormat:function(a){var b=this._longDateFormat[a];return!b&&this._longDateFormat[a.toUpperCase()]&&(b=this._longDateFormat[a.toUpperCase()].replace(/MMMM|MM|DD|dddd/g,function(a){return a.slice(1)}),this._longDateFormat[a]=b),b},isPM:function(a){return"p"===(a+"").toLowerCase().charAt(0)},_meridiemParse:/[ap]\.?m?\.?/i,meridiem:function(a,b,c){return a>11?c?"pm":"PM":c?"am":"AM"},_calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},calendar:function(a,b){var c=this._calendar[a];return"function"==typeof c?c.apply(b):c},_relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},relativeTime:function(a,b,c,d){var e=this._relativeTime[c];return"function"==typeof e?e(a,b,c,d):e.replace(/%d/i,a)},pastFuture:function(a,b){var c=this._relativeTime[a>0?"future":"past"];return"function"==typeof c?c(b):c.replace(/%s/i,b)},ordinal:function(a){return this._ordinal.replace("%d",a)},_ordinal:"%d",preparse:function(a){return a},postformat:function(a){return a},week:function(a){return X(a,this._week.dow,this._week.doy).week},_week:{dow:0,doy:6},_invalidDate:"Invalid date",invalidDate:function(){return this._invalidDate}}),cb=function(b,c,d,e){return"boolean"==typeof d&&(e=d,d=a),Z({_i:b,_f:c,_l:d,_strict:e,_isUTC:!1})},cb.utc=function(b,c,d,e){var f;return"boolean"==typeof d&&(e=d,d=a),f=Z({_useUTC:!0,_isUTC:!0,_l:d,_i:b,_f:c,_strict:e}).utc()},cb.unix=function(a){return cb(1e3*a)},cb.duration=function(a,b){var c,d,e,g=a,h=null;return cb.isDuration(a)?g={ms:a._milliseconds,d:a._days,M:a._months}:"number"==typeof a?(g={},b?g[b]=a:g.milliseconds=a):(h=rb.exec(a))?(c="-"===h[1]?-1:1,g={y:0,d:q(h[jb])*c,h:q(h[kb])*c,m:q(h[lb])*c,s:q(h[mb])*c,ms:q(h[nb])*c}):(h=sb.exec(a))&&(c="-"===h[1]?-1:1,e=function(a){var b=a&&parseFloat(a.replace(",","."));return(isNaN(b)?0:b)*c},g={y:e(h[2]),M:e(h[3]),d:e(h[4]),h:e(h[5]),m:e(h[6]),s:e(h[7]),w:e(h[8])}),d=new f(g),cb.isDuration(a)&&a.hasOwnProperty("_lang")&&(d._lang=a._lang),d},cb.version=eb,cb.defaultFormat=Kb,cb.updateOffset=function(){},cb.lang=function(a,b){var c;return a?(b?z(x(a),b):null===b?(A(a),a="en"):ob[a]||B(a),c=cb.duration.fn._lang=cb.fn._lang=B(a),c._abbr):cb.fn._lang._abbr},cb.langData=function(a){return a&&a._lang&&a._lang._abbr&&(a=a._lang._abbr),B(a)},cb.isMoment=function(a){return a instanceof e},cb.isDuration=function(a){return a instanceof f},db=Wb.length-1;db>=0;--db)p(Wb[db]);for(cb.normalizeUnits=function(a){return n(a)},cb.invalid=function(a){var b=cb.utc(0/0);return null!=a?g(b._pf,a):b._pf.userInvalidated=!0,b},cb.parseZone=function(a){return cb(a).parseZone()},g(cb.fn=e.prototype,{clone:function(){return cb(this)},valueOf:function(){return+this._d+6e4*(this._offset||0)},unix:function(){return Math.floor(+this/1e3)},toString:function(){return this.clone().lang("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},toDate:function(){return this._offset?new Date(+this):this._d},toISOString:function(){var a=cb(this).utc();return 0<a.year()&&a.year()<=9999?E(a,"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]"):E(a,"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]")},toArray:function(){var a=this;return[a.year(),a.month(),a.date(),a.hours(),a.minutes(),a.seconds(),a.milliseconds()]},isValid:function(){return w(this)},isDSTShifted:function(){return this._a?this.isValid()&&m(this._a,(this._isUTC?cb.utc(this._a):cb(this._a)).toArray())>0:!1},parsingFlags:function(){return g({},this._pf)},invalidAt:function(){return this._pf.overflow},utc:function(){return this.zone(0)},local:function(){return this.zone(0),this._isUTC=!1,this},format:function(a){var b=E(this,a||cb.defaultFormat);return this.lang().postformat(b)},add:function(a,b){var c;return c="string"==typeof a?cb.duration(+b,a):cb.duration(a,b),j(this,c,1),this},subtract:function(a,b){var c;return c="string"==typeof a?cb.duration(+b,a):cb.duration(a,b),j(this,c,-1),this},diff:function(a,b,c){var d,e,f=y(a,this),g=6e4*(this.zone()-f.zone());return b=n(b),"year"===b||"month"===b?(d=432e5*(this.daysInMonth()+f.daysInMonth()),e=12*(this.year()-f.year())+(this.month()-f.month()),e+=(this-cb(this).startOf("month")-(f-cb(f).startOf("month")))/d,e-=6e4*(this.zone()-cb(this).startOf("month").zone()-(f.zone()-cb(f).startOf("month").zone()))/d,"year"===b&&(e/=12)):(d=this-f,e="second"===b?d/1e3:"minute"===b?d/6e4:"hour"===b?d/36e5:"day"===b?(d-g)/864e5:"week"===b?(d-g)/6048e5:d),c?e:h(e)},from:function(a,b){return cb.duration(this.diff(a)).lang(this.lang()._abbr).humanize(!b)},fromNow:function(a){return this.from(cb(),a)},calendar:function(){var a=y(cb(),this).startOf("day"),b=this.diff(a,"days",!0),c=-6>b?"sameElse":-1>b?"lastWeek":0>b?"lastDay":1>b?"sameDay":2>b?"nextDay":7>b?"nextWeek":"sameElse";return this.format(this.lang().calendar(c,this))},isLeapYear:function(){return t(this.year())},isDST:function(){return this.zone()<this.clone().month(0).zone()||this.zone()<this.clone().month(5).zone()},day:function(a){var b=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=a?(a=U(a,this.lang()),this.add({d:a-b})):b},month:function(a){var b,c=this._isUTC?"UTC":"";return null!=a?"string"==typeof a&&(a=this.lang().monthsParse(a),"number"!=typeof a)?this:(b=this.date(),this.date(1),this._d["set"+c+"Month"](a),this.date(Math.min(b,this.daysInMonth())),cb.updateOffset(this),this):this._d["get"+c+"Month"]()},startOf:function(a){switch(a=n(a)){case"year":this.month(0);case"month":this.date(1);case"week":case"isoWeek":case"day":this.hours(0);case"hour":this.minutes(0);case"minute":this.seconds(0);case"second":this.milliseconds(0)}return"week"===a?this.weekday(0):"isoWeek"===a&&this.isoWeekday(1),this},endOf:function(a){return a=n(a),this.startOf(a).add("isoWeek"===a?"week":a,1).subtract("ms",1)},isAfter:function(a,b){return b="undefined"!=typeof b?b:"millisecond",+this.clone().startOf(b)>+cb(a).startOf(b)},isBefore:function(a,b){return b="undefined"!=typeof b?b:"millisecond",+this.clone().startOf(b)<+cb(a).startOf(b)},isSame:function(a,b){return b=b||"ms",+this.clone().startOf(b)===+y(a,this).startOf(b)},min:function(a){return a=cb.apply(null,arguments),this>a?this:a},max:function(a){return a=cb.apply(null,arguments),a>this?this:a},zone:function(a){var b=this._offset||0;return null==a?this._isUTC?b:this._d.getTimezoneOffset():("string"==typeof a&&(a=H(a)),Math.abs(a)<16&&(a=60*a),this._offset=a,this._isUTC=!0,b!==a&&j(this,cb.duration(b-a,"m"),1,!0),this)},zoneAbbr:function(){return this._isUTC?"UTC":""},zoneName:function(){return this._isUTC?"Coordinated Universal Time":""},parseZone:function(){return this._tzm?this.zone(this._tzm):"string"==typeof this._i&&this.zone(this._i),this},hasAlignedHourOffset:function(a){return a=a?cb(a).zone():0,(this.zone()-a)%60===0},daysInMonth:function(){return r(this.year(),this.month())},dayOfYear:function(a){var b=gb((cb(this).startOf("day")-cb(this).startOf("year"))/864e5)+1;return null==a?b:this.add("d",a-b)},quarter:function(){return Math.ceil((this.month()+1)/3)},weekYear:function(a){var b=X(this,this.lang()._week.dow,this.lang()._week.doy).year;return null==a?b:this.add("y",a-b)},isoWeekYear:function(a){var b=X(this,1,4).year;return null==a?b:this.add("y",a-b)},week:function(a){var b=this.lang().week(this);return null==a?b:this.add("d",7*(a-b))},isoWeek:function(a){var b=X(this,1,4).week;return null==a?b:this.add("d",7*(a-b))},weekday:function(a){var b=(this.day()+7-this.lang()._week.dow)%7;return null==a?b:this.add("d",a-b)},isoWeekday:function(a){return null==a?this.day()||7:this.day(this.day()%7?a:a-7)},get:function(a){return a=n(a),this[a]()},set:function(a,b){return a=n(a),"function"==typeof this[a]&&this[a](b),this},lang:function(b){return b===a?this._lang:(this._lang=B(b),this)}}),db=0;db<Ob.length;db++)$(Ob[db].toLowerCase().replace(/s$/,""),Ob[db]);$("year","FullYear"),cb.fn.days=cb.fn.day,cb.fn.months=cb.fn.month,cb.fn.weeks=cb.fn.week,cb.fn.isoWeeks=cb.fn.isoWeek,cb.fn.toJSON=cb.fn.toISOString,g(cb.duration.fn=f.prototype,{_bubble:function(){var a,b,c,d,e=this._milliseconds,f=this._days,g=this._months,i=this._data;i.milliseconds=e%1e3,a=h(e/1e3),i.seconds=a%60,b=h(a/60),i.minutes=b%60,c=h(b/60),i.hours=c%24,f+=h(c/24),i.days=f%30,g+=h(f/30),i.months=g%12,d=h(g/12),i.years=d},weeks:function(){return h(this.days()/7)},valueOf:function(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*q(this._months/12)},humanize:function(a){var b=+this,c=W(b,!a,this.lang());return a&&(c=this.lang().pastFuture(b,c)),this.lang().postformat(c)},add:function(a,b){var c=cb.duration(a,b);return this._milliseconds+=c._milliseconds,this._days+=c._days,this._months+=c._months,this._bubble(),this},subtract:function(a,b){var c=cb.duration(a,b);return this._milliseconds-=c._milliseconds,this._days-=c._days,this._months-=c._months,this._bubble(),this},get:function(a){return a=n(a),this[a.toLowerCase()+"s"]()},as:function(a){return a=n(a),this["as"+a.charAt(0).toUpperCase()+a.slice(1)+"s"]()},lang:cb.fn.lang,toIsoString:function(){var a=Math.abs(this.years()),b=Math.abs(this.months()),c=Math.abs(this.days()),d=Math.abs(this.hours()),e=Math.abs(this.minutes()),f=Math.abs(this.seconds()+this.milliseconds()/1e3);return this.asSeconds()?(this.asSeconds()<0?"-":"")+"P"+(a?a+"Y":"")+(b?b+"M":"")+(c?c+"D":"")+(d||e||f?"T":"")+(d?d+"H":"")+(e?e+"M":"")+(f?f+"S":""):"P0D"}});for(db in Pb)Pb.hasOwnProperty(db)&&(ab(db,Pb[db]),_(db.toLowerCase()));ab("Weeks",6048e5),cb.duration.fn.asMonths=function(){return(+this-31536e6*this.years())/2592e6+12*this.years()},cb.lang("en",{ordinal:function(a){var b=a%10,c=1===q(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th";return a+c}}),pb?(module.exports=cb,bb(!0)):"function"==typeof define&&define.amd?define("moment",function(b,c,d){return d.config&&d.config()&&d.config().noGlobal!==!0&&bb(d.config().noGlobal===a),cb}):bb()}).call(this);
0 7
\ No newline at end of file
... ...
@@ -0,0 +1,371 @@
1
+refresh_group_list=function() {
2
+  grouplist=$('#group-choice')[0];
3
+  $('a.group-choice').each(function(idx,a) {
4
+    $(a).parent().remove();
5
+  });
6
+
7
+  if (groups.count()==0) {
8
+    $(grouplist).prepend('<li><a class="group-choice">Aucune groupe</a></li>');
9
+    
10
+  }
11
+  else { 
12
+    groups.each(function(idx,group) {
13
+      $(grouplist).prepend('<li><a class="group-choice">'+group.name+'</a></li>');
14
+    });
15
+
16
+    $('a.group-choice').each(function(idx,a) {
17
+      $(a).bind('click',on_group_choice_click);
18
+    });
19
+  }
20
+}
21
+
22
+
23
+/****************
24
+ * Add group
25
+ ****************/
26
+on_show_add_group_modal=function(e) {
27
+  $('#add_group_modal #add_group_name').focus();
28
+}
29
+
30
+on_valid_add_group_modal=function () {
31
+  var name=$('#add_group_name')[0].value;
32
+  if (name=='') {
33
+    alert('Vous devez saisir un nom !');
34
+    return;
35
+  }
36
+  if (groups[name]!==undefined) {
37
+    alert('Ce groupe exite déjà !');
38
+    return;
39
+  }
40
+  groups[name]=new Group(name);
41
+  refresh_group_list();
42
+  $('#add_group_modal').modal('hide');
43
+  groups.save();
44
+  view_group(groups[name]);
45
+}
46
+
47
+on_close_add_group_modal=function () {
48
+  $('#add_group_name form')[0].reset();
49
+}
50
+
51
+/****************
52
+ * Nav bars
53
+ ****************/
54
+on_group_choice_click=function(e) {
55
+  view_group(groups[$(e.target).html()]);
56
+}
57
+
58
+/****************
59
+ * View group
60
+ ****************/
61
+view_group=function(group) {
62
+  $('#view-group h1').html(group.name);
63
+  set_contributors(group);
64
+  on_contributor_change();
65
+  $('#view-group').css('display','block');
66
+}
67
+
68
+set_contributors=function(group) {
69
+  $('#view-group #contributor option').remove();
70
+  if(group.contributors.length==0) {
71
+    $('#view-group #contributor').append('<option>Aucun participant</option>');
72
+  }
73
+  else {
74
+    $(group.contributors).each(function(idx,c) {
75
+      $('#view-group #contributor').append('<option value="'+c.name+'">'+c.name+'</option>');
76
+    });
77
+  }
78
+}
79
+
80
+on_contributor_change=function(e) {
81
+  show_contributions(groups[$('#view-group h1').html()],$('#view-group #contributor')[0].value);
82
+}
83
+
84
+show_contributions=function(group,contributor_name) {
85
+  var tbody=$($('#view-group #contributions tbody')[0]);
86
+  tbody.html('');
87
+  total=$($('#view-group #total-value')[0]);
88
+  contributions=group.contributionsByContributorName(contributor_name);
89
+  if (contributions.length==0) {
90
+    tbody.append('<tr><td colspan=3>Aucune contributions</td></tr>');
91
+    total.html('0,00 €');
92
+  }
93
+  else {
94
+    sum=0;
95
+    for (idx in contributions) {
96
+      col_actions='<td><div class="btn-group" data-id="'+contributions[idx].id+'"><button type="button" class="btn btn-default contribution_edit_btn"><span class="glyphicon glyphicon-edit"></span></button><button type="button" class="btn btn-default contribution_delete_btn"><span class="glyphicon glyphicon-trash"></span></button></div></td>';
97
+      tbody.append('<tr><td>'+contributions[idx].getTitle()+'</td><td>'+contributions[idx].cost+' €</td>'+col_actions+'</tr>');
98
+      sum+=contributions[idx].cost;
99
+    }
100
+    total.html(sum+' €');
101
+  }
102
+
103
+  $('.contribution_delete_btn').bind('click',on_contribution_delete_btn_click);
104
+  $('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click);
105
+}
106
+
107
+/*********************
108
+ * Add contributor
109
+ *********************/
110
+on_click_add_contributor_btn=function() {
111
+  $('#add_contributor_modal #group_name')[0].value=$($('#view-group h1')[0]).html();
112
+  $('#add_contributor_modal').modal('show');
113
+}
114
+
115
+on_show_add_contributor_modal=function(e) {
116
+  $('#add_contributor_modal #add_contributor_name').focus();
117
+}
118
+
119
+on_valid_add_contributor_modal=function() {
120
+  var group=groups[$('#add_contributor_modal #group_name')[0].value];
121
+  var name=$('#add_contributor_name')[0].value;
122
+  if (name=='') {
123
+    alert('Vous devez saisir un nom !');
124
+    return;
125
+  }
126
+  if (group.contributorByName(name)!=undefined) {
127
+    alert('Un contributor porte déjà ce nom !');
128
+    return;
129
+  }
130
+  var email=$('#add_contributor_email')[0].value;
131
+  if (email=='') {
132
+    alert('Vous devez saisir un email !');
133
+    return;
134
+  }
135
+  if (group.contributorByEmail(email)!=undefined) {
136
+    alert('Un contributor utilise déjà cet email !');
137
+    return;
138
+  }
139
+  group.contributors.push(new Contributor(name,email));
140
+  set_contributors(group);
141
+  $('#add_contributor_modal').modal('hide');
142
+  $('#add_contributor_name')[0].value='';
143
+  $('#add_contributor_email')[0].value='';
144
+  groups.save();
145
+
146
+}
147
+
148
+on_close_add_contributor_modal=function () {
149
+  $('#add_contributor_name')[0].value='';
150
+  $('#add_contributor_email')[0].value='';
151
+}
152
+
153
+on_click_del_contributor_btn=function() {
154
+  contributor=$('#view-group #contributor')[0].value;
155
+  question='Voulez-vous vraiment supprimer '+contributor+' ?';
156
+  myconfirm(question,on_confirm_del_contributor,null,contributor);
157
+}
158
+
159
+on_confirm_del_contributor=function(contributor) {
160
+  var group=groups[$($('#view-group h1')[0]).html()];
161
+  group.removeContributor(contributor);
162
+  set_contributors(group);
163
+  groups.save();
164
+}
165
+
166
+/********************************
167
+ * Add/edit/delete contribution
168
+ ********************************/
169
+on_show_add_contribution_modal=function(e) {
170
+  var cs=$($('#add_contribution_modal #add_contribution_contributor_name')[0]);
171
+  cs.html('');
172
+  $('#view-group #contributor option').each(function(idx,option) {
173
+    cs.append($(option).clone());
174
+  });
175
+  cs[0].value = $('#view-group #contributor')[0].value;
176
+  $('#add_contribution_modal #add_contribution_title').focus();
177
+}
178
+
179
+on_click_add_contribution_btn=function() {
180
+  $('#add_contribution_modal #group_name')[0].value=$($('#view-group h1')[0]).html();
181
+  $('#add_contribution_modal #edit_id')[0].value='-1';
182
+  $('#add_contribution_modal').modal('show');
183
+}
184
+
185
+on_valid_add_contribution_modal=function(e) {
186
+  e.preventDefault();
187
+  var group=groups[$('#add_contribution_modal #group_name')[0].value];
188
+  var contributor_name=$('#add_contribution_contributor_name')[0].value;
189
+  var contributor=group.contributorByName(contributor_name);
190
+  if (contributor==undefined) {
191
+    alert('Participant inconu !');
192
+    return;
193
+  }
194
+  var title=$('#add_contribution_title')[0].value;
195
+  if (title=='') {
196
+    $('#add_contribution_title')[0].focus();
197
+    alert('Vous devez saisir un titre !');
198
+    return;
199
+  }
200
+  var cost=$('#add_contribution_cost')[0].value;
201
+  if (cost=='') {
202
+    $('#add_contribution_cost')[0].focus();
203
+    alert('Vous devez saisir un coût !');
204
+    return;
205
+  }
206
+  else if(!RegExp('^[0-9]*(,[0-9]{1,2})*$').test(cost)) {
207
+    $('#add_contribution_cost')[0].focus();
208
+    alert('Coût incorrect !');
209
+    return;
210
+  }
211
+  cost=parseFloat(cost.replace(',','.'));
212
+
213
+  var date=$('#add_contribution_date')[0].value;
214
+  if (date!='') {
215
+    if(!RegExp('^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]$').test(date)) {
216
+      $('#add_contribution_date')[0].focus();
217
+      alert('Date incorrect !');
218
+      return;
219
+    }
220
+    date=moment(date,'DD-MM-YYYY').toDate();
221
+    if (jQuery.type(date)!='date') {
222
+      alert('Date non-reconnu !');
223
+      return;
224
+    }
225
+  }
226
+  else {
227
+    date=new Date();
228
+  }
229
+
230
+  if($('#add_contribution_modal #edit_id')[0].value=='-1') {
231
+    group.addContribution(new Contribution(contributor,cost,title,date));
232
+  }
233
+  else {
234
+    contribution_id=$('#add_contribution_modal #edit_id')[0].value;
235
+    group.replaceContribution(contribution_id,new Contribution(contributor,cost,title,date));
236
+  }
237
+  show_contributions(group,contributor_name);
238
+  $('#add_contribution_modal').modal('hide');
239
+  $('#add_contribution_modal form')[0].reset();
240
+  groups.save();
241
+}
242
+
243
+on_close_add_contribution_modal=function () {
244
+  $('#add_contribution_modal form')[0].reset();
245
+}
246
+
247
+on_contribution_delete_btn_click=function(e) {
248
+  var group=groups[$($('#view-group h1')[0]).html()];
249
+  contribution_id=$($(e.target).parents('div')[0]).data('id');
250
+  contribution=group.contributions[contribution_id];
251
+  myconfirm('Etes-vous sûre de vouloir supprimer la participation '+contribution.getTitle()+' de '+contribution.contributor.name+' ?',on_confirm_contribution_delete,null,{'group':group,'contribution_id':contribution_id, 'contribution': contribution} );
252
+}
253
+
254
+on_confirm_contribution_delete=function(data) {
255
+  delete data.group.contributions[data.contribution_id];
256
+  groups.save();
257
+  on_contributor_change();
258
+}
259
+
260
+on_contribution_edit_btn_click=function(e) {
261
+  var group=groups[$($('#view-group h1')[0]).html()];
262
+  $('#add_contribution_modal #group_name')[0].value=$($('#view-group h1')[0]).html();
263
+  contribution_id=$($(e.target).parents('div')[0]).data('id');
264
+  contribution=group.contributions[contribution_id];
265
+  $('#add_contribution_modal #add_contribution_contributor_name')[0].value=contribution.contributor.name;
266
+  console.log($('#add_contribution_modal #add_contribution_contributor_name')[0]);
267
+  console.log(contribution.contributor.name);
268
+  $('#add_contribution_modal #add_contribution_title')[0].value=contribution.getTitle();
269
+  $('#add_contribution_modal #add_contribution_cost')[0].value=contribution.cost;
270
+  $('#add_contribution_modal #add_contribution_date')[0].value=moment(contribution.date).format('DD/MM/YYYY');
271
+  $('#add_contribution_modal #edit_id')[0].value=contribution_id;
272
+  $('#add_contribution_modal').modal('show');
273
+}
274
+
275
+
276
+
277
+/********************
278
+ * Clear local data
279
+ ********************/
280
+clear_local_data=function() {
281
+  myconfirm('Etes-vous sûre de vouloir supprimer les données locales ?',on_confirm_clear_local_data);
282
+}
283
+
284
+on_confirm_clear_local_data=function(data) {
285
+  localStorage.clear();
286
+  location.reload();
287
+}
288
+
289
+/*********************
290
+ * View balance
291
+ *********************/
292
+
293
+on_display_balance_btn_click=function(e) {
294
+  group=groups[$($('#view-group h1')[0]).html()];
295
+  display_balance(group);
296
+}
297
+
298
+display_balance=function(group) {
299
+  bal=group.balance();
300
+  tbody=$($('#display_balance_modal tbody')[0]);
301
+  tbody.html('');
302
+  sum=0;
303
+  for (c in bal) {
304
+    tbody.append('<tr><td>'+c+'</td><td>'+bal[c]+' €</td></tr>');
305
+    sum+=bal[c];
306
+  }
307
+  $('#display_balance_modal #total-value').html(sum+' €');
308
+  $('#display_balance_modal').modal('show');
309
+}
310
+
311
+/*********************
312
+ * Remove group
313
+ *********************/
314
+
315
+on_remove_group_btn_click=function(e) {
316
+  group=groups[$($('#view-group h1')[0]).html()];
317
+  myconfirm('Etes-vous sûre de vouloir supprimer le group '+group.name+' ?',on_confirm_remove_group,null,group);
318
+  
319
+}
320
+
321
+on_confirm_remove_group=function(group) {
322
+  if(groups.removeGroup(group.name)) {
323
+    groups.save();
324
+    location.reload();
325
+  }
326
+  else {
327
+    alert('Erreur en supprimant le groupe '+group.name+' :(');
328
+  }
329
+}
330
+
331
+
332
+/*********************
333
+ * Activate
334
+ *********************/
335
+$( document ).ready( function() {
336
+  if(typeof(Storage)!=="undefined"){
337
+    groups=new GroupList();
338
+    groups.loadFromLocalStorage();
339
+    refresh_group_list();
340
+  }
341
+  else {
342
+    alert('Local storage not supported !');
343
+  }
344
+
345
+  $('#add_group_submit').bind('click',on_valid_add_group_modal);
346
+  $("#add_group_modal").on('shown.bs.modal',on_show_add_group_modal);
347
+  $("#add_group_modal").on('hidden.bs.modal',on_close_add_group_modal);
348
+  $("#add_group_modal form").on('submit',on_valid_add_group_modal);
349
+
350
+  $('#clear_local_data').bind('click',clear_local_data);
351
+
352
+  $('#view-group #contributor').bind('change',on_contributor_change);
353
+
354
+  $('#add_contributor_btn').bind('click',on_click_add_contributor_btn);
355
+  $('#add_contributor_submit').bind('click',on_valid_add_contributor_modal);
356
+  $("#add_contributor_modal").on('shown.bs.modal',on_show_add_contributor_modal);
357
+  $("#add_contributor_modal").on('hidden.bs.modal',on_close_add_contributor_modal);
358
+  $("#add_contributor_modal form").on('submit',on_valid_add_contributor_modal);
359
+
360
+  $('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
361
+
362
+  $('#add_contribution_btn').bind('click',on_click_add_contribution_btn);
363
+  $('#add_contribution_submit').bind('click',on_valid_add_contribution_modal);
364
+  $("#add_contribution_modal").on('shown.bs.modal',on_show_add_contribution_modal);
365
+  $("#add_contribution_modal").on('hidden.bs.modal',on_close_add_contribution_modal);
366
+  $("#add_contribution_modal form").on('submit',on_valid_add_contribution_modal);
367
+
368
+  $("#display_balance_btn").bind('click',on_display_balance_btn_click);
369
+
370
+  $('#remove_group_btn').bind('click',on_remove_group_btn_click);
371
+} );
... ...
@@ -0,0 +1,35 @@
1
+var _myconfirm={
2
+  'onconfirm': null,
3
+  'oncancel': null,
4
+  'data': null
5
+};
6
+
7
+myconfirm=function(question,onconfirm,oncancel,data) {
8
+  $('#confirm_modal #question').html(question);
9
+  _myconfirm={
10
+    'onconfirm': onconfirm,
11
+    'oncancel': oncancel,
12
+    'data': data
13
+  };
14
+  $('#confirm_modal').modal('show');
15
+}
16
+
17
+_myconfirm_on_valid_click=function(e) {
18
+  $('#confirm_modal').modal('hide');
19
+  console.log(jQuery.type(_myconfirm.onconfirm));
20
+  if (jQuery.type(_myconfirm.onconfirm) == 'function') {
21
+    _myconfirm.onconfirm(_myconfirm.data);
22
+  }
23
+}
24
+
25
+_myconfirm_on_cancel_click=function(e) {
26
+  $('#confirm_modal').modal('hide');
27
+  if (jQuery.type(_myconfirm.oncancel) == 'function') {
28
+    _myconfirm.oncancel(_myconfirm.data);
29
+  }
30
+}
31
+
32
+$( document ).ready( function() {
33
+  $('#confirm_modal_submit').bind('click',_myconfirm_on_valid_click);
34
+  $('#confirm_modal .cancel').bind('click',_myconfirm_on_cancel_click);
35
+});
... ...
@@ -0,0 +1,198 @@
1
+function GroupList() {
2
+  
3
+  this.loadFromLocalStorage=function() {
4
+    if (localStorage.groups!==undefined) {
5
+      var groups=JSON.parse(localStorage.groups);
6
+      for (el in groups) {
7
+        this[el]=new Group(el,groups[el]);
8
+      }
9
+    }
10
+  }
11
+
12
+  this.export=function() {
13
+    ret={};
14
+    for (el in this) {
15
+      if (this.isGroup(this[el])) {
16
+        ret[el]=this[el].export();
17
+      }
18
+    }
19
+    return ret;
20
+  }
21
+
22
+  this.save=function() {
23
+    localStorage.groups=JSON.stringify(this.export());
24
+  }
25
+
26
+  this.each=function(fct) {
27
+    var idx=0;
28
+    for (el in this) {
29
+      if(this.isGroup(this[el])) {
30
+        fct(idx++,this[el]);
31
+      }
32
+    }
33
+  }
34
+
35
+  this.count=function() {
36
+    len=0;
37
+    for (el in this) {
38
+      if (this.isGroup(this[el])) len=len+1;
39
+    }
40
+    return len;
41
+  }
42
+
43
+  this.isGroup=function(el) {
44
+    return (el.isGroup!==undefined);
45
+  }
46
+
47
+  this.removeGroup=function(name) {
48
+    if (this.isGroup(this[name])) {
49
+      delete this[name];
50
+      return true;
51
+    }
52
+    return false;
53
+  }
54
+}
55
+
56
+function Group(name,data) {
57
+  this.name=name;
58
+  this.contributors=[];
59
+  this.contributions=[];
60
+
61
+
62
+  this.isGroup=function() {
63
+    return true;
64
+  }
65
+
66
+  this.export=function() {
67
+    var contributors=[];
68
+    for (idx in this.contributors) {
69
+      contributors.push(this.contributors[idx].export());
70
+    }
71
+    var contributions=[];
72
+    for (idx in this.contributions) {
73
+      contributions.push(this.contributions[idx].export());
74
+    }
75
+    return {
76
+      'name': this.name,
77
+      'contributors': contributors,
78
+      'contributions': contributions
79
+    };
80
+  }
81
+
82
+  this.removeContributor=function(c) {
83
+    this.contributors=this.contributors.filter(function(v){
84
+      return (v.name!=c);
85
+    });
86
+  }
87
+
88
+  this.contributorByName=function(name) {
89
+    for (c in this.contributors) {
90
+      if (this.contributors[c].name == name) return this.contributors[c];
91
+    }
92
+    return undefined;
93
+  }
94
+
95
+  this.contributorByEmail=function(email) {
96
+    for (c in this.contributors) {
97
+      if (this.contributors[c].email == email) return this.contributors[c];
98
+    }
99
+    return undefined;
100
+  }
101
+
102
+  this.contributionsByContributorName=function(name) {
103
+    var ret=[];
104
+    for (idx in this.contributions) {
105
+      if (this.contributions[idx].contributor.name==name) {
106
+        ret.push(this.contributions[idx]);
107
+      }
108
+    }
109
+    return ret;
110
+  }
111
+
112
+  this.addContribution=function(c) {
113
+    c.id=this.contributions.length;
114
+    this.contributions.push(c);
115
+  }
116
+
117
+  this.replaceContribution=function(idx,c) {
118
+    c.id=idx;
119
+    this.contributions[idx]=c;
120
+  }
121
+
122
+
123
+  this.balance=function() {
124
+    ret={}
125
+    for (idx in this.contributors) {
126
+      sum=0;
127
+      c=this.contributors[idx].name;
128
+      cl=this.contributionsByContributorName(c);
129
+      for (idc in cl) {
130
+        sum+=cl[idc].cost;
131
+      }
132
+      ret[c]=sum;
133
+    }
134
+    return ret;
135
+  }
136
+
137
+  if (jQuery.type(data)=='object') {
138
+    try {
139
+    this.name=data.name;
140
+    if (jQuery.type(data.contributors) == 'array') {
141
+      for (idx in data.contributors) {
142
+        this.contributors.push(new Contributor(
143
+          data.contributors[idx].name,
144
+          data.contributors[idx].email
145
+        ));
146
+      }
147
+    }
148
+    if (jQuery.type(data.contributions) == 'array') {
149
+      for (idx in data.contributions) {
150
+        this.contributions.push(new Contribution(
151
+          this.contributorByName(data.contributions[idx].contributor),
152
+          data.contributions[idx].cost,
153
+          data.contributions[idx].title,
154
+          data.contributions[idx].date,
155
+          idx
156
+        ));
157
+      }
158
+    }
159
+    }
160
+    catch (e) {
161
+      alert('Une erreur est survenue en chargeant le groupe '+this.name+' depuis le cache');
162
+    }
163
+  }
164
+}
165
+
166
+function Contributor(name,email) {
167
+  this.name=name;
168
+  this.email=email;
169
+  this.export=function() {
170
+    return {
171
+      'name': this.name,
172
+      'email': this.email
173
+    };
174
+  }
175
+}
176
+
177
+function Contribution(contributor,cost,title,date,id) {
178
+  this.contributor=contributor;
179
+  this.cost=cost;
180
+  this.title=title;
181
+  this.date=date;
182
+  this.id=id;
183
+  this.export=function() {
184
+    return {
185
+      'contributor': this.contributor.name,
186
+      'cost': this.cost,
187
+      'title': this.title,
188
+      'date': this.date,
189
+    };
190
+  }
191
+
192
+  this.getTitle=function() {
193
+    if (jQuery.type(this.title)=='string') {
194
+      return this.title;
195
+    }
196
+    return '';
197
+  }
198
+}
... ...
@@ -0,0 +1,296 @@
1
+<!DOCTYPE html>
2
+<html>
3
+  <head>
4
+    <title>MyCo</title>
5
+    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
6
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+    <link rel="shortcut icon" href="favicon.png">
8
+    <!-- Bootstrap -->
9
+<!-- Latest compiled and minified CSS -->
10
+<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
11
+
12
+<!-- Optional theme -->
13
+<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
14
+    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
15
+    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
16
+    <!--[if lt IE 9]>
17
+      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
18
+      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
19
+    <![endif]-->
20
+  </head>
21
+<style>
22
+body{
23
+  margin-top: 4em;
24
+}
25
+
26
+#total-label {
27
+  text-align: right;
28
+}
29
+
30
+#total-label, #total-value {
31
+  font-weight: bold;
32
+}
33
+
34
+.late {
35
+  color: red;
36
+}
37
+
38
+.hidden-part {
39
+  display: none;
40
+}
41
+
42
+#view-group h1 {
43
+  text-transform: capitalize;
44
+}
45
+</style>
46
+  <body>
47
+    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
48
+      <div class="container">
49
+        <div class="navbar-header">
50
+          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-groupe-collapse">
51
+            <span class="sr-only">Toggle navigation</span>
52
+            <span class="icon-bar"></span>
53
+            <span class="icon-bar"></span>
54
+            <span class="icon-bar"></span>
55
+          </button>
56
+          <a class="navbar-brand" href="index.html">MyCo</a>
57
+        </div>
58
+        <div class="collapse navbar-collapse"  id="navbar-groupe-collapse">
59
+          <ul class="nav navbar-nav">
60
+            <li class="dropdown">
61
+              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Groupe <b class="caret"></b></a>
62
+              <ul id="group-choice" class="dropdown-menu">
63
+                <li><a class='group-choice'>Quotidien</a></li>
64
+                <li><a class='group-choice'>Noël</a></li>
65
+                <li class="divider"></li>
66
+                <li><a href="#" id='add_group' data-toggle="modal" data-target="#add_group_modal">Nouveau</a></li>
67
+              </ul>
68
+            </li>
69
+            <li><a id='clear_local_data'>Purger les données locales</a></li>
70
+          </ul>
71
+        </div><!--/.nav-collapse -->
72
+      </div>
73
+    </div>
74
+<div class="container">
75
+
76
+<div id='view-group' class='part hidden-part'>
77
+  <h1>Noël</h1>
78
+  <form class="form-horizontal" role="form">
79
+    <div class="form-group">
80
+      <div class="input-group">
81
+        <span class="input-group-addon">Participant</span>
82
+        <select id='contributor' class="form-control">
83
+          <option value='Benjamin'>Benjamin</option>
84
+          <option value='Ludovic'>Ludovic</option>
85
+        </select>
86
+        <span class="input-group-btn">
87
+          <button type="button" class="btn btn-primary" id='edit_contributor_btn'><span class='glyphicon glyphicon-edit'></span></button>
88
+          <button type="button" class="btn btn-primary" id='del_contributor_btn'><span class='glyphicon glyphicon-trash'></span></button>
89
+          <button type="button" class="btn btn-primary" id='add_contributor_btn'><span class='glyphicon glyphicon-plus'></span></button>
90
+        </span>
91
+      </div>
92
+    </div>
93
+  </form>
94
+  <div class="btn-group">
95
+    <button id='add_contribution_btn' class="btn btn-primary"><span class='glyphicon glyphicon-plus'></span> Ajouter une dépence</span></button>
96
+    <button id='display_balance_btn' class="btn btn-info"><span class='glyphicon glyphicon-euro'></span> Balance</span></button>
97
+    <div class="btn-group">
98
+      <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
99
+        <span class="glyphicon glyphicon-cog"></span>
100
+      </button>
101
+      <ul class="dropdown-menu">
102
+        <li><a id='remove_group_btn'><span class='glyphicon glyphicon-trash'></span> Supprimer le groupe</span></a></li>
103
+      </ul>
104
+    </div>
105
+  </div>
106
+  <table id='contributions' class="table">
107
+    <thead>
108
+      <tr>
109
+        <th>Dépence</th>
110
+        <th>Coût</th>
111
+        <th>Actions</th>
112
+      </tr>
113
+    </thead>
114
+    <tbody>
115
+      <tr>
116
+        <td>Simply</td>
117
+        <td>124,56€</td>
118
+        <td>
119
+          <div class="btn-group" data-id='0'>
120
+            <button type="button" class="btn btn-default contribution_edit_btn"><span class='glyphicon glyphicon-edit'></span></button>
121
+            <button type="button" class="btn btn-default contribution_delete_btn"><span class='glyphicon glyphicon-trash'></span></button>
122
+          </div>
123
+        </td>
124
+      </tr>
125
+    </tbody>
126
+    <tfoot>
127
+      <tr>
128
+        <td id='total-label'>Total :</td>
129
+        <td id='total-value' colspan='2'>126,56€</td>
130
+      </tr>
131
+    </tfoot> 
132
+  </table>
133
+</div>
134
+
135
+<div class="modal fade" id="add_group_modal" tabindex="-1" role="dialog" aria-labelledby="addGroupModal" aria-hidden="true">
136
+  <div class="modal-dialog">
137
+    <div class="modal-content">
138
+      <div class="modal-header">
139
+        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
140
+        <h4 class="modal-title">Ajouter un groupe</h4>
141
+      </div>
142
+      <div class="modal-body">
143
+        <form class="form-horizontal" role="form">
144
+          <div class="form-group">
145
+            <div class="input-group">
146
+              <span class="input-group-addon">Nom *</span>
147
+              <input type='text' id='add_group_name' class="form-control" placeholder='Nom'/>
148
+            </div>
149
+          </div>
150
+        </form>
151
+      </div>
152
+      <div class="modal-footer">
153
+        <button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
154
+        <button type="button" class="btn btn-primary" id='add_group_submit'>Ajouter</button>
155
+      </div>
156
+    </div><!-- /.modal-content -->
157
+  </div><!-- /.modal-dialog -->
158
+</div>
159
+
160
+<div class="modal fade" id="add_contributor_modal" tabindex="-1" role="dialog" aria-labelledby="addContributorModal" aria-hidden="true">
161
+  <div class="modal-dialog">
162
+    <div class="modal-content">
163
+      <div class="modal-header">
164
+        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
165
+        <h4 class="modal-title">Ajouter un participant</h4>
166
+      </div>
167
+      <div class="modal-body">
168
+        <form class="form-horizontal" role="form">
169
+          <input type='hidden' id='group_name' />
170
+          <div class="form-group">
171
+            <div class="input-group">
172
+              <span class="input-group-addon">Nom *</span>
173
+              <input type='text' id='add_contributor_name' class="form-control" placeholder='Nom'/>
174
+            </div>
175
+          </div>
176
+          <div class="form-group">
177
+            <div class="input-group">
178
+              <span class="input-group-addon">Email *</span>
179
+              <input type='text' id='add_contributor_email' class="form-control" placeholder='Email'/>
180
+            </div>
181
+          </div>
182
+        </form>
183
+      </div>
184
+      <div class="modal-footer">
185
+        <button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
186
+        <button type="button" class="btn btn-primary" id='add_contributor_submit'>Ajouter</button>
187
+      </div>
188
+    </div><!-- /.modal-content -->
189
+  </div><!-- /.modal-dialog -->
190
+</div>
191
+
192
+
193
+<div class="modal fade" id="add_contribution_modal" tabindex="-1" role="dialog" aria-labelledby="addContributorModal" aria-hidden="true">
194
+  <div class="modal-dialog">
195
+    <div class="modal-content">
196
+      <div class="modal-header">
197
+        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
198
+        <h4 class="modal-title">Ajouter une contribution</h4>
199
+      </div>
200
+      <div class="modal-body">
201
+        <form class="form-horizontal" role="form">
202
+          <input type='hidden' id='group_name' />
203
+          <input type='hidden' id='edit_id' value='-1' />
204
+          <div class="form-group">
205
+            <div class="input-group">
206
+              <span class="input-group-addon">Participant *</span>
207
+              <select id='add_contribution_contributor_name' class="form-control"></select>
208
+            </div>
209
+          </div>
210
+          <div class="form-group">
211
+            <div class="input-group">
212
+              <span class="input-group-addon">Titre *</span>
213
+              <input type='text' id='add_contribution_title' class="form-control" placeholder='Titre'/>
214
+            </div>
215
+          </div>
216
+          <div class="form-group">
217
+            <div class="input-group">
218
+              <span class="input-group-addon">Coût *</span>
219
+              <input type='text' id='add_contribution_cost' class="form-control" placeholder='0,00'/>
220
+              <span class="input-group-addon">€</span>
221
+            </div>
222
+          </div>
223
+          <div class="form-group">
224
+            <div class="input-group">
225
+              <span class="input-group-addon">Date</span>
226
+              <input type='text' id='add_contribution_date' class="form-control" placeholder='JJ/MM/AAAA'/>
227
+            </div>
228
+          </div>
229
+        </form>
230
+      </div>
231
+      <div class="modal-footer">
232
+        <button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
233
+        <button type="button" class="btn btn-primary" id='add_contribution_submit'>Ajouter</button>
234
+      </div>
235
+    </div><!-- /.modal-content -->
236
+  </div><!-- /.modal-dialog -->
237
+</div>
238
+
239
+<div class="modal fade" id="display_balance_modal" tabindex="-1" role="dialog" aria-labelledby="displayBalanceModal" aria-hidden="true">
240
+  <div class="modal-dialog">
241
+    <div class="modal-content">
242
+      <div class="modal-header">
243
+        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
244
+        <h4 class="modal-title">Balance</h4>
245
+      </div>
246
+      <div class="modal-body">
247
+        <table class="table table-striped">
248
+          <thead>
249
+            <tr><th>Participant</th><th>Participation</th></tr>
250
+          </thead>
251
+          <tbody></tbody>
252
+          <tfoot>
253
+            <tr>
254
+              <td id='total-label'>Total :</td>
255
+              <td id='total-value'></td>
256
+            </tr>
257
+          </tfoot>
258
+        </table>
259
+      </div>
260
+      <div class="modal-footer">
261
+        <button type="button" class="btn btn-default" data-dismiss="modal">Ok</button>
262
+      </div>
263
+    </div><!-- /.modal-content -->
264
+  </div><!-- /.modal-dialog -->
265
+</div>
266
+
267
+
268
+<div class="modal fade" id="confirm_modal" tabindex="-1" role="dialog" aria-labelledby="confirmModal" aria-hidden="true">
269
+  <div class="modal-dialog">
270
+    <div class="modal-content">
271
+      <div class="modal-header">
272
+        <button type="button" class="close cancel" aria-hidden="true">&times;</button>
273
+        <h4 class="modal-title">Confirmation</h4>
274
+      </div>
275
+      <div class="modal-body">
276
+        <p id='question'></p>
277
+      </div>
278
+      <div class="modal-footer">
279
+        <button type="button" class="btn btn-default cancel">Annuler</button>
280
+        <button type="button" class="btn btn-primary" id='confirm_modal_submit'>Valider</button>
281
+      </div>
282
+    </div><!-- /.modal-content -->
283
+  </div><!-- /.modal-dialog -->
284
+</div>
285
+
286
+</div>
287
+  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
288
+  <script src="https://code.jquery.com/jquery.js"></script>
289
+  <!-- Latest compiled and minified JavaScript -->
290
+  <script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
291
+  <script src="inc/lib/moment.min.js"></script>
292
+  <script src="inc/myco_objects.js"></script>
293
+  <script src="inc/myco_confirm.js"></script>
294
+  <script src="inc/myco.js"></script>
295
+  </body>
296
+</html>
0 297