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