Sort cuentas in home
This commit is contained in:
@ -18,6 +18,11 @@ class Categoria extends Model {
|
|||||||
public function cuentas() {
|
public function cuentas() {
|
||||||
if ($this->cuentas === null) {
|
if ($this->cuentas === null) {
|
||||||
$this->cuentas = $this->parentOf(Cuenta::class, [Model::CHILD_KEY => 'categoria_id']);
|
$this->cuentas = $this->parentOf(Cuenta::class, [Model::CHILD_KEY => 'categoria_id']);
|
||||||
|
if ($this->cuentas !== null) {
|
||||||
|
usort($this->cuentas, function($a, $b) {
|
||||||
|
return strcmp($a->nombre, $b->nombre);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->cuentas;
|
return $this->cuentas;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,20 @@ class Cuenta {
|
|||||||
}
|
}
|
||||||
tr.append(td)
|
tr.append(td)
|
||||||
})
|
})
|
||||||
$("[data-id='" + this.categoria_id + "'][data-class='categoria']").after(tr)
|
const prev = this.prev()
|
||||||
|
prev.after(tr)
|
||||||
|
}
|
||||||
|
prev() {
|
||||||
|
let prev = $("[data-id='" + this.categoria_id + "'][data-class='categoria']")
|
||||||
|
let n = 0
|
||||||
|
while (prev.next().attr('data-class') === 'cuenta') {
|
||||||
|
prev = prev.next()
|
||||||
|
n ++;
|
||||||
|
if (n >= 100) {
|
||||||
|
return prev
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return prev
|
||||||
}
|
}
|
||||||
remove() {
|
remove() {
|
||||||
$("[data-id='" + this.id + "'][data-class='cuenta']").remove()
|
$("[data-id='" + this.id + "'][data-class='cuenta']").remove()
|
||||||
|
Reference in New Issue
Block a user