123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- //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){
-
- if(element){
- var li = $(element).closest('li');
- var data = {
- 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')
- }
- }else{
- var data = $('#part-form').toJson();
- }
- data.action = 'part_part_save';
- $.action(data,function(r){
- if(element){
- li.removeClass('edition');
- 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').addClass('edition');
- 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);
- });
- }
|