|
@@ -0,0 +1,266 @@
|
|
|
+//CHARGEMENT DE LA PAGE
|
|
|
+function init_plugin_part(){
|
|
|
+ switch($.urlParam('page')){
|
|
|
+ case 'list.part':
|
|
|
+ part_part_search();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ part_part_search();
|
|
|
+
|
|
|
+
|
|
|
+ $('#parts').sortable_table({
|
|
|
+ onSort : part_part_search
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//Enregistrement des configurations
|
|
|
+function part_setting_save(){
|
|
|
+ $.action({
|
|
|
+ action : 'part_setting_save',
|
|
|
+ fields : $('#part-setting-form').toJson()
|
|
|
+ },function(){ $.message('info','Configuration enregistrée'); });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/** PART **/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//Récuperation d'une liste de part dans le tableau #parts
|
|
|
+function part_resource_part_search(callback){
|
|
|
+
|
|
|
+ $('#parts').fill({
|
|
|
+ action:'part_resource_part_search',
|
|
|
+ resource : $('#sketch-editor').attr('data-id'),
|
|
|
+ showing : function(li,i){
|
|
|
+ li.css('transform','scale(0)').removeClass('hidden');
|
|
|
+ setTimeout(function(){
|
|
|
+ li.css('transform','scale(1)');
|
|
|
+ },i*200);
|
|
|
+ }
|
|
|
+ },function(){
|
|
|
+ $('#parts li:not(:eq(0))').each(function(i,li){
|
|
|
+ part_resource_part_upload(li);
|
|
|
+ var div = $('[data-stream]',li);
|
|
|
+ if($(div).attr('data-stream') =='') return;
|
|
|
+ $(div).css('background','url(data:'+$(div).attr('data-stream')+')')
|
|
|
+ .css('background-size','cover');
|
|
|
+ });
|
|
|
+
|
|
|
+ if(callback!=null) callback();
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//Récuperation d'une liste de part dans le tableau #parts
|
|
|
+function part_part_search(callback){
|
|
|
+
|
|
|
+
|
|
|
+ $('#parts').fill({
|
|
|
+ action:'part_part_search',
|
|
|
+ resource : $('#sketch-editor').attr('data-id'),
|
|
|
+ },function(){
|
|
|
+ $('#parts li:not(:eq(0))').each(function(i,li){
|
|
|
+
|
|
|
+ part_resource_part_upload(li);
|
|
|
+
|
|
|
+ var div = $('[data-stream]',li);
|
|
|
+
|
|
|
+ if($(div).attr('data-stream') =='') return;
|
|
|
+ $(div).css('background','url(data:'+$(div).attr('data-stream')+')')
|
|
|
+ .css('background-size','cover');
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $('#parts li:not(:eq(0))').css('transform','scale(0)').removeClass('hidden')
|
|
|
+
|
|
|
+ $('#parts li:not(:eq(0))').each(function(i,li){
|
|
|
+ var li = $(li);
|
|
|
+ setTimeout(function(){
|
|
|
+ li.css('transform','scale(1)');
|
|
|
+ },i*200);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(callback!=null) callback();
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+//Ajout ou modification d'élément part
|
|
|
+function part_part_save(element){
|
|
|
+ var li = $(element).closest('li');
|
|
|
+
|
|
|
+ var data = {
|
|
|
+ action : 'part_part_save',
|
|
|
+ resource : $('#sketch-editor').attr('data-id'),
|
|
|
+ part : li.attr('data-part'),
|
|
|
+ id : li.attr('data-id'),
|
|
|
+ label : li.find('.label').val(),
|
|
|
+ brand : li.find('.brand input').val(),
|
|
|
+ price : li.find('.price input').val(),
|
|
|
+ url : li.find('.url').val(),
|
|
|
+ picture : li.find('.part-image').attr('data-stream')
|
|
|
+ }
|
|
|
+ $.action(data,function(r){
|
|
|
+
|
|
|
+ li.attr('data-part',r.part);
|
|
|
+ li.attr('data-id',r.id)
|
|
|
+ $.message('success','Enregistré');
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function part_part_find(element){
|
|
|
+ var li = $(element).closest('li');
|
|
|
+ var label = li.find('.label').val();
|
|
|
+ var brand = li.find('.brand input').val();
|
|
|
+ var url = "https://www.ebay.fr/sch/i.html?_from=R40&_sacat=0&LH_BIN=1&LH_PrefLoc=2&_sop=15";
|
|
|
+ if(null!=brand && brand !='') label = brand+'+'+label;
|
|
|
+ url += "&_nkw="+label;
|
|
|
+ window.open(url);
|
|
|
+}
|
|
|
+
|
|
|
+function part_part_add(){
|
|
|
+
|
|
|
+ var tpl = $('#parts li:eq(0)').get(0).outerHTML;
|
|
|
+
|
|
|
+ var data = {
|
|
|
+ price : 1,
|
|
|
+ url : 'http://ebay.com'
|
|
|
+ }
|
|
|
+ var item = $(Mustache.render(tpl,data));
|
|
|
+ item.removeClass('hidden');
|
|
|
+ item.css({
|
|
|
+ transform : 'scale(0)',
|
|
|
+ opacity : 0,
|
|
|
+ });
|
|
|
+ $('#parts li:eq(0)').after(item);
|
|
|
+
|
|
|
+ item.css({
|
|
|
+ transform : 'scale(1) rotate(0deg)',
|
|
|
+ opacity : 1,
|
|
|
+ });
|
|
|
+
|
|
|
+ init_components(item);
|
|
|
+
|
|
|
+ part_resource_part_upload(item);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function part_resource_part_upload(item){
|
|
|
+ var item = $(item);
|
|
|
+ var image = item.find('.part-image');
|
|
|
+ image.click(function(e){
|
|
|
+ e.preventDefault();
|
|
|
+ e.stopPropagation();
|
|
|
+ var picker = image.next('input[type="file"]');
|
|
|
+ picker.trigger('click');
|
|
|
+ picker.change(function(){
|
|
|
+ var file = picker.get(0).files[0];
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.addEventListener("load", function () {
|
|
|
+
|
|
|
+ image.css('background','url('+reader.result+')')
|
|
|
+ .attr('data-stream',reader.result)
|
|
|
+ .css('background-size','cover');
|
|
|
+ }, false);
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ image.on('drag dragstart dragend dragover dragenter dragleave drop', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ e.stopPropagation();
|
|
|
+ })
|
|
|
+ image.on('drop', function (e) {
|
|
|
+ var droppedFiles = e.originalEvent.dataTransfer.files;
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.readAsDataURL(droppedFiles[0]);
|
|
|
+ reader.onload = function () {
|
|
|
+
|
|
|
+ image.css('background','url('+reader.result+')')
|
|
|
+ .attr('data-stream',reader.result)
|
|
|
+ .css('background-size','cover');
|
|
|
+ };
|
|
|
+ reader.onerror = function (error) {
|
|
|
+ console.log('Error: ', error);
|
|
|
+ };
|
|
|
+
|
|
|
+ });
|
|
|
+ /*
|
|
|
+ var preload = $('<div class="preload progress-bar progress-bar-striped progress-bar-animated"></div>');
|
|
|
+ item.find('.part-image').append(preload);
|
|
|
+ item.find('.part-image').attr('id','part-image-'+$('#parts li').length());
|
|
|
+ item.find('.part-image').upload({
|
|
|
+ allowed : 'jpg,png,jpeg,bmp,svg',
|
|
|
+ size : 0,
|
|
|
+ action : 'part_part_image_upload',
|
|
|
+ readonly: false,
|
|
|
+ start: function(){
|
|
|
+ preload.show();
|
|
|
+ },
|
|
|
+ success: function(response){
|
|
|
+ if(response.previews.length && response.previews[0].name) {
|
|
|
+
|
|
|
+ }
|
|
|
+ console.log(response);
|
|
|
+ preload.fadeOut();
|
|
|
+ },
|
|
|
+ complete: function(){
|
|
|
+ preload.fadeOut();
|
|
|
+ }
|
|
|
+ });*/
|
|
|
+}
|
|
|
+
|
|
|
+//Suppression d'élement part
|
|
|
+function part_resource_part_delete(element){
|
|
|
+ if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
|
|
|
+ var line = $(element).closest('li');
|
|
|
+
|
|
|
+ if(line.attr('data-id')==''){
|
|
|
+ line.css('transform','scale(0)');
|
|
|
+ setTimeout(function(){
|
|
|
+ line.remove()
|
|
|
+ },210);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $.action({
|
|
|
+ action : 'part_resource_part_delete',
|
|
|
+ id : line.attr('data-id')
|
|
|
+ },function(r){
|
|
|
+ line.css('transform','scale(0)');
|
|
|
+ setTimeout(function(){
|
|
|
+ line.remove()
|
|
|
+ },210);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+//Suppression d'élement part
|
|
|
+function part_part_delete(element){
|
|
|
+ if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
|
|
|
+ var line = $(element).closest('li');
|
|
|
+
|
|
|
+ if(line.attr('data-id')==''){
|
|
|
+ line.css('transform','scale(0)');
|
|
|
+ setTimeout(function(){
|
|
|
+ line.remove()
|
|
|
+ },210);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $.action({
|
|
|
+ action : 'part_part_delete',
|
|
|
+ id : line.attr('data-id')
|
|
|
+ },function(r){
|
|
|
+ line.css('transform','scale(0)');
|
|
|
+ setTimeout(function(){
|
|
|
+ line.remove()
|
|
|
+ },210);
|
|
|
+ });
|
|
|
+}
|