11<template >
22 <div class =" bw-page-container sponsors-page" >
3- <NavbarBweb ></NavbarBweb >
43 <div class =" popis" >
54
65 <div v-if =" this.guestsEnabled != 0" class =" popis-element1" >
1615 </div >
1716
1817 <div >
19- <h1 v-if =" this.guestsEnabled == 0" class =" page-title-dis" style =" margin-left : 50px ; margin-top : 70px ;" >Popis
18+ <h1 v-if =" this.guestsEnabled == 0" class =" page-title-dis" style =" margin-left : 50px ; margin-top : 70px ;" >
19+ Popis
2020 uzvanika</h1 >
2121
2222 <div v-if =" this.guestsEnabled != 0" class =" infofield" >
6161 <div class =" sponsorsPage-table" >
6262 <div class =row >
6363 <table id =" guests" >
64- <tbody :class =" { [$style.tbodyHigh]: this.tbodyHigh }" style = " overflow : auto ; height : 35 rem !important ; "
65- class =" tbody" >
66- <tr v-for =" guest in sponsorGuests" :key =" guest.id" >
64+ <tbody :class =" { [$style.tbodyHigh]: this.tbodyHigh }"
65+ style = " overflow : auto ; height : 35 rem !important ; " class =" tbody" >
66+ <tr v-for =" guest in sponsorGuests" style = " width : 100 % ; " :key =" guest.id" >
6767 <td style =" padding-left : 20% !important ;" >{{ guest.name }}</td >
6868 <td v-if =" this.guestsEnabled != 0" style =" padding-left : 10% !important ;" ><button
6969 class =" button-icon" @click =sponsorDelete(guest)
7777 </div >
7878 </div >
7979
80- <Footer ></Footer >
8180 </div >
81+ <Footer ></Footer >
8282</template >
8383
8484<script >
8585import Footer from ' @/components/NavbarAndFooter/Footer.vue'
8686import NavbarBweb from ' @/components/NavbarAndFooter/NavbarBweb.vue'
8787import store from ' @/store/visibilityStore'
88- import axios from ' axios'
88+ import { publicApi } from " @/plugins/publicApi" ;
89+ import { api } from ' @/plugins/api' ;
8990
9091export default {
9192 components: { Footer, NavbarBweb },
@@ -97,7 +98,6 @@ export default {
9798 progress: 0 ,
9899 message: " " ,
99100
100- sponsorss: [],
101101 name: ' ' ,
102102 id: ' ' ,
103103 len: ' ' ,
@@ -112,14 +112,14 @@ export default {
112112 mounted () {
113113 this .slug = this .$route .params .slug ;
114114 if (this .slug != ' 0' ) {
115- axios .get (process . env . VUE_APP_BASE_URL + ' /sponsors/?search= ' + this .slug + " &search_fields=slug " )
115+ publicApi .get (" /sponsors/public/ " , { params : { slug : this .slug } } )
116116 .then (async response => {
117117 this .sponsors = response .data ;
118118 if (this .sponsors .length == 0 ) {
119119 this .$router .push ({ path: ' /admin/sponsors-add/0' });
120120 }
121121
122- this .sponsorsInstance = this .sponsors [ 0 ] ;
122+ this .sponsorsInstance = this .sponsors ;
123123 this .name = this .sponsorsInstance .name ;
124124 this .previewImage = this .sponsorsInstance .image ;
125125 this .id = this .sponsorsInstance .id ;
@@ -130,11 +130,9 @@ export default {
130130
131131 this .guestsEnabled = this .sponsorsInstance .guestsEnabled ;
132132
133-
134-
135- console .log (this .guestsEnabled )
136133 if (this .guestsEnabled != 2 ) {
137134 let closeTime = Date .parse (store .state .SPONSORS_INPUT_TIME ); // pravi closetime 12.11.2022 u 19.00
135+ console .log (closeTime)
138136 if (Date .now () > closeTime) {
139137 console .log (" zatvaraaaaj" )
140138 console .log (this .sponsorsInstance )
@@ -168,50 +166,60 @@ export default {
168166
169167 methods: {
170168 created () {
171-
172- if (this .slug != ' 0' ) {
173- axios .get (process .env .VUE_APP_BASE_URL + ' /guests/?search=' + this .slug + " &search_fields=tag" )
169+ if (this .slug !== ' 0' ) {
170+ api
171+ .get (` ${ process .env .VUE_APP_BASE_URL } /sponsors/public/guests/` , {
172+ params: { slug: this .slug }
173+ })
174174 .then (response => {
175175 this .sponsorGuests = response .data ;
176176 this .guestsAdded = this .sponsorGuests .length ;
177- axios .get (process .env .VUE_APP_BASE_URL + ' /guests/' )
178- .then (response => {
179- this .guests = response .data ;
180- })
181- })
182-
183- } else {
184- axios .get (process .env .VUE_APP_BASE_URL + ' /sponsors/?ordering=order' ,)
185- .then (response => {
186- this .sponsorss = response .data ;
187177 })
178+ .catch (err => {
179+ const msg = err? .response ? .data ? .detail || " Greška pri dohvaćanju gostiju" ;
180+ window .alert (msg);
181+ });
188182 }
189183 },
190184 sponsorDelete (guest ) {
191- axios .delete (process .env .VUE_APP_BASE_URL + ' /guests/' + guest .id + ' /' ,
192- { auth: { username: process .env .VUE_APP_DJANGO_USER , password: process .env .VUE_APP_DJANGO_PASS } }
193- )
194- .then (() => {
195- this .created ();
196- })
185+ api .delete (
186+ ` ${ process .env .VUE_APP_BASE_URL } /sponsors/public/guests/` ,
187+ { params: { slug: this .slug , id: guest .id } }
188+ ).then (() => {
189+ this .created ();
190+ }).catch (err => {
191+ const msg = err? .response ? .data ? .detail || " Greška pri brisanju gosta" ;
192+ window .alert (msg);
193+ });
197194 },
198195 sponsorPost () {
199- if (this .guestCap == this .guestsAdded ) {
200- window .alert (" Već ste unjeli maximum dozvoljenih gostiju" )
201- } else {
202-
203- let sponsorTag = this .slug + " VIP - Sponzor - " + this .name ;
204-
205- axios .post (process .env .VUE_APP_BASE_URL + ' /guests/' ,
206- { name: this .sponsorName , tag: sponsorTag, bought: ' 1' , entered: ' 0' },
207- { auth: { username: process .env .VUE_APP_DJANGO_USER , password: process .env .VUE_APP_DJANGO_PASS } }
208- )
209- .then (() => {
210- this .sponsorName = " " ;
211- this .created ()
212- })
196+ // Check if sponsor reached guest limit
197+ if (this .guestCap === this .guestsAdded ) {
198+ window .alert (" Već ste unijeli maksimalan broj dozvoljenih gostiju" );
199+ return ;
213200 }
201+
202+ const guestName = (this .sponsorName || " " ).trim ();
203+ if (! guestName) {
204+ return ;
205+ }
206+
207+ const payload = {
208+ slug: this .slug ,
209+ name: guestName,
210+ };
211+
212+ api .post (` ${ process .env .VUE_APP_BASE_URL } /sponsors/public/guests/` , payload)
213+ .then (() => {
214+ this .sponsorName = " " ;
215+ this .created ();
216+ })
217+ .catch (err => {
218+ const msg = err? .response ? .data ? .detail || " Greška pri unosu gosta" ;
219+ window .alert (msg);
220+ });
214221 }
222+
215223 }
216224}
217225< / script>
@@ -286,7 +294,6 @@ export default {
286294
287295.popis {
288296 position: relative;
289- margin-top : 2% ;
290297 display: grid;
291298 grid- template- rows: 55 % 45 % ;
292299 width: 100 % ;
359366
360367.footery {
361368 background: var (-- bw- footer- color);
362- ;
369+ ;
363370}
364371
365372.footery :: after {
0 commit comments