Alias UI
This commit is contained in:
@ -6,6 +6,15 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<h3 class="ui header c_code"></h3>
|
<h3 class="ui header c_code"></h3>
|
||||||
|
<table class="ui table">
|
||||||
|
<thead>
|
||||||
|
<th>Alias</th>
|
||||||
|
<th class="right aligned" id="add_alias">
|
||||||
|
<i class="plus icon"></i>
|
||||||
|
</th>
|
||||||
|
</thead>
|
||||||
|
<tbody id="aliases"></tbody>
|
||||||
|
</table>
|
||||||
<table class="ui table">
|
<table class="ui table">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Url</th>
|
<th>Url</th>
|
||||||
@ -87,10 +96,112 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ui modal" id="add_aliases">
|
||||||
|
<div class="header">
|
||||||
|
Agregar Alias para <span class="c_name"></span>
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<form class="ui form">
|
||||||
|
<div class="inline field">
|
||||||
|
<label>Alias</label>
|
||||||
|
<input type="text" name="alias" />
|
||||||
|
</div>
|
||||||
|
<button class="ui button">Agregar</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('scripts')
|
@push('scripts')
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
let aliases = {
|
||||||
|
id: '#aliases',
|
||||||
|
add_button: '#add_alias',
|
||||||
|
add_modal: '#add_aliases',
|
||||||
|
loading: '',
|
||||||
|
loaded: false,
|
||||||
|
aliases: [],
|
||||||
|
setup: function() {
|
||||||
|
$(this.id).hide()
|
||||||
|
$(this.add_button).css('cursor', 'pointer').click((e) => {
|
||||||
|
this.add()
|
||||||
|
})
|
||||||
|
this.buildModal()
|
||||||
|
},
|
||||||
|
get: function(currency_id, data) {
|
||||||
|
if (!this.loaded) {
|
||||||
|
this.aliases = data.aliases
|
||||||
|
this.populate(currency_id)
|
||||||
|
socket.sendMessage('currency.sources', {currency_id: currency_id})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var url = '{{$urls->api}}/currency/' + currency_id + '/aliases'
|
||||||
|
$.getJSON(url, (data) => {
|
||||||
|
this.aliases = data.aliases
|
||||||
|
this.populate(currency_id)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
buildModal: function() {
|
||||||
|
$(this.add_modal).modal()
|
||||||
|
$(this.add_modal).find('form').submit((e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
this.doAdd()
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
populate: function(currency_id) {
|
||||||
|
$(this.id).html('')
|
||||||
|
$.each(this.aliases, (i, el) => {
|
||||||
|
let row = $('<tr></tr>').append(
|
||||||
|
$('<td></td>').html(el.alias)
|
||||||
|
).append(
|
||||||
|
$('<td></td>').attr('class', 'remove_source right aligned').attr('data-id', el.id).append(
|
||||||
|
$('<i></i>').attr('class', 'minus icon')
|
||||||
|
).css('cursor', 'pointer').click((e) => {
|
||||||
|
this.remove(currency_id, $(e.currentTarget).attr('data-id'))
|
||||||
|
})
|
||||||
|
)
|
||||||
|
$(this.id).append(row)
|
||||||
|
})
|
||||||
|
$(this.id).show()
|
||||||
|
},
|
||||||
|
add: function() {
|
||||||
|
$(this.add_modal).find('form').trigger('reset')
|
||||||
|
$(this.add_modal).modal('show')
|
||||||
|
},
|
||||||
|
doAdd: function() {
|
||||||
|
let form = $(this.add_modal).find('form')
|
||||||
|
let info = {
|
||||||
|
alias: form.find("[name='alias']").val()
|
||||||
|
}
|
||||||
|
var url = '{{$urls->api}}/currency/{{$currency_id}}/aliases/add'
|
||||||
|
$(this.add_modal).modal('hide')
|
||||||
|
$(this.loading).modal('show')
|
||||||
|
$.post(url, JSON.stringify(info), (data) => {
|
||||||
|
if (data.aliases[0].created) {
|
||||||
|
this.get('{{$currency_id}}')
|
||||||
|
}
|
||||||
|
}, 'json').then(() => {
|
||||||
|
$(this.loading).modal('hide')
|
||||||
|
})
|
||||||
|
},
|
||||||
|
remove: function(id) {
|
||||||
|
var url = '{{$urls->api}}/alias/' + id + '/delete'
|
||||||
|
$(this.loading).modal('show')
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
method: 'DELETE',
|
||||||
|
dataType: 'json',
|
||||||
|
success: (data) => {
|
||||||
|
if (data.deleted) {
|
||||||
|
this.get()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
$(this.loading).modal('hide')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
let sources = {
|
let sources = {
|
||||||
id: '#sources',
|
id: '#sources',
|
||||||
add_button: '#add_source',
|
add_button: '#add_source',
|
||||||
@ -302,6 +413,8 @@
|
|||||||
},
|
},
|
||||||
loading: '#loading',
|
loading: '#loading',
|
||||||
setup: function() {
|
setup: function() {
|
||||||
|
aliases.loading = this.loading
|
||||||
|
aliases.setup()
|
||||||
sources.loading = this.loading
|
sources.loading = this.loading
|
||||||
sources.setup()
|
sources.setup()
|
||||||
values.loading = this.loading
|
values.loading = this.loading
|
||||||
@ -317,6 +430,9 @@
|
|||||||
if (response.request.action == 'currency') {
|
if (response.request.action == 'currency') {
|
||||||
currency.get(response.body)
|
currency.get(response.body)
|
||||||
}
|
}
|
||||||
|
if (response.request.action == 'currency.aliases') {
|
||||||
|
aliases.get(response.request.body.currency_id, response.body)
|
||||||
|
}
|
||||||
if (response.request.action == 'currency.sources') {
|
if (response.request.action == 'currency.sources') {
|
||||||
sources.get(response.request.body.currency_id, response.body)
|
sources.get(response.request.body.currency_id, response.body)
|
||||||
}
|
}
|
||||||
@ -331,7 +447,7 @@
|
|||||||
$.each(this.map, (i, el) => {
|
$.each(this.map, (i, el) => {
|
||||||
$(el).html(data.currency[i])
|
$(el).html(data.currency[i])
|
||||||
})
|
})
|
||||||
socket.sendMessage('currency.sources', {currency_id: '{{$currency_id}}'})
|
socket.sendMessage('currency.aliases', {currency_id: '{{$currency_id}}'})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
|
@ -32,7 +32,7 @@ return [
|
|||||||
return (object) $arr;
|
return (object) $arr;
|
||||||
}),
|
}),
|
||||||
'urls' => function(Container $c) {
|
'urls' => function(Container $c) {
|
||||||
$arr = ['base' => ($c->has('base_url')) ? $c->get('base_url') : ''];
|
$arr = ['base' => ($c->has('base_url')) ? $c->get('base_url') : '/'];
|
||||||
$arr['assets'] = implode('/', [
|
$arr['assets'] = implode('/', [
|
||||||
$arr['base'],
|
$arr['base'],
|
||||||
'assets'
|
'assets'
|
||||||
|
Reference in New Issue
Block a user