123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- $(document).ready(function(){
- if($.urlParam('embeded') =="1"){
- $('.navbar,.resources-options,#sketch').hide();
- $('.container-fluid,.col-md-9,.col-md-3').css('padding','0');
- $('.list-group-item,#resource').css('padding','3px').css('border-radius','0px');
- $('.jumbotron').css('border-radius','0');
- $('.row').css('margin','0');
- $('#resources').before('<div style="width:100%;border-radius:0px;" onclick="'+$('#download').attr('onclick')+'" class="btn btn-success" ><i class="fa fa-arrow-circle-o-down"></i> Télécharger</div>');
- $('.col-md-3,.col-md-9').attr('style','width:20%;float:left;padding:0;');
- $('.col-md-9').attr('style','width:70%;float:left;padding:0;');
- }
- if($.urlParam('sidebar') =="0"){
- $('#resourceMenu').hide();
- $('#resourceContent').removeClass('col-md-9').addClass('col-md-12');
- }
- var init = 'init_'+$.page();
- if(window[init]!=null) window[init]();
- if($.page()=='' ) init_index();
-
- Dropzone.autoDiscover = false;
- });
- function init_index(){
- search_sketch();
- $('#label').enter(function(){
- create_sketch();
- });
-
- $('#importJsonSketch').dropzone({
- url : 'action.php?action=import_sketch',
- complete : function(useless){
-
- if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
- search_sketch();
- }
- },
- success: function(file, response){
- if(response.errors.length>0) alert(response.errors.join(','));
- },
- sending : function(file, xhr, formData){
- formData.append('from','file');
- }
- });
- }
- //COMPONENT
- function init_component(){
- search_component();
- /*
- $('#imageUpload').upzone({
- url : 'action.php?action=upload_component_image',
- id : $('#sketch').attr('data-id'),
- success : function(server){
- $('#imageUpload').attr('src',server);
- }
- });
- */
- $('#imageUpload').dropzone({
- url : 'action.php?action=upload_component_image',
- success : function(useless,server){
- if(server.error != null)
- return alert(server.error);
-
- $('#imageUpload').attr('src',server.thumb);
-
- },
- sending : function(file, xhr, formData){
- formData.append('id', $('#sketch').attr('data-id'));
- }
- });
-
- $('#label').autocomplete({
- source : 'http://hack.idleman.fr/action.php?action=find_component',
- minLength: 4,
- select: function( event, ui ) {
-
- $.setForm('#editComponent',ui.item.value);
- $('#imageUpload').attr('src',ui.item.value.image);
- return false;
- }
- }).data("uiAutocomplete")._renderItem = function (ul, item) {
-
- return $("<li />")
- .data("item.autocomplete", item)
- .append("<a><img style='height:50px;width:auto;' src='" + item.value.image + "' /> " + item.label + "</a>")
- .appendTo(ul);
- };
-
-
- };
- function save_component(){
- var data = $.getForm('#editComponent');
-
- if($('#imageUpload').attr('src').substring(0,10)=='data:image')
- data.image = $('#imageUpload').attr('src');
-
- $.action(data,function(r){
- search_component();
- });
- }
- function search_component(){
- $('#components').fill({action:'search_component'});
- }
- function edit_component(element){
- var data = {action : 'edit_component'};
- $('#editComponent input').val('');
- $('#imageUpload').attr('src','img/default_image.png');
- if(element!=null){
- var line = $(element).closest('tr');
- data.id = line.attr('data-id');
- }
-
- $.action(data,function(r){
- $('#editComponent').modal('show');
- $.setForm('#editComponent',r);
- $('#imageUpload').attr('src',r.image);
- $('#editComponent').attr('data-id',r.id);
- });
- }
- function delete_component(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer ça?')) return;
- var line = $(element).closest('tr');
- $.action({action : 'delete_component',id : line.attr('data-id')},function(r){
- line.remove();
- });
- }
- //SKETCH
- function init_sketch(){
- search_resources(function(){
- var resource = $.hashData('resource');
- resource = resource == '' ? $('#resources a:visible():eq(1)').attr('data-id') : resource;
- select_resource(resource);
- });
-
-
-
- $('#importResource i').dropzone({
- url : 'action.php?action=import_resource',
- complete : function(useless,server){
- if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
- search_resources();
- }
- },
- sending : function(file, xhr, formData){
- formData.append('id', $('#sketch').attr('data-id'));
- }
- });
- }
- function search_sketch(){
- $('#sketchs').fill({action:'search_sketch'});
- }
- function create_sketch(){
- $.action($.getForm('#editSketch'),function(r){
- window.location = 'sketch.php?id='+r.id;
- });
- }
- function import_sketch(){
- var data = $.getForm('#importSketch');
- data.from = 'url';
- $.action(data,function(){
- search_sketch();
- });
- }
- function delete_sketch(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer ça?')) return;
- var line = $(element).closest('tr');
- $.action({action : 'delete_sketch',id : line.attr('data-id')},function(r){
- line.remove();
- });
- }
- function save_sketch_title(element){
- $.action({action : 'save_sketch_title',label : $(element).val(),id:$('#sketch').attr('data-id')});
- }
- function toggle_share_sketch(element){
- var button = $(element).find('i');
- var nextState = !button.hasClass('fa-eye');
- $.action({action:'toggle_share_sketch',state:(nextState?1:0),id:$('#sketch').attr('data-id')},function(){
- button.removeClass('fa-eye').removeClass('fa-eye-slash');
- button.addClass((nextState?'fa-eye':'fa-eye-slash'));
- $(element).attr('title','Rendre '+(nextState?'Privé':'Public'));
- });
- }
- function toggle_embed_sketch(){
- $('#embedModal').modal('show');
- get_embeded_code();
-
- }
- function get_embeded_code(){
- var url = window.location.protocol+'//'+window.location.host+window.location.pathname+window.location.search;
- url+= '&embeded=1';
- if(!$('#enableSideBar').prop('checked'))
- url+= '&sidebar=0';
-
- url+= window.location.hash;
-
- var html = '<a href="'+window.location+'"><small>Voir en taille réelle<small></a><br/>';
- html += '<iframe frameborder="0" width="100%" align="center" height="400px" src="'+url+'"></iframe>';
- $('#embedModal textarea').val(html);
-
- $("#embedModal textarea").focus(function() {
- var $this = $(this);
- $this.select();
- $this.mouseup(function() {
- $this.unbind("mouseup");
- return false;
- });
- });
- }
- //RESOURCE
- function add_resource(selected){
- $('#resources a').removeClass('active');
- $('#editResourceMeta').modal('show');
- if(selected!=null) $('#editResourceMeta select').val(selected);
- $('#label').val('').focus();
- $('#resource').attr('data-id','');
- }
- function save_resource(){
- var data = $.getForm('#editResourceMeta');
- data.sketch = $('#sketch').attr('data-id');
-
- $.action(data,function(r){
- $('#editResourceMeta input').val('');
- $('#editResourceMeta').attr('data-id','');
- search_resources(select_resource(r.id));
- });
- }
- function search_resources(callback){
- var id = $('#sketch').attr('data-id');
- $('#resources').fill({id:id,action:'search_resources'},function(){
- if(callback!=null) callback();
- });
- }
- function edit_resource(element,event){
- event.stopPropagation();
- var line = $(element).closest('a');
-
- $.action({action:'edit_resource',id:line.attr('data-id')},function(r){
- $('#editResourceMeta').modal('show');
- $.setForm('#editResourceMeta',r);
-
- $('#editResourceMeta').attr('data-id',r.id);
- });
- }
- function delete_resource(element,event){
- event.stopPropagation();
- if(!confirm('Êtes vous sûr de vouloir supprimer ça?')) return;
- var line = $(element).closest('a');
- $.action({action : 'delete_resource',id : line.attr('data-id')},function(r){
- line.remove();
- });
- }
- function select_resource(id){
- $.hashData({resource:id});
- load_resource();
- }
- function load_resource(){
- var id = $.hashData('resource');
-
- var line = $('[data-id="'+id+'"]');
- if(line.attr('data-id')==null) return;
- $('.preloader').show();
- $('#resource p').html('');
-
-
- $.action({action:'edit_resource',id:line.attr('data-id')},function(r){
- $('.preloader').hide();
- $('#resources a').removeClass('active');
- line.addClass('active');
-
- $('#resource').attr('data-id',r.id);
- $('#resource h2').html(r.label);
- $('#resource p').html(r.content);
- $('#resource textarea:eq(0)').focus();
- if(r.upload !=null){
- var data = {};
- data.url = r.upload.url;
- data.success = function(useless,r){
- if(r.errors.length!=0){
- alert('Erreur : '+r.errors.join(','));
- }else{
- eval(r.upload.callback);
-
- }
- }
- data.sending = function(file, xhr, formData){
- formData.append('id', $('#resource').attr('data-id'));
- }
- data.createImageThumbnails = false;
- $(r.upload.element).dropzone(data);
- }
- if(r.code != null){
- var editor = CodeMirror.fromTextArea($('#resource p textarea').get(0),r.code);
- editor.on("change", function() {
- var data ={height:800};
- var wrap = editor.getWrapperElement();
- var approp = editor.getScrollInfo().height > data.height ? data.height+"px" : "auto";
- if (wrap.style.height != approp) {
- wrap.style.height = approp;
- editor.refresh();
- }
- });
-
-
- editor.on("blur", function(cm,obj){
- var data = {};
- data.content = cm.getValue();
- data.action='save_resource_content';
- data.id = $('#resource').attr('data-id');
-
- $.action(data,function(r){
-
- });
- });
- }
-
- if(r.callback !=null){
- eval(r.callback);
- }
-
- });
- }
- /*FILE*/
- function init_file(){
- search_file();
- };
- function search_file(){
- $('#files').fill({action:'search_file',id:$('#resource').attr('data-id')});
- }
- function delete_file(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer ça?')) return;
- var line = $(element).closest('tr');
- $.action({action : 'delete_file',resource : $('#resource').attr('data-id'),id : line.attr('data-id')},function(r){
- line.remove();
- });
- }
- /*PART*/
- function init_part(){
- $('#label').autocomplete({
- source : 'action.php?action=autocomplete_part',
- minLength: 2,
- select: function( event, ui ) {
- save_part(ui.item.value);
- return false;
- }
- }).data("uiAutocomplete")._renderItem = function (ul, item) {
-
- return $("<li />")
- .data("item.autocomplete", item)
- .append("<a><img style='height:50px;width:auto; float:left;' src='" + item.value.image + "' /> " + item.label + " <br/></a><small>"+item.value.brand+"</small>")
- .appendTo(ul);
- };
- search_part();
- };
- function search_part(){
- $('#parts').fill({action:'search_part',id:$('#resource').attr('data-id')});
- }
- function save_part(model){
- var data = $.getForm('#partForm');
- if (model!=null) data.model = model.id;
- data.resource = $('#resource').attr('data-id');
- $.action(data,function(r){
- search_part();
- clear_part();
- });
- }
- function clear_part(){
- $('#partForm input').val('');
- $('#partForm').attr('data-id','');
- }
- /*
- function edit_part(element){
- var line = $(element).closest('tr');
- $.action({action:'edit_part',id:line.attr('data-id')},function(r){
- $.setForm('#partForm',r);
- $('#partForm').attr('data-id',r.id);
- });
- }
- */
- function delete_part(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer ça?')) return;
- var line = $(element).closest('tr');
- $.action({action : 'delete_part',id : line.attr('data-id')},function(r){
- line.remove();
- });
- }
|