diff --git a/kfet/static/kfet/js/kpsul.min.js b/kfet/static/kfet/js/kpsul.min.js new file mode 100644 index 00000000..6e2037d8 --- /dev/null +++ b/kfet/static/kfet/js/kpsul.min.js @@ -0,0 +1 @@ +(function(){var root=typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global||this||{};var previousUnderscore=root._;var ArrayProto=Array.prototype,ObjProto=Object.prototype;var SymbolProto=typeof Symbol!=="undefined"?Symbol.prototype:null;var push=ArrayProto.push,slice=ArrayProto.slice,toString=ObjProto.toString,hasOwnProperty=ObjProto.hasOwnProperty;var nativeIsArray=Array.isArray,nativeKeys=Object.keys,nativeCreate=Object.create;var Ctor=function(){};var _=function(obj){if(obj instanceof _)return obj;if(!(this instanceof _))return new _(obj);this._wrapped=obj};if(typeof exports!="undefined"&&!exports.nodeType){if(typeof module!="undefined"&&!module.nodeType&&module.exports){exports=module.exports=_}exports._=_}else{root._=_}_.VERSION="1.9.1";var optimizeCb=function(func,context,argCount){if(context===void 0)return func;switch(argCount==null?3:argCount){case 1:return function(value){return func.call(context,value)};case 3:return function(value,index,collection){return func.call(context,value,index,collection)};case 4:return function(accumulator,value,index,collection){return func.call(context,accumulator,value,index,collection)}}return function(){return func.apply(context,arguments)}};var builtinIteratee;var cb=function(value,context,argCount){if(_.iteratee!==builtinIteratee)return _.iteratee(value,context);if(value==null)return _.identity;if(_.isFunction(value))return optimizeCb(value,context,argCount);if(_.isObject(value)&&!_.isArray(value))return _.matcher(value);return _.property(value)};_.iteratee=builtinIteratee=function(value,context){return cb(value,context,Infinity)};var restArguments=function(func,startIndex){startIndex=startIndex==null?func.length-1:+startIndex;return function(){var length=Math.max(arguments.length-startIndex,0),rest=Array(length),index=0;for(;index=0&&length<=MAX_ARRAY_INDEX};_.each=_.forEach=function(obj,iteratee,context){iteratee=optimizeCb(iteratee,context);var i,length;if(isArrayLike(obj)){for(i=0,length=obj.length;i0?0:length-1;if(!initial){memo=obj[keys?keys[index]:index];index+=dir}for(;index>=0&&index=3;return reducer(obj,optimizeCb(iteratee,context,4),memo,initial)}};_.reduce=_.foldl=_.inject=createReduce(1);_.reduceRight=_.foldr=createReduce(-1);_.find=_.detect=function(obj,predicate,context){var keyFinder=isArrayLike(obj)?_.findIndex:_.findKey;var key=keyFinder(obj,predicate,context);if(key!==void 0&&key!==-1)return obj[key]};_.filter=_.select=function(obj,predicate,context){var results=[];predicate=cb(predicate,context);_.each(obj,(function(value,index,list){if(predicate(value,index,list))results.push(value)}));return results};_.reject=function(obj,predicate,context){return _.filter(obj,_.negate(cb(predicate)),context)};_.every=_.all=function(obj,predicate,context){predicate=cb(predicate,context);var keys=!isArrayLike(obj)&&_.keys(obj),length=(keys||obj).length;for(var index=0;index=0};_.invoke=restArguments((function(obj,path,args){var contextPath,func;if(_.isFunction(path)){func=path}else if(_.isArray(path)){contextPath=path.slice(0,-1);path=path[path.length-1]}return _.map(obj,(function(context){var method=func;if(!method){if(contextPath&&contextPath.length){context=deepGet(context,contextPath)}if(context==null)return void 0;method=context[path]}return method==null?method:method.apply(context,args)}))}));_.pluck=function(obj,key){return _.map(obj,_.property(key))};_.where=function(obj,attrs){return _.filter(obj,_.matcher(attrs))};_.findWhere=function(obj,attrs){return _.find(obj,_.matcher(attrs))};_.max=function(obj,iteratee,context){var result=-Infinity,lastComputed=-Infinity,value,computed;if(iteratee==null||typeof iteratee=="number"&&typeof obj[0]!="object"&&obj!=null){obj=isArrayLike(obj)?obj:_.values(obj);for(var i=0,length=obj.length;iresult){result=value}}}else{iteratee=cb(iteratee,context);_.each(obj,(function(v,index,list){computed=iteratee(v,index,list);if(computed>lastComputed||computed===-Infinity&&result===-Infinity){result=v;lastComputed=computed}}))}return result};_.min=function(obj,iteratee,context){var result=Infinity,lastComputed=Infinity,value,computed;if(iteratee==null||typeof iteratee=="number"&&typeof obj[0]!="object"&&obj!=null){obj=isArrayLike(obj)?obj:_.values(obj);for(var i=0,length=obj.length;ib||a===void 0)return 1;if(a0?0:length-1;for(;index>=0&&index0){i=idx>=0?idx:Math.max(idx+length,i)}else{length=idx>=0?Math.min(idx+1,length):idx+length+1}}else if(sortedIndex&&idx&&length){idx=sortedIndex(array,item);return array[idx]===item?idx:-1}if(item!==item){idx=predicateFind(slice.call(array,i,length),_.isNaN);return idx>=0?idx+i:-1}for(idx=dir>0?i:length-1;idx>=0&&idxwait){if(timeout){clearTimeout(timeout);timeout=null}previous=now;result=func.apply(context,args);if(!timeout)context=args=null}else if(!timeout&&options.trailing!==false){timeout=setTimeout(later,remaining)}return result};throttled.cancel=function(){clearTimeout(timeout);previous=0;timeout=context=args=null};return throttled};_.debounce=function(func,wait,immediate){var timeout,result;var later=function(context,args){timeout=null;if(args)result=func.apply(context,args)};var debounced=restArguments((function(args){if(timeout)clearTimeout(timeout);if(immediate){var callNow=!timeout;timeout=setTimeout(later,wait);if(callNow)result=func.apply(this,args)}else{timeout=_.delay(later,wait,this,args)}return result}));debounced.cancel=function(){clearTimeout(timeout);timeout=null};return debounced};_.wrap=function(func,wrapper){return _.partial(wrapper,func)};_.negate=function(predicate){return function(){return!predicate.apply(this,arguments)}};_.compose=function(){var args=arguments;var start=args.length-1;return function(){var i=start;var result=args[start].apply(this,arguments);while(i--)result=args[i].call(this,result);return result}};_.after=function(times,func){return function(){if(--times<1){return func.apply(this,arguments)}}};_.before=function(times,func){var memo;return function(){if(--times>0){memo=func.apply(this,arguments)}if(times<=1)func=null;return memo}};_.once=_.partial(_.before,2);_.restArguments=restArguments;var hasEnumBug=!{toString:null}.propertyIsEnumerable("toString");var nonEnumerableProps=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];var collectNonEnumProps=function(obj,keys){var nonEnumIdx=nonEnumerableProps.length;var constructor=obj.constructor;var proto=_.isFunction(constructor)&&constructor.prototype||ObjProto;var prop="constructor";if(has(obj,prop)&&!_.contains(keys,prop))keys.push(prop);while(nonEnumIdx--){prop=nonEnumerableProps[nonEnumIdx];if(prop in obj&&obj[prop]!==proto[prop]&&!_.contains(keys,prop)){keys.push(prop)}}};_.keys=function(obj){if(!_.isObject(obj))return[];if(nativeKeys)return nativeKeys(obj);var keys=[];for(var key in obj)if(has(obj,key))keys.push(key);if(hasEnumBug)collectNonEnumProps(obj,keys);return keys};_.allKeys=function(obj){if(!_.isObject(obj))return[];var keys=[];for(var key in obj)keys.push(key);if(hasEnumBug)collectNonEnumProps(obj,keys);return keys};_.values=function(obj){var keys=_.keys(obj);var length=keys.length;var values=Array(length);for(var i=0;i1)iteratee=optimizeCb(iteratee,keys[1]);keys=_.allKeys(obj)}else{iteratee=keyInObj;keys=flatten(keys,false,false);obj=Object(obj)}for(var i=0,length=keys.length;i1)context=keys[1]}else{keys=_.map(flatten(keys,false,false),String);iteratee=function(value,key){return!_.contains(keys,key)}}return _.pick(obj,iteratee,context)}));_.defaults=createAssigner(_.allKeys,true);_.create=function(prototype,props){var result=baseCreate(prototype);if(props)_.extendOwn(result,props);return result};_.clone=function(obj){if(!_.isObject(obj))return obj;return _.isArray(obj)?obj.slice():_.extend({},obj)};_.tap=function(obj,interceptor){interceptor(obj);return obj};_.isMatch=function(object,attrs){var keys=_.keys(attrs),length=keys.length;if(object==null)return!length;var obj=Object(object);for(var i=0;i":">",'"':""","'":"'","`":"`"};var unescapeMap=_.invert(escapeMap);var createEscaper=function(map){var escaper=function(match){return map[match]};var source="(?:"+_.keys(map).join("|")+")";var testRegexp=RegExp(source);var replaceRegexp=RegExp(source,"g");return function(string){string=string==null?"":""+string;return testRegexp.test(string)?string.replace(replaceRegexp,escaper):string}};_.escape=createEscaper(escapeMap);_.unescape=createEscaper(unescapeMap);_.result=function(obj,path,fallback){if(!_.isArray(path))path=[path];var length=path.length;if(!length){return _.isFunction(fallback)?fallback.call(obj):fallback}for(var i=0;i/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var noMatch=/(.)^/;var escapes={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"};var escapeRegExp=/\\|'|\r|\n|\u2028|\u2029/g;var escapeChar=function(match){return"\\"+escapes[match]};_.template=function(text,settings,oldSettings){if(!settings&&oldSettings)settings=oldSettings;settings=_.defaults({},settings,_.templateSettings);var matcher=RegExp([(settings.escape||noMatch).source,(settings.interpolate||noMatch).source,(settings.evaluate||noMatch).source].join("|")+"|$","g");var index=0;var source="__p+='";text.replace(matcher,(function(match,escape,interpolate,evaluate,offset){source+=text.slice(index,offset).replace(escapeRegExp,escapeChar);index=offset+match.length;if(escape){source+="'+\n((__t=("+escape+"))==null?'':_.escape(__t))+\n'"}else if(interpolate){source+="'+\n((__t=("+interpolate+"))==null?'':__t)+\n'"}else if(evaluate){source+="';\n"+evaluate+"\n__p+='"}return match}));source+="';\n";if(!settings.variable)source="with(obj||{}){\n"+source+"}\n";source="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+source+"return __p;\n";var render;try{render=new Function(settings.variable||"obj","_",source)}catch(e){e.source=source;throw e}var template=function(data){return render.call(this,data,_)};var argument=settings.variable||"obj";template.source="function("+argument+"){\n"+source+"}";return template};_.chain=function(obj){var instance=_(obj);instance._chain=true;return instance};var chainResult=function(instance,obj){return instance._chain?_(obj).chain():obj};_.mixin=function(obj){_.each(_.functions(obj),(function(name){var func=_[name]=obj[name];_.prototype[name]=function(){var args=[this._wrapped];push.apply(args,arguments);return chainResult(this,func.apply(_,args))}}));return _};_.mixin(_);_.each(["pop","push","reverse","shift","sort","splice","unshift"],(function(name){var method=ArrayProto[name];_.prototype[name]=function(){var obj=this._wrapped;method.apply(obj,arguments);if((name==="shift"||name==="splice")&&obj.length===0)delete obj[0];return chainResult(this,obj)}}));_.each(["concat","join","slice"],(function(name){var method=ArrayProto[name];_.prototype[name]=function(){return chainResult(this,method.apply(this._wrapped,arguments))}}));_.prototype.value=function(){return this._wrapped};_.prototype.valueOf=_.prototype.toJSON=_.prototype.value;_.prototype.toString=function(){return String(this._wrapped)};if(typeof define=="function"&&define.amd){define("underscore",[],(function(){return _}))}})();(function(factory){var root=typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;if(typeof define==="function"&&define.amd){define(["underscore","jquery","exports"],(function(_,$,exports){root.Backbone=factory(root,exports,_,$)}))}else if(typeof exports!=="undefined"){var _=require("underscore"),$;try{$=require("jquery")}catch(e){}factory(root,exports,_,$)}else{root.Backbone=factory(root,{},root._,root.jQuery||root.Zepto||root.ender||root.$)}})((function(root,Backbone,_,$){var previousBackbone=root.Backbone;var slice=Array.prototype.slice;Backbone.VERSION="1.4.0";Backbone.$=$;Backbone.noConflict=function(){root.Backbone=previousBackbone;return this};Backbone.emulateHTTP=false;Backbone.emulateJSON=false;var Events=Backbone.Events={};var eventSplitter=/\s+/;var _listening;var eventsApi=function(iteratee,events,name,callback,opts){var i=0,names;if(name&&typeof name==="object"){if(callback!==void 0&&"context"in opts&&opts.context===void 0)opts.context=callback;for(names=_.keys(name);ithis.length)at=this.length;if(at<0)at+=this.length+1;var set=[];var toAdd=[];var toMerge=[];var toRemove=[];var modelMap={};var add=options.add;var merge=options.merge;var remove=options.remove;var sort=false;var sortable=this.comparator&&at==null&&options.sort!==false;var sortAttr=_.isString(this.comparator)?this.comparator:null;var model,i;for(i=0;i7);this._useHashChange=this._wantsHashChange&&this._hasHashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.history&&this.history.pushState);this._usePushState=this._wantsPushState&&this._hasPushState;this.fragment=this.getFragment();this.root=("/"+this.root+"/").replace(rootStripper,"/");if(this._wantsHashChange&&this._wantsPushState){if(!this._hasPushState&&!this.atRoot()){var rootPath=this.root.slice(0,-1)||"/";this.location.replace(rootPath+"#"+this.getPath());return true}else if(this._hasPushState&&this.atRoot()){this.navigate(this.getHash(),{replace:true})}}if(!this._hasHashChange&&this._wantsHashChange&&!this._usePushState){this.iframe=document.createElement("iframe");this.iframe.src="javascript:0";this.iframe.style.display="none";this.iframe.tabIndex=-1;var body=document.body;var iWindow=body.insertBefore(this.iframe,body.firstChild).contentWindow;iWindow.document.open();iWindow.document.close();iWindow.location.hash="#"+this.fragment}var addEventListener=window.addEventListener||function(eventName,listener){return attachEvent("on"+eventName,listener)};if(this._usePushState){addEventListener("popstate",this.checkUrl,false)}else if(this._useHashChange&&!this.iframe){addEventListener("hashchange",this.checkUrl,false)}else if(this._wantsHashChange){this._checkUrlInterval=setInterval(this.checkUrl,this.interval)}if(!this.options.silent)return this.loadUrl()},stop:function(){var removeEventListener=window.removeEventListener||function(eventName,listener){return detachEvent("on"+eventName,listener)};if(this._usePushState){removeEventListener("popstate",this.checkUrl,false)}else if(this._useHashChange&&!this.iframe){removeEventListener("hashchange",this.checkUrl,false)}if(this.iframe){document.body.removeChild(this.iframe);this.iframe=null}if(this._checkUrlInterval)clearInterval(this._checkUrlInterval);History.started=false},route:function(route,callback){this.handlers.unshift({route:route,callback:callback})},checkUrl:function(e){var current=this.getFragment();if(current===this.fragment&&this.iframe){current=this.getHash(this.iframe.contentWindow)}if(current===this.fragment)return false;if(this.iframe)this.navigate(current);this.loadUrl()},loadUrl:function(fragment){if(!this.matchRoot())return false;fragment=this.fragment=this.getFragment(fragment);return _.some(this.handlers,(function(handler){if(handler.route.test(fragment)){handler.callback(fragment);return true}}))},navigate:function(fragment,options){if(!History.started)return false;if(!options||options===true)options={trigger:!!options};fragment=this.getFragment(fragment||"");var rootPath=this.root;if(fragment===""||fragment.charAt(0)==="?"){rootPath=rootPath.slice(0,-1)||"/"}var url=rootPath+fragment;fragment=fragment.replace(pathStripper,"");var decodedFragment=this.decodeFragment(fragment);if(this.fragment===decodedFragment)return;this.fragment=decodedFragment;if(this._usePushState){this.history[options.replace?"replaceState":"pushState"]({},document.title,url)}else if(this._wantsHashChange){this._updateHash(this.location,fragment,options.replace);if(this.iframe&&fragment!==this.getHash(this.iframe.contentWindow)){var iWindow=this.iframe.contentWindow;if(!options.replace){iWindow.document.open();iWindow.document.close()}this._updateHash(iWindow.location,fragment,options.replace)}}else{return this.location.assign(url)}if(options.trigger)return this.loadUrl(fragment)},_updateHash:function(location,fragment,replace){if(replace){var href=location.href.replace(/(javascript:|#).*$/,"");location.replace(href+"#"+fragment)}else{location.hash="#"+fragment}}});Backbone.history=new History;var extend=function(protoProps,staticProps){var parent=this;var child;if(protoProps&&_.has(protoProps,"constructor")){child=protoProps.constructor}else{child=function(){return parent.apply(this,arguments)}}_.extend(child,parent,staticProps);child.prototype=_.create(parent.prototype,protoProps);child.prototype.constructor=child;child.__super__=parent.prototype;return child};Model.extend=Collection.extend=Router.extend=View.extend=History.extend=extend;var urlError=function(){throw new Error('A "url" property or function must be specified')};var wrapError=function(model,options){var error=options.error;options.error=function(resp){if(error)error.call(options.context,model,resp,options);model.trigger("error",model,resp,options)}};return Backbone}));var Account=Backbone.Model.extend({defaults:{id:0,name:"",email:"",is_cof:"",promo:"",balance:"",is_frozen:false,departement:"",nickname:""},url:function(){return django_urls["kfet.account.read.json"](encodeURIComponent(this.get("trigramme")))},reset:function(){this.set(this.defaults)},parse:function(resp,options){if(_.has(resp,"balance")){return _.extend(resp,{balance:parseFloat(resp.balance)})}else{return resp}},view:function(){var view_class;if(!this.is_empty_account()){view_class=EmptyAccountView}else if(this.get("trigramme")=="LIQ"){view_class=LIQView}else{view_class=AccountView}return new view_class({model:this})},render:function(){this.view().render()},is_empty_account:function(){return this.id!=0}});var AccountView=Backbone.View.extend({el:"#account",buttons:".buttons",id_field:"#id_on_acc",props:_.keys(Account.prototype.defaults),get:function(property){var getter_name=`get_${property}`;if(_.functions(this).includes(getter_name))return this[getter_name]();else return this.model.get(property)},get_is_cof:function(){return this.model.get("is_cof")?"COF":"Non-COF"},get_balance:function(){return amountToUKF(this.model.get("balance"),this.model.get("is_cof"),true)},attr_data_balance:function(){if(this.model.get("balance")<0){return"neg"}else if(this.model.get("balance")<=5){return"low"}else{return"ok"}},get_buttons:function(){var url=django_urls["kfet.account.read"](this.model.get("trigramme"));return``},render:function(){for(let prop of this.props){var selector="#account-"+prop;this.$(selector).text(this.get(prop))}this.$el.attr("data-balance",this.attr_data_balance());this.$(this.buttons).html(this.get_buttons());$(this.id_field).val(this.get("id"))}});var LIQView=AccountView.extend({get_balance:function(){return""},attr_data_balance:function(){return"ok"}});var EmptyAccountView=AccountView.extend({get:function(){return""},attr_data_balance:function(){return""},get_buttons:function(){var buttons='';var trigramme=this.model.get("trigramme");if(trigramme.is_valid_trigramme()){trigramme=encodeURIComponent(trigramme);var url_base=django_urls["kfet.account.create"]();var url=`${url_base}?trigramme=${trigramme}`;buttons+=``}return buttons}});class AccountManager{constructor(){this._$input=$("#id_trigramme");this._$container=$("#account");this._$article_select=$("#article_autocomplete");this.account=new Account({trigramme:""});this.search=new AccountSearch(this);this._init_events()}get data(){return this.account.toJSON()}_init_events(){var that=this;this._$input.on("input",()=>this.update());this._$input.on("keydown",(function(e){if(e.key=="ArrowDown"){that.set("LIQ")}}));this._$container.on("click",".search",(function(){that.search.open()}));this._$container.on("keydown",(function(e){if(e.key=="f"&&e.ctrlKey){that.search.open();e.preventDefault()}}))}set(trigramme){this._$input.val(trigramme);this.update()}update(){var trigramme=this._$input.val().format_trigramme();this.account.set({trigramme:trigramme});if(trigramme.is_valid_trigramme()){this.account.fetch({success:this._on_success.bind(this),error:this.reset.bind(this,false)})}else{this.reset()}}_on_success(){this.account.render();this._$article_select.focus();window.updateBasketAmount();window.updateBasketRel()}reset(hard_reset=false){this.account.reset();this.account.render();if(hard_reset){this._$input.val("");this.update()}}}class AccountSearch{constructor(manager){this.manager=manager;this._content='
';this._input="#search_autocomplete";this._results_container="#account_results"}open(){var that=this;this._$dialog=$.dialog({title:"Recherche de compte",content:this._content,backgroundDismiss:true,animation:"top",closeAnimation:"bottom",keyboardEnabled:true,onOpen:function(){that._$input=$(that._input);that._$results_container=$(that._results_container);that._init_form()._init_events()}})}_init_form(){var that=this;this._$input.yourlabsAutocomplete({url:django_urls["kfet.account.search.autocomplete"](),minimumCharacters:2,id:"search_autocomplete",choiceSelector:".autocomplete-value",placeholder:"Chercher un utilisateur K-Fêt",container:that._$results_container,box:that._$results_container,fixPosition:function(){}});return this}_init_events(){this._$input.bind("selectChoice",(e,choice,autocomplete)=>this._on_select(e,choice,autocomplete));return this}_on_select(e,choice,autocomplete){var choice_text=choice.text().trim();var trigramme_regex=/\((.{3})\)$/;var trigramme=choice_text.match(trigramme_regex)[1];this.manager.set(trigramme);this.close()}close(){if(this._$dialog!==undefined){this._$dialog.close()}}}$((function(){self.account_manager=new AccountManager})); \ No newline at end of file diff --git a/kfet/static/kfet/src/kpsul/Makefile b/kfet/static/kfet/src/kpsul/Makefile new file mode 100644 index 00000000..0100549f --- /dev/null +++ b/kfet/static/kfet/src/kpsul/Makefile @@ -0,0 +1,28 @@ +# Compilation des fichiers .js de K-Psul en une version minifiée + +LIBS = libs/underscore.js libs/backbone.js +MODELS = $(wildcard models/**.js) +MANAGERS = $(wildcard managers/**.js) +ENTRYPOINT = kpsul.js + +CONCAT_FILE = kpsul.src.js +TARGET = ../../js/kpsul.min.js + +FLAGS = + + +build: concat minify clean +# For dev use : we don't minify +dev: concat cp clean + +concat: + @cat $(LIBS) $(MODELS) $(MANAGERS) $(ENTRYPOINT) > $(CONCAT_FILE) + +cp: + @cp $(CONCAT_FILE) $(TARGET) + +minify: + terser $(CONCAT_FILE) -o $(TARGET) $(FLAGS) + +clean: + @rm $(CONCAT_FILE) \ No newline at end of file diff --git a/kfet/static/kfet/src/kpsul/kpsul.js b/kfet/static/kfet/src/kpsul/kpsul.js new file mode 100644 index 00000000..e88f4282 --- /dev/null +++ b/kfet/static/kfet/src/kpsul/kpsul.js @@ -0,0 +1,3 @@ +$(function () { + self.account_manager = new AccountManager(); +}) \ No newline at end of file diff --git a/kfet/static/kfet/src/backbone.js b/kfet/static/kfet/src/kpsul/libs/backbone.js similarity index 100% rename from kfet/static/kfet/src/backbone.js rename to kfet/static/kfet/src/kpsul/libs/backbone.js diff --git a/kfet/static/kfet/src/underscore.js b/kfet/static/kfet/src/kpsul/libs/underscore.js similarity index 100% rename from kfet/static/kfet/src/underscore.js rename to kfet/static/kfet/src/kpsul/libs/underscore.js diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/src/kpsul/managers/account_manager.js similarity index 98% rename from kfet/static/kfet/js/kpsul.js rename to kfet/static/kfet/src/kpsul/managers/account_manager.js index a1ac8d37..3ee556a3 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/src/kpsul/managers/account_manager.js @@ -141,7 +141,7 @@ class AccountSearch { var choice_text = choice.text().trim(); var trigramme_regex = /\((.{3})\)$/; // le match est de la forme [, ] - trigramme = choice_text.match(trigramme_regex)[1] + var trigramme = choice_text.match(trigramme_regex)[1] this.manager.set(trigramme); this.close(); } @@ -151,4 +151,4 @@ class AccountSearch { this._$dialog.close(); } } -} +} \ No newline at end of file diff --git a/kfet/static/kfet/js/account.js b/kfet/static/kfet/src/kpsul/models/account.js similarity index 93% rename from kfet/static/kfet/js/account.js rename to kfet/static/kfet/src/kpsul/models/account.js index 07fd6688..8f5d7e6c 100644 --- a/kfet/static/kfet/js/account.js +++ b/kfet/static/kfet/src/kpsul/models/account.js @@ -31,6 +31,7 @@ var Account = Backbone.Model.extend({ }, view: function () { + var view_class; if (this.is_empty_account()) { view_class = EmptyAccountView } else if (this.get("trigramme") == 'LIQ') { @@ -61,7 +62,7 @@ var AccountView = Backbone.View.extend({ get: function (property) { /* If the function this.get_ is defined, we call it ; else we call this.model.. */ - getter_name = `get_${property}`; + var getter_name = `get_${property}`; if (_.functions(this).includes(getter_name)) return this[getter_name]() else @@ -131,8 +132,8 @@ var EmptyAccountView = AccountView.extend({ /* Léger changement de fonctionnement : on affiche *toujours* le bouton de recherche si le compte est invalide */ - buttons = ''; - trigramme = this.model.get("trigramme") + var buttons = ''; + var trigramme = this.model.get("trigramme") if (trigramme.is_valid_trigramme()) { trigramme = encodeURIComponent(trigramme); var url_base = django_urls["kfet.account.create"](); @@ -142,4 +143,4 @@ var EmptyAccountView = AccountView.extend({ return buttons } -}) \ No newline at end of file +}) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 03ade3c6..4fb90ce2 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -7,10 +7,7 @@ - - - - + {% endblock %} {% block title %}K-Psul{% endblock %} @@ -209,12 +206,7 @@ $(document).ready(function() { }); } - - // ----- - // Account data management - // ----- - - var account_manager = new AccountManager(); + var triInput = $('#id_trigramme');