Skip to content

Commit

Permalink
Merge pull request #305 from crucialfelix/feature/misc-fixes
Browse files Browse the repository at this point in the history
feature/misc fixes
  • Loading branch information
crucialfelix committed Dec 6, 2023
2 parents 06a199d + 748fd62 commit c802d38
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Build and publish python package

on:
release:
types: [published]

jobs:
publish-service-client-package:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.17
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
9 changes: 2 additions & 7 deletions ajax_select/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""JQuery-Ajax Autocomplete fields for Django Forms."""
__version__ = "1.7.0"
__version__ = "2.2.0"
__author__ = "crucialfelix"
__contact__ = "crucialfelix@gmail.com"
__homepage__ = "https://github.com/crucialfelix/django-ajax-selects/"
Expand All @@ -8,14 +8,9 @@
from ajax_select.helpers import make_ajax_form, make_ajax_field # noqa
from ajax_select.lookup_channel import LookupChannel # noqa

# django 1.7+ will use the new AppConfig api
# It will load all your lookups.py modules
# and any specified in settings.AJAX_LOOKUP_CHANNELS
# It will do this after all apps are imported.
from django.apps import AppConfig # noqa

# Django 3.2+ does not need default_app_config set.
# Remove this once django <3.2 support is removed
import django
if django.VERSION < (3, 2):
default_app_config = 'ajax_select.apps.AjaxSelectConfig'
default_app_config = "ajax_select.apps.AjaxSelectConfig"
9 changes: 4 additions & 5 deletions ajax_select/static/ajax_select/css/ajax_select.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.results_on_deck .ui-icon-trash {
float: left;
cursor: pointer;
}

Expand All @@ -20,19 +19,19 @@ html[data-theme="dark"] {
.results_on_deck {
padding: 0.25em 0;
}
.results_on_deck > div {
.results_on_deck .item_on_deck {
display: grid;
grid-template-columns: auto 1fr;
align-items: center;
}
.results_on_deck .item_on_deck > div {
margin: 0.5em 0;
}

form .aligned .results_on_deck {
padding-left: 14px;
margin-left: 160px;
}
.results_on_deck > div {
margin: 0.5em 0;
}
.ui-autocomplete-loading {
background: url("../images/loading-indicator.gif") no-repeat;
background-origin: content-box;
Expand Down
49 changes: 20 additions & 29 deletions ajax_select/static/ajax_select/js/ajax_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,33 @@

function receiveResult(event, ui) {
if ($this.val()) {
kill();
removeItem();
}
$this.val(ui.item.pk);
$text.val("");
addKiller(ui.item.repr, ui.item.pk);
addItemOnDeck(ui.item.repr, ui.item.pk);
$deck.trigger("added", [ui.item.pk, ui.item]);
$this.trigger("change");

return false;
}

function addKiller(repr, pk) {
var killId = "kill_" + pk + id,
killButton =
'<span class="ui-icon ui-icon-trash" id="' + killId + '">X</span> ';
function addItemOnDeck(repr, pk) {
var trashId = "trash_" + pk + id,
killButton = `<span class="ui-icon ui-icon-trash" id="${trashId}">X</span>`;
if (repr) {
$deck.empty();
$deck.append("<div>" + killButton + repr + "</div>");
$deck.append(`<div>${killButton}${repr}</div>`);
} else {
$("#" + id + "_on_deck > div").prepend(killButton);
$(`#${id}_on_deck > div`).prepend(killButton);
}
$("#" + killId).click(function () {
kill();
$("#" + trashId).click(function () {
removeItem();
$deck.trigger("killed", [pk]);
});
}

function kill() {
function removeItem() {
$this.val("");
$deck.children().fadeOut(1.0).remove();
}
Expand All @@ -45,10 +44,10 @@

function reset() {
if (options.initial) {
addKiller(options.initial[0], options.initial[1]);
addItemOnDeck(options.initial[0], options.initial[1]);
$this.val(options.initial[1]);
} else {
kill();
removeItem();
}
}

Expand All @@ -69,8 +68,8 @@
return this.each(function () {
var id = this.id,
$this = $(this),
$text = $("#" + id + "_text"),
$deck = $("#" + id + "_on_deck");
$text = $(`#${id}_text`),
$deck = $(`#${id}_on_deck`);

function receiveResult(event, ui) {
var pk = ui.item.pk,
Expand All @@ -87,18 +86,12 @@
}

function addKiller(repr, pk) {
var killId = "kill_" + pk + id,
killButton =
'<span class="ui-icon ui-icon-trash" id="' + killId + '">X</span> ';
var killId = "kill_" + pk + id;
$deck.append(
'<div id="' +
id +
"_on_deck_" +
pk +
'">' +
killButton +
repr +
" </div>"
`<div id="${id}_on_deck_${pk}" class="item_on_deck">
<span class="ui-icon ui-icon-trash" id="${killId}">X</span>
<div class="repr">${repr}</div>
</div>`
);

$("#" + killId).click(function () {
Expand All @@ -109,9 +102,7 @@

function kill(pk) {
$this.val($this.val().replace("|" + pk + "|", "|"));
$("#" + id + "_on_deck_" + pk)
.fadeOut()
.remove();
$(`#${id}_on_deck_${pk}`).fadeOut().remove();
}

options.select = receiveResult;
Expand Down
2 changes: 1 addition & 1 deletion docs/source/Install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Include the urls in your project::
# place it at whatever base url you like
url(r'^ajax_select/', include(ajax_select_urls)),

url(r'^admin/', include(admin.site.urls)),
url(r'^admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)


Expand Down

0 comments on commit c802d38

Please sign in to comment.