prettifying the otrs links as wished through a javascript function onload, in /static/dropdown/js/otrs_link.js

This commit is contained in:
alpcentaur 2023-12-30 19:01:06 +00:00
parent 1454fce9ba
commit a51552d4dd
3 changed files with 14 additions and 7 deletions

View file

@ -36,6 +36,10 @@ class ProjectAdmin(admin.ModelAdmin):
date_hierarchy = 'end' date_hierarchy = 'end'
readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id') readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id')
class Media:
js = ('dropdown/js/otrs_link.js',)
@admin.register(BusinessCard) @admin.register(BusinessCard)
class BusinessCardAdmin(admin.ModelAdmin): class BusinessCardAdmin(admin.ModelAdmin):

View file

@ -102,10 +102,6 @@ class Project(Volunteer):
project_of_year = models.IntegerField(default=0) project_of_year = models.IntegerField(default=0)
end_quartal = models.CharField(max_length=15, null=True, blank=True, verbose_name="Quartal Projekt Ende") end_quartal = models.CharField(max_length=15, null=True, blank=True, verbose_name="Quartal Projekt Ende")
def some_otrs(self):
""" This returns a HTML anchor (hyperlink) to somewhere """
return u'<a href="%s">Link</a>' % self.otrs
some_otrs.allow_tags = True
def save(self,*args,**kwargs): def save(self,*args,**kwargs):
'''we generate the autogenerated fields here''' '''we generate the autogenerated fields here'''

View file

@ -2,9 +2,16 @@ window.addEventListener("load", function() {
(function($) { (function($) {
$(function() { $(function() {
let otrs_link = document.querySelector(".field-otrs > div > p.url > a").href;
console.log(otrs_link);
alert(otrs_link);
let otrs_link_pret = otrs_link.replace(/%3B/g, ";");
let otrs_link_pretty = otrs_link_pret.replace(/%3D/g, "=");
html.body.style.backgroundColor = color[red]; console.log(otrs_link_pretty);
document.querySelector(".field-otrs > div > p.url > a").href = otrs_link_pretty;
}); });