Installation de la version modifié de QBE dans src/
[auf_rh_dae.git] / src / qbe / django_qbe / templates / qbe.js
1 {% load i18n %}
2 /**
3 * QBE Interface details
4 */
5 if (!window.qbe) {
6 var qbe = {};
7 }
8 qbe.Models = {% autoescape off %}{{ json_models }}{% endautoescape %};
9 {% if json_data %}
10 qbe.Data = {% autoescape off %}{{ json_data }}{% endautoescape %};
11 {% else %}
12 qbe.Data = null;
13 {% endif %}
14 qbe.Containers = [];
15 (function($) {
16 $(document).ready(function() {
17 var rows = "#qbeConditionsTable tbody tr";
18
19 $("#qbeTabularTab").click(function() {
20 selectTab("Tabular");
21 return false;
22 });
23 $("#qbeDiagramTab").click(function() {
24 selectTab("Diagram");
25 $(window).resize();
26 qbe.Diagram.repaintAll();
27 return false;
28 });
29 $("#qbeModelsTab").click(function() {
30 // #qbeConnectorList,
31 $("#changelist-filter").toggle();
32 if ($(".qbeContainer").css("width") == "85%") {
33 $(".qbeContainer").css("width", "100%");
34 } else {
35 $(".qbeContainer").css("width", "85%");
36 }
37 });
38 function selectTab(tab) {
39 $("#qbeTabular").hide();
40 $("#qbeDiagram").hide();
41 $("#qbe"+ tab).show();
42 }
43
44 $('#qbeForm tbody tr').formset({
45 prefix: '{{ formset.prefix }}',
46 addText: '{% trans "Add another" %}',
47 addCssClass: "add-row",
48 deleteText: '{% trans "Remove" %}',
49 deleteCssClass: "inline-deletelink",
50 formCssClass: "dynamic-{{ formset.prefix }}",
51 emptyCssClass: "add-row",
52 removed: qbe.Core.alternatingRows,
53 added: qbe.Core.updateRow
54 });
55 // Workaround in order to get the class "add-row" in the right row
56 $(rows +":last").addClass("add-row");
57
58 $("a.qbeModelAnchor").click(qbe.Core.toggleModel);
59
60 $(".submit-row input[type='submit']").click(function() {
61 var checked = ($("input[type='checkbox']:checked").length != 0);
62 if (!checked) {
63 alert("{% trans "Select at least one field to show" %}");
64 } else {
65 qbe.Diagram.saveBoxPositions();
66 }
67 return checked;
68 });
69
70 $("#autocomplete").click(function() {
71 var models = [];
72 $(".qbeFillModels :selected").each(function() {
73 var key = $(this).val();
74 if (models.indexOf(key) == -1) {
75 models.push(key);
76 }
77 });
78 $.ajax({
79 url: "{% url django_qbe.views.qbe_autocomplete %}",
80 dataType: 'json',
81 data: "models="+ models.join(","),
82 type: 'post',
83 success: showAutocompletionOptions
84 });
85 });
86
87 function showAutocompletionOptions(data) {
88 if (!data) {
89 return false;
90 }
91 var select = $("#autocompletionOptions");
92 var options = ['<option disabled="disabled" value="">{% trans "With one of those sets" %}</option>'];
93 for(i=0; i<data.length; i++) {
94 var key = data[i].join("-");
95 var value = data[i].join(", ");
96 options.push('<option value="'+ key +'">'+ value +'</option>');
97 }
98 select.html(options.join(""));
99 select.show();
100 select.change(function() {
101 qbe.Core.addRelationsFrom(select.val());
102 });
103 };
104
105 $(".qbeFillModels").live("change", qbe.Core.fillModelsEvent);
106 $(".qbeFillFields").live("change", qbe.Core.fillFieldsEvent);
107
108 function initialize() {
109 if (qbe.Data) {
110 qbe.Core.loadData(qbe.Data);
111 }
112 $(window).resize();
113 };
114 initialize();
115 });
116 })(jQuery.noConflict());