| 1 |
/* global visualizer1 */ |
| 2 |
|
| 3 |
(function($, v) { |
| 4 |
|
| 5 |
$(document).ready(function(){ |
| 6 |
onReady(); |
| 7 |
initTable(); |
| 8 |
}); |
| 9 |
|
| 10 |
function onReady() { |
| 11 |
$( '#editor-chart-button' ).on( 'click', function(){ |
| 12 |
$('.viz-simple-editor-type').hide(); |
| 13 |
if($("#simple-editor-type").is(':checked')){ |
| 14 |
switch($("#simple-editor-type").val()) { |
| 15 |
case 'textarea': |
| 16 |
showText($(this)); |
| 17 |
break; |
| 18 |
} |
| 19 |
} else { |
| 20 |
showTable($(this)); |
| 21 |
} |
| 22 |
}); |
| 23 |
} |
| 24 |
|
| 25 |
function showText(button) { |
| 26 |
if( button.attr( 'data-current' ) === 'chart'){ |
| 27 |
button.val( button.attr( 'data-t-editor' ) ); |
| 28 |
button.html( button.attr( 'data-t-editor' ) ); |
| 29 |
button.attr( 'data-current', 'editor' ); |
| 30 |
$('p.simple-editor-type').hide(); |
| 31 |
$( '.viz-text-editor' ).css("z-index", "9999").show(); |
| 32 |
$( '#canvas' ).css("z-index", "-100").hide(); |
| 33 |
$('.viz-simple-editor').css("z-index", "9999").show(); |
| 34 |
}else{ |
| 35 |
button.val( button.attr( 'data-t-chart' ) ); |
| 36 |
button.html( button.attr( 'data-t-chart' ) ); |
| 37 |
button.attr( 'data-current', 'chart' ); |
| 38 |
$( '.viz-text-editor' ).hide(); |
| 39 |
$('p.simple-editor-type').show(); |
| 40 |
$( '#canvas' ).css("z-index", "1").show(); |
| 41 |
$('.viz-simple-editor').hide(); |
| 42 |
} |
| 43 |
|
| 44 |
$( '#viz-text-editor-button').on('click', function(e){ |
| 45 |
$( '#editor-chart-button' ).attr("disabled", "disabled"); |
| 46 |
$('#chart-data').val($('#edited_text').val()); |
| 47 |
$('#canvas').lock(); |
| 48 |
$('#editor-form').submit(); |
| 49 |
$( '#editor-chart-button' ).removeAttr("disabled"); |
| 50 |
$( '#editor-chart-button' ).trigger('click'); |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
function initTable() { |
| 55 |
setTimeout(function(){ |
| 56 |
$('body').trigger('visualizer:db:editor:table:init', {}); |
| 57 |
$( '#canvas' ).unlock(); |
| 58 |
}, 1000); |
| 59 |
|
| 60 |
// when the data is set and the chart is updated, toggle the screen so that the chart is shown |
| 61 |
$('#table-editor-form').on( 'submit', function(e){ |
| 62 |
$( '#editor-chart-button' ).trigger('click'); |
| 63 |
$('#canvas').lock(); |
| 64 |
}); |
| 65 |
} |
| 66 |
|
| 67 |
function showTable(button) { |
| 68 |
if( button.attr( 'data-current' ) === 'chart'){ |
| 69 |
button.val( button.attr( 'data-t-editor' ) ); |
| 70 |
button.html( button.attr( 'data-t-editor' ) ); |
| 71 |
button.attr( 'data-current', 'editor' ); |
| 72 |
$( '.viz-table-editor' ).css("z-index", "9999").show(); |
| 73 |
$('body').trigger('visualizer:db:editor:table:redraw', {}); |
| 74 |
$( '#canvas' ).css("z-index", "-100").hide(); |
| 75 |
$('p.simple-editor-type').hide(); |
| 76 |
$('.viz-simple-editor').css("z-index", "9999").show(); |
| 77 |
}else{ |
| 78 |
button.val( button.attr( 'data-t-chart' ) ); |
| 79 |
button.html( button.attr( 'data-t-chart' ) ); |
| 80 |
button.attr( 'data-current', 'chart' ); |
| 81 |
$( '.viz-table-editor' ).hide(); |
| 82 |
$( '#canvas' ).css("z-index", "1").show(); |
| 83 |
$('.viz-simple-editor').hide(); |
| 84 |
$('p.simple-editor-type').show(); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
})(jQuery, visualizer1); |