-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(apis_entities): move template code to
apis_relations
The `apis_entities` templates contained code that handles data that comes from the `apis_relations` app. This commit moves those code parts to template files in the `apis_relations` app, which has the advantage that they are only included if the app is enabled. The `entity_relations_multiple_cards.html` template also only handles `apis_relations` related stuff, therefore it was also moved.
- Loading branch information
Showing
5 changed files
with
153 additions
and
142 deletions.
There are no files selected for viewing
16 changes: 0 additions & 16 deletions
16
apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_detail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,8 @@ | ||
{% extends "apis_core/apis_entities/abstractentity.html" %} | ||
{% load django_tables2 %} | ||
{% load apis_entities %} | ||
|
||
{% block col-zero %} | ||
<div class="card"> | ||
<div class="card-body">{% include "generic/partials/object_table.html" %}</div> | ||
<div class="card-footer">{% include "apis_entities/partials/linked_open_data.html" %}</div> | ||
</div> | ||
{% endblock col-zero %} | ||
|
||
{% block col-one %} | ||
<div class="card"> | ||
<div class="card-body"> | ||
{% object_relations as object_relations %} | ||
{% for rel in object_relations %} | ||
{% if rel.1.data|length > 0 %} | ||
<h5>{{ rel.0|title }}</h5> | ||
<div id="tab_{{ rel.2 }}">{% render_table rel.1 %}</div> | ||
{% endif %} | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% endblock col-one %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
apis_core/apis_relations/templates/apis_core/apis_entities/abstractentity_detail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "apis_core/apis_entities/abstractentity_detail.html" %} | ||
{% load django_tables2 %} | ||
{% load apis_entities %} | ||
|
||
{% block col-one %} | ||
<div class="card"> | ||
<div class="card-body"> | ||
{% object_relations as object_relations %} | ||
{% for rel in object_relations %} | ||
{% if rel.1.data|length > 0 %} | ||
<h5>{{ rel.0|title }}</h5> | ||
<div id="tab_{{ rel.2 }}">{% render_table rel.1 %}</div> | ||
{% endif %} | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% endblock col-one %} |
135 changes: 135 additions & 0 deletions
135
apis_core/apis_relations/templates/apis_core/apis_entities/abstractentity_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
{% extends "apis_core/apis_entities/abstractentity_form.html" %} | ||
{% load core %} | ||
{% load apis_entities %} | ||
|
||
{% block col-one %} | ||
<div class="card"> | ||
<div class="card-body">{% include "apis_relations/entity_relations_multiple_cards.html" %}</div> | ||
</div> | ||
{% endblock col-one %} | ||
|
||
{% block scripts %} | ||
{{ block.super }} | ||
<script type="text/javascript"> | ||
{% with object|opts as opts %} | ||
{% with opts.object_name|lower as modelname %} | ||
function GetFormAjax(FormName , ObjectID , ButtonText) { | ||
function add_form(data) { | ||
// update our tooltip content with our returned data and cache it | ||
$('#tab_'+data.tab).find('div:eq(1)').remove(); | ||
$('#tab_'+data.tab).append(data.form); | ||
$('#form_PersonInstitutionForm div:first div:first select').focus(); | ||
$('#tab_'+data.tab+" select.listselect2").each(function( index, element ){ | ||
console.log($(this).data("autocompleteLightUrl")) | ||
$(this).select2({ | ||
escapeMarkup: function(markup) { | ||
return markup; | ||
}, | ||
templateResult: function(data) { | ||
return data.text; | ||
}, | ||
templateSelection: function(data) { | ||
return data.text; | ||
}, | ||
ajax: { | ||
url: $(this).data("autocompleteLightUrl"), | ||
dataType: 'json' | ||
// Additional AJAX parameters go here; see the end of this chapter for the full code of this example | ||
}, | ||
}) | ||
|
||
|
||
}) //$(".form.ajax_form").unbind() | ||
console.log($('#tab_'+data.tab+" select.listselect2")) | ||
{% if apis_bibsonomy %} | ||
reinitialize_bibsonomy_tooltips() | ||
{% endif %} | ||
$('#tab_'+data.tab).each(function() { | ||
htmx.process(this); | ||
}); | ||
}; | ||
if (!$.ApisForms) { | ||
$.ApisForms = {} | ||
}; | ||
if (ObjectID === undefined) { | ||
if ($.ApisForms[FormName+'_'+'{{object}}']) { | ||
var new_data = $.ApisForms[FormName+'_'+'{{modelname}}'] | ||
new_data.form = new_data.form.replace('##ENT_PK##', {{object.pk}}); | ||
add_form(new_data); | ||
return; | ||
}; | ||
}; | ||
if (ButtonText === undefined) { | ||
ButtonText = 'create/modify'; | ||
}; | ||
return $.ajax( | ||
{ | ||
type: 'POST', | ||
url: '{% url 'apis_core:apis_relations:get_form_ajax' %}', | ||
beforeSend: function(request) { | ||
var csrftoken = getCookie('csrftoken'); | ||
request.setRequestHeader("X-CSRFToken", csrftoken); | ||
}, | ||
data: { | ||
'FormName':FormName, | ||
'SiteID':{{object.pk}}, | ||
'ObjectID':ObjectID, | ||
'ButtonText':ButtonText, | ||
'entity_type': '{{modelname}}', | ||
}, | ||
success: function(data) { | ||
console.log(data); | ||
add_form(data); | ||
if (!ObjectID) { | ||
$.ApisForms[FormName+'_'+'{{modelname}}'] = data; | ||
$.ApisForms[FormName+'_'+'{{modelname}}'].form = $.ApisForms[FormName+'_'+'{{modelname}}'].form | ||
.replace('/{{object.pk}}/', '/##ENT_PK##/'); | ||
}; | ||
}, | ||
error: function(error) { | ||
console.log(error) | ||
} | ||
} | ||
); | ||
} | ||
{% endwith %} | ||
{% endwith %} | ||
|
||
function EntityRelationForm_response(response){ | ||
if (response.test == false) { | ||
$('#'+response.DivID).replaceWith(response.form); | ||
//$(".form.ajax_form").unbind(); | ||
if ($.ApisHigh.tt_instance_detail) { | ||
if ($.ApisHigh.tt_instance_detail["__state"] == 'stable') { | ||
$.ApisHigh.tt_instance_detail.content(response.form); | ||
} } | ||
} else { | ||
console.log('test did not fail'); | ||
$('#tab_'+response.tab).find('div').remove(); | ||
$('#tab_'+response.tab).append(response.table_html); | ||
{% if object %} | ||
if (response.right_card) { | ||
GetFormAjax(response.tab); | ||
}; | ||
if ($.ApisHigh){ | ||
if ($.ApisHigh.tt_instance_detail["__state"] == 'stable') { | ||
$.ApisHigh.tt_instance_detail.close() | ||
} else { | ||
$('.reldelete').addClass('disabled') | ||
} | ||
} | ||
{% endif %} | ||
}; | ||
} | ||
</script> | ||
{% object_relations as object_relations %} | ||
<script type="text/javascript"> | ||
function activate_editing(){ | ||
{% for obj in object_relations %} | ||
GetFormAjax("{{obj.2}}"); | ||
//unbind_ajax_forms(); | ||
{% endfor %} | ||
}; | ||
activate_editing(); | ||
</script> | ||
{% endblock scripts %} |
File renamed without changes.