Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Label;
|
||||
|
||||
use Xentral\Core\DependencyInjection\ContainerInterface;
|
||||
|
||||
final class Bootstrap
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function registerServices()
|
||||
{
|
||||
return [
|
||||
'LabelModule' => 'onInitLabelModule',
|
||||
'LabelService' => 'onInitLabelService',
|
||||
'LabelGateway' => 'onInitLabelGateway',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
*
|
||||
* @return LabelModule
|
||||
*/
|
||||
public static function onInitLabelModule(ContainerInterface $container)
|
||||
{
|
||||
return new LabelModule($container->get('LabelService'), $container->get('LabelGateway'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
*
|
||||
* @return LabelService
|
||||
*/
|
||||
public static function onInitLabelService(ContainerInterface $container)
|
||||
{
|
||||
return new LabelService($container->get('Database'), $container->get('LabelGateway'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
*
|
||||
* @return LabelGateway
|
||||
*/
|
||||
public static function onInitLabelGateway(ContainerInterface $container)
|
||||
{
|
||||
return new LabelGateway($container->get('Database'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Label\Exception;
|
||||
|
||||
use InvalidArgumentException as SplInvalidArgumentException;
|
||||
|
||||
class InvalidArgumentException extends SplInvalidArgumentException implements LabelExceptionInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Label\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class LabelAssignException extends RuntimeException implements LabelExceptionInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Label\Exception;
|
||||
|
||||
use Xentral\Core\Exception\ModuleExceptionInterface;
|
||||
|
||||
interface LabelExceptionInterface extends ModuleExceptionInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Label\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class LabelTypeNotFoundException extends RuntimeException implements LabelExceptionInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Label;
|
||||
|
||||
use Xentral\Components\Database\Database;
|
||||
use Xentral\Modules\Label\Exception\LabelTypeNotFoundException;
|
||||
|
||||
final class LabelGateway
|
||||
{
|
||||
/** @var Database $db */
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @param Database $db
|
||||
*/
|
||||
public function __construct(Database $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $labelType
|
||||
*
|
||||
* @throws LabelTypeNotFoundException
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLabelTypeId($labelType)
|
||||
{
|
||||
$labelType = (string)$labelType;
|
||||
|
||||
$labelTypeId = (int)$this->db->fetchValue(
|
||||
'SELECT lt.id FROM label_type AS lt WHERE lt.type = :label_type',
|
||||
['label_type' => $labelType]
|
||||
);
|
||||
|
||||
if ($labelTypeId === 0) {
|
||||
throw new LabelTypeNotFoundException(sprintf(
|
||||
'Label type "%s" not found.', $labelType
|
||||
));
|
||||
}
|
||||
|
||||
return $labelTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int $referenceId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findLabelsByReference($referenceTable, $referenceId)
|
||||
{
|
||||
$referenceTable = (string)$referenceTable;
|
||||
$referenceId = (int)$referenceId;
|
||||
|
||||
$result = $this->db->fetchAll(
|
||||
'SELECT lr.id, lr.reference_table, lr.reference_id, lt.type, lt.title, lt.hexcolor
|
||||
FROM label_reference AS lr
|
||||
INNER JOIN label_type AS lt ON lr.label_type_id = lt.id
|
||||
LEFT JOIN label_group AS lg ON lg.id = lt.label_group_id
|
||||
WHERE lr.reference_table = :reference_table AND lr.reference_id = :reference_id
|
||||
AND (lt.label_group_id = 0 OR lg.group_table = :reference_table)',
|
||||
[
|
||||
'reference_table' => $referenceTable,
|
||||
'reference_id' => $referenceId,
|
||||
]
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int[]|array $referenceIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findLabelsByReferences($referenceTable, $referenceIds)
|
||||
{
|
||||
$referenceTable = (string)$referenceTable;
|
||||
$referenceIds = (array)$referenceIds;
|
||||
|
||||
$cleanedIds = [];
|
||||
foreach ($referenceIds as $referenceId) {
|
||||
$referenceId = (int)$referenceId;
|
||||
if ($referenceId > 0) {
|
||||
$cleanedIds[] = $referenceId;
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->db->fetchAll(
|
||||
'SELECT lr.id, lr.reference_table, lr.reference_id, lt.type, lt.title, lt.hexcolor
|
||||
FROM label_reference AS lr
|
||||
INNER JOIN label_type AS lt ON lr.label_type_id = lt.id
|
||||
LEFT JOIN label_group AS lg ON lt.label_group_id = lg.id
|
||||
WHERE lr.reference_table = :reference_table AND lr.reference_id IN (:reference_ids)
|
||||
AND (lt.label_group_id = 0 OR lg.group_table = :reference_table)',
|
||||
[
|
||||
'reference_table' => $referenceTable,
|
||||
'reference_ids' => $cleanedIds,
|
||||
]
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int $referenceId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findLabelTypesByReference($referenceTable, $referenceId)
|
||||
{
|
||||
$referenceId = (int)$referenceId;
|
||||
$referenceTable = (string)$referenceTable;
|
||||
|
||||
$labelTypes = (array)$this->db->fetchAll(
|
||||
'SELECT
|
||||
lt.id, lt.type, lt.title, lt.hexcolor, lr.id AS label_id
|
||||
FROM label_type AS lt
|
||||
LEFT JOIN label_group AS lg ON lt.label_group_id = lg.id
|
||||
LEFT JOIN label_reference AS lr
|
||||
ON lr.label_type_id = lt.id
|
||||
AND lr.reference_id = :reference_id
|
||||
AND lr.reference_table = :reference_table
|
||||
WHERE (lt.label_group_id = 0 OR lg.group_table = :reference_table)',
|
||||
[
|
||||
'reference_table' => $referenceTable,
|
||||
'reference_id' => $referenceId,
|
||||
]
|
||||
);
|
||||
|
||||
return $labelTypes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Label;
|
||||
|
||||
use Xentral\Modules\Label\Exception\InvalidArgumentException;
|
||||
use Xentral\Modules\Label\Exception\LabelAssignException;
|
||||
use Xentral\Modules\Label\Exception\LabelTypeNotFoundException;
|
||||
|
||||
/**
|
||||
* Simple Facade for accessing LabelService and LabelGateway
|
||||
*/
|
||||
final class LabelModule
|
||||
{
|
||||
/** @var LabelService $service */
|
||||
private $service;
|
||||
|
||||
/** @var LabelGateway $gateway */
|
||||
private $gateway;
|
||||
|
||||
/**
|
||||
* @param LabelService $service
|
||||
* @param LabelGateway $gateway
|
||||
*/
|
||||
public function __construct(LabelService $service, LabelGateway $gateway)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->gateway = $gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int $referenceId
|
||||
* @param string $labelType
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @throws LabelTypeNotFoundException
|
||||
* @throws LabelAssignException If assignment fails
|
||||
*
|
||||
* @return int Created ID from label_reference table
|
||||
*/
|
||||
public function assignLabel($referenceTable, $referenceId, $labelType)
|
||||
{
|
||||
return $this->service->assignLabel($referenceTable, $referenceId, $labelType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int $referenceId
|
||||
* @param string $labelType
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @throws LabelAssignException If assignment fails
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unassignLabel($referenceTable, $referenceId, $labelType)
|
||||
{
|
||||
$this->service->unassignLabel($referenceTable, $referenceId, $labelType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int $referenceId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findLabelsByReference($referenceTable, $referenceId)
|
||||
{
|
||||
return $this->gateway->findLabelsByReference($referenceTable, $referenceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int[]|array $referenceIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findLabelsByReferences($referenceTable, $referenceIds)
|
||||
{
|
||||
return $this->gateway->findLabelsByReferences($referenceTable, $referenceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int $referenceId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findLabelTypesByReference($referenceTable, $referenceId)
|
||||
{
|
||||
return $this->gateway->findLabelTypesByReference($referenceTable, $referenceId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Label;
|
||||
|
||||
use Xentral\Components\Database\Database;
|
||||
use Xentral\Components\Database\Exception\DatabaseExceptionInterface;
|
||||
use Xentral\Modules\Label\Exception\InvalidArgumentException;
|
||||
use Xentral\Modules\Label\Exception\LabelAssignException;
|
||||
use Xentral\Modules\Label\Exception\LabelTypeNotFoundException;
|
||||
|
||||
final class LabelService
|
||||
{
|
||||
/** @var Database $db */
|
||||
private $db;
|
||||
|
||||
/** @var LabelGateway $gateway */
|
||||
private $gateway;
|
||||
|
||||
/**
|
||||
* @param Database $db
|
||||
* @param LabelGateway $gateway
|
||||
*/
|
||||
public function __construct(Database $db, LabelGateway $gateway)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->gateway = $gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int $referenceId
|
||||
* @param string $labelType
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @throws LabelTypeNotFoundException
|
||||
* @throws LabelAssignException If assignment fails
|
||||
*
|
||||
* @return int Created ID from label_reference table
|
||||
*/
|
||||
public function assignLabel($referenceTable, $referenceId, $labelType)
|
||||
{
|
||||
$referenceTable = (string)$referenceTable;
|
||||
$referenceId = (int)$referenceId;
|
||||
$labelType = (string)$labelType;
|
||||
|
||||
if ($referenceId <= 0) {
|
||||
throw new InvalidArgumentException('Could not assign label. Argument "referenceId" is empty.');
|
||||
}
|
||||
if (empty($referenceTable)) {
|
||||
throw new InvalidArgumentException('Could not assign label. Argument "referenceTable" is empty.');
|
||||
}
|
||||
if (empty($referenceTable)) {
|
||||
throw new InvalidArgumentException('Could not assign label. Argument "labelType" is empty.');
|
||||
}
|
||||
|
||||
$labelTypeId = $this->gateway->getLabelTypeId($labelType);
|
||||
|
||||
try {
|
||||
$this->db->perform(
|
||||
'INSERT INTO label_reference (reference_table, reference_id, label_type_id, created_at)
|
||||
VALUES (:reference_table, :reference_id, :label_type_id, CURRENT_TIMESTAMP)',
|
||||
[
|
||||
'reference_table' => $referenceTable,
|
||||
'reference_id' => $referenceId,
|
||||
'label_type_id' => $labelTypeId,
|
||||
]
|
||||
);
|
||||
} catch (DatabaseExceptionInterface $exception) {
|
||||
throw new LabelAssignException(
|
||||
sprintf(
|
||||
'Could not assign label. Data: reference_table "%s", reference_id "%s", label_type "%s"',
|
||||
$referenceTable, $referenceId, $labelType
|
||||
), 0, $exception
|
||||
);
|
||||
}
|
||||
|
||||
return $this->db->lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $referenceTable
|
||||
* @param int $referenceId
|
||||
* @param string $labelType
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @throws LabelAssignException If deletion of assignment fails
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unassignLabel($referenceTable, $referenceId, $labelType)
|
||||
{
|
||||
$referenceTable = (string)$referenceTable;
|
||||
$referenceId = (int)$referenceId;
|
||||
$labelType = (string)$labelType;
|
||||
|
||||
if ($referenceId <= 0) {
|
||||
throw new InvalidArgumentException('Could not unassign label. Argument "referenceId" is empty.');
|
||||
}
|
||||
if (empty($referenceTable)) {
|
||||
throw new InvalidArgumentException('Could not unassign label. Argument "referenceTable" is empty.');
|
||||
}
|
||||
if (empty($referenceTable)) {
|
||||
throw new InvalidArgumentException('Could not unassign label. Argument "labelType" is empty.');
|
||||
}
|
||||
|
||||
try {
|
||||
$labelReferenceId = (int)$this->db->fetchValue(
|
||||
'SELECT lr.id FROM label_reference AS lr
|
||||
INNER JOIN label_type AS lt ON lr.label_type_id = lt.id
|
||||
WHERE lt.type = :label_type
|
||||
AND lr.reference_table = :reference_table
|
||||
AND lr.reference_id = :reference_id',
|
||||
[
|
||||
'reference_table' => $referenceTable,
|
||||
'reference_id' => $referenceId,
|
||||
'label_type' => $labelType,
|
||||
]
|
||||
);
|
||||
|
||||
$this->db->perform(
|
||||
'DELETE FROM label_reference WHERE id = :label_reference_id LIMIT 1',
|
||||
['label_reference_id' => $labelReferenceId]
|
||||
);
|
||||
} catch (DatabaseExceptionInterface $exception) {
|
||||
throw new LabelAssignException(
|
||||
sprintf(
|
||||
'Could not unassign label. Data: reference_table "%s", reference_id "%s", label_type "%s"',
|
||||
$referenceTable, $referenceId, $labelType
|
||||
), 0, $exception
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
/* Labels
|
||||
- - - - - - - - - - - - - - - - - - - - - - */
|
||||
.dataTable .label-container {
|
||||
display: inline-block;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
line-height: 1em;
|
||||
}
|
||||
|
||||
.dataTable .label {
|
||||
display: inline-block;
|
||||
font-size: 90%;
|
||||
line-height: 1em;
|
||||
margin: 1px 0 1px 4px;
|
||||
padding: 3px 7px 2px 7px;
|
||||
border-radius: 5px;
|
||||
border: 1px solid transparent;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Label-Manager-Icon (in DataTable)
|
||||
- - - - - - - - - - - - - - - - - - - - - - */
|
||||
.dataTable .label-manager-icon {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 4px;
|
||||
background-image: url('../themes/new/images/label.svg');
|
||||
background-size: 20px 20px;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
/* LiveTabelle im Modul
|
||||
- - - - - - - - - - - - - - - - - - - - - - */
|
||||
#datatablelabels_list .label-color-preview {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
|
||||
/**
|
||||
LABELS
|
||||
*/
|
||||
.label-container {
|
||||
display: inline-block;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
line-height: 1em;
|
||||
}
|
||||
|
||||
.label-container .label {
|
||||
cursor: default;
|
||||
display: inline-block;
|
||||
font-size: 90%;
|
||||
line-height: 1em;
|
||||
margin: 1px 0 1px 4px;
|
||||
padding: 3px 7px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 5px;
|
||||
white-space: nowrap;
|
||||
min-width: 2px;
|
||||
min-height: 11px;
|
||||
}
|
||||
|
||||
.label-container .label-text-normal {
|
||||
display: inline-block;
|
||||
}
|
||||
.label-container .label-text-compact {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.label-container.label-compact .label-text-normal {
|
||||
display: none;
|
||||
}
|
||||
.label-container.label-compact .label-text-compact {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.label-manager {
|
||||
cursor: pointer;
|
||||
}
|
||||
/* ENDE LABELS */
|
||||
|
||||
|
||||
/*
|
||||
LABEL-MANAGER-OVERLAY
|
||||
*/
|
||||
#label-manager-overlay {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 100001;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
min-width: 250px;
|
||||
min-height: 100px;
|
||||
border-radius: 10px;
|
||||
border: 5px solid var(--fieldset);
|
||||
background-color: var(--fieldset);
|
||||
box-shadow: 3px 3px 10px rgba(0, 0, 0, .33);
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#label-manager-overlay header,
|
||||
#label-manager-overlay section,
|
||||
#label-manager-overlay footer {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#label-manager-overlay header {
|
||||
padding: 10px;
|
||||
background-color: var(--fieldset);
|
||||
border-bottom: 1px solid var(--textfield-border);
|
||||
}
|
||||
|
||||
#label-manager-overlay footer {
|
||||
padding: 0 10px 5px 10px;
|
||||
background-color: var(--fieldset);
|
||||
}
|
||||
|
||||
#label-manager-overlay header h1 {
|
||||
font-size: 14px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#label-manager-overlay header .icon-close {
|
||||
cursor: pointer;
|
||||
float: right;
|
||||
display: inline-block;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background-image: url('../themes/new/images/x-icon.png');
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 80%;
|
||||
}
|
||||
|
||||
#label-manager-overlay .content-list {
|
||||
display: block;
|
||||
min-height: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#label-manager-overlay .line {
|
||||
clear: both;
|
||||
display: block;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
#label-manager-overlay .line input {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#label-manager-overlay .line .label-title {
|
||||
display: inline-block;
|
||||
line-height: 1em;
|
||||
margin: 0 0 0 4px;
|
||||
padding: 3px 7px;
|
||||
border-radius: 5px;
|
||||
white-space: nowrap;
|
||||
border: 1px solid transparent;
|
||||
background-color: var(--fieldset);
|
||||
}
|
||||
/* ENDE LABEL-MANAGER-OVERLAY */
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Modul zum Nachladen von Labeln in Datatables
|
||||
*
|
||||
* Markup:
|
||||
* `<a href="#" class="label-manager"
|
||||
* data-label-reference-table="wiedervorlage"
|
||||
* data-label-reference-id="6"
|
||||
* data-label-column-number="5">
|
||||
* <span class="label-manager-icon"></span>
|
||||
* </a>
|
||||
*
|
||||
* Vorgehen:
|
||||
* 1. Auf Event warten dass eine DataTable fertig gerendert ist
|
||||
* 2. Prüfen ob DataTable Markup zum Nachladen für Labels enthält
|
||||
* 3. HTML-Markup für LabelLoader-Modul erzeugen
|
||||
* 4. LabelLoader-Modul aufrufen (Modul sammelt benötigte Informationen; lädt Labels per AJAX nach und rendert diese)
|
||||
*/
|
||||
var DataTableLabelLoader = (function ($, LabelLoaderModule) {
|
||||
'use strict';
|
||||
|
||||
var me = {
|
||||
|
||||
init: function () {
|
||||
me.registerEvents();
|
||||
},
|
||||
|
||||
registerEvents: function () {
|
||||
$(document).on('draw.dt', function (e, settings) {
|
||||
me.onDrawDataTableDraw(settings.sTableId);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* EventHandler fürs Nachladen von Labeln
|
||||
*
|
||||
* Der EventHandler greift wenn eine DataTable fertig gerendert ist.
|
||||
*
|
||||
* @param {string} tableName
|
||||
*/
|
||||
onDrawDataTableDraw: function (tableName) {
|
||||
// Prüfen ob LabelLoader manuell erstellt wurde, oder noch erstellt werden muss
|
||||
if (me.checkLoaderRequired(tableName) === true) {
|
||||
var $firstManager = $('#' + tableName).find('.label-manager').first();
|
||||
var columnNumber = $firstManager.data('labelColumnNumber');
|
||||
if (typeof columnNumber !== 'undefined') {
|
||||
me.createLabelLoader(tableName, columnNumber);
|
||||
}
|
||||
}
|
||||
|
||||
// Benötigte Elemente mit Data-Attributen wurden erstellt
|
||||
// Ab hier übernimmt das "normale" LabelLoader-Modul
|
||||
LabelLoaderModule.loadAll();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} tableName
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
checkLoaderRequired: function (tableName) {
|
||||
var $table = $('#' + tableName);
|
||||
var hasLabelContainer = $table.find('.label-container').length > 0;
|
||||
var hasLabelManager = $table.find('.label-manager').length > 0;
|
||||
|
||||
return hasLabelManager === true && hasLabelContainer === false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Markup für LabelLoader-Modul erzeugen
|
||||
*
|
||||
* Markup:
|
||||
* `<span class="label-loader" data-label-reference-id="1" data-label-reference-table="adresse"></span>`
|
||||
*
|
||||
* @param {string} tableName
|
||||
* @param {number} columnNumber
|
||||
*/
|
||||
createLabelLoader: function (tableName, columnNumber) {
|
||||
var $table = $('#' + tableName);
|
||||
var $rows = $table.children('tbody').children('tr');
|
||||
|
||||
$rows.each(function (index, row) {
|
||||
var $row = $(row);
|
||||
var $labelManager = $row.find('.label-manager').first();
|
||||
if ($labelManager.length === 0) {
|
||||
return;
|
||||
}
|
||||
var referenceId = $labelManager.data('labelReferenceId');
|
||||
var referenceTable = $labelManager.data('labelReferenceTable');
|
||||
if (typeof referenceId === 'undefined' || typeof referenceTable === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
var $cell = $row.children('td').eq(columnNumber - 1);
|
||||
var $labelLoader = $('<span>').addClass('label-loader').data({
|
||||
labelReferenceId: referenceId,
|
||||
labelReferenceTable: referenceTable
|
||||
});
|
||||
$cell.append($labelLoader);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Modul so früh wie möglich registrieren.
|
||||
// Ansonsten kriegt man nicht alle DataTable Draw-Events mit.
|
||||
me.init();
|
||||
|
||||
return {
|
||||
init: me.init
|
||||
}
|
||||
|
||||
})(jQuery, LabelLoader);
|
||||
@@ -0,0 +1,555 @@
|
||||
/**
|
||||
* Für die Bedienung der Modul-Oberfläche
|
||||
*/
|
||||
var DataTableLabelsUi = (function ($) {
|
||||
'use strict';
|
||||
|
||||
var me = {
|
||||
|
||||
isInitialized: false,
|
||||
|
||||
storage: {
|
||||
$table: null,
|
||||
$editDialog: null,
|
||||
dataTableApi: null
|
||||
},
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
init: function () {
|
||||
if (me.isInitialized === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
me.storage.$table = $('#datatablelabels_list');
|
||||
me.storage.$editDialog = $('#datatablelabels_edit');
|
||||
me.storage.dataTableApi = me.storage.$table.dataTable().api();
|
||||
|
||||
if (me.storage.$table.length === 0 || me.storage.$editDialog.length === 0) {
|
||||
throw 'Could not initialize DataTableLabelsUi. Required elements are missing.';
|
||||
}
|
||||
|
||||
me.initDialog();
|
||||
me.registerEvents();
|
||||
|
||||
me.isInitialized = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
initDialog: function () {
|
||||
me.storage.$editDialog.dialog({
|
||||
modal: true,
|
||||
bgiframe: true,
|
||||
closeOnEscape: false,
|
||||
minWidth: 550,
|
||||
maxHeight: 400,
|
||||
autoOpen: false,
|
||||
buttons: [{
|
||||
text: 'ABBRECHEN',
|
||||
click: function () {
|
||||
me.resetEditDialog();
|
||||
me.closeEditDialog();
|
||||
}
|
||||
}, {
|
||||
text: 'SPEICHERN',
|
||||
click: function () {
|
||||
me.saveItem();
|
||||
}
|
||||
}],
|
||||
open: function () {
|
||||
var $colorInput = $('#datatablelabel_hexcolor');
|
||||
var $titleInput = $('#datatablelabel_title');
|
||||
var $typeInput = $('#datatablelabel_type');
|
||||
var isTypeInputEmpty = ($typeInput.val().length === 0);
|
||||
|
||||
// Fokus auf erstes Eingabefeld setzen
|
||||
$titleInput.trigger('focus');
|
||||
|
||||
// Default-Farbe setzen, wenn leer
|
||||
if ($colorInput.val().length === 0) {
|
||||
$colorInput.val('#000000').trigger('change');
|
||||
}
|
||||
|
||||
// Kennung automatisch aus Titel füllen
|
||||
$titleInput.on('keyup', function () {
|
||||
if (!isTypeInputEmpty) {
|
||||
return;
|
||||
}
|
||||
var titleVal = $(this).val();
|
||||
var typeVal = titleVal.toLowerCase().replace(/[^a-z0-9_]+/g, '').substr(0, 24);
|
||||
$typeInput.val(typeVal);
|
||||
});
|
||||
},
|
||||
close: function () {
|
||||
me.resetEditDialog();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
registerEvents: function () {
|
||||
|
||||
// Eintrag bearbeiten
|
||||
$(document).on('click', '.datatablelabels-edit', function (e) {
|
||||
e.preventDefault();
|
||||
var fieldId = $(this).data('id');
|
||||
me.editItem(fieldId);
|
||||
});
|
||||
|
||||
// Eintrag löschen
|
||||
$(document).on('click', '.datatablelabels-delete', function (e) {
|
||||
e.preventDefault();
|
||||
var fieldId = $(this).data('id');
|
||||
me.deleteItem(fieldId);
|
||||
});
|
||||
|
||||
// Farb-Vorschau in LiveTabelle anzeigen
|
||||
$(document).on('draw.dt', function (e, settings) {
|
||||
var tableName = settings.sTableId;
|
||||
var $table = $('#' + tableName);
|
||||
|
||||
$table.find('.label-color-preview').each(function (index, element) {
|
||||
var $element = $(element);
|
||||
var hexColor = $element.data('hexcolor');
|
||||
$element.css('background-color', hexColor);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
createItem: function () {
|
||||
if (me.isInitialized === false) {
|
||||
me.init();
|
||||
}
|
||||
me.resetEditDialog();
|
||||
me.openEditDialog();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {number} labelTypeId
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
editItem: function (labelTypeId) {
|
||||
labelTypeId = parseInt(labelTypeId);
|
||||
if (isNaN(labelTypeId) || labelTypeId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: 'index.php?module=datatablelabels&action=edit&cmd=get',
|
||||
data: {
|
||||
id: labelTypeId
|
||||
},
|
||||
method: 'post',
|
||||
dataType: 'json',
|
||||
beforeSend: function () {
|
||||
App.loading.open();
|
||||
},
|
||||
success: function (result) {
|
||||
me.storage.$editDialog.find('#datatablelabel_id').val(result.data.id);
|
||||
me.storage.$editDialog.find('#datatablelabel_type').val(result.data.type);
|
||||
me.storage.$editDialog.find('#datatablelabel_title').val(result.data.title);
|
||||
me.storage.$editDialog.find('#datatablelabel_group').val(result.data.group_id);
|
||||
me.storage.$editDialog.find('#datatablelabel_hexcolor').val(result.data.hexcolor).trigger('change');
|
||||
me.storage.$editDialog.dialog('open');
|
||||
},
|
||||
error: function (jqXhr) {
|
||||
alert('Fehler: ' + jqXhr.responseJSON.error);
|
||||
},
|
||||
complete: function () {
|
||||
App.loading.close();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
saveItem: function () {
|
||||
$.ajax({
|
||||
url: 'index.php?module=datatablelabels&action=edit&cmd=save',
|
||||
data: {
|
||||
id: $('#datatablelabel_id').val(),
|
||||
type: $('#datatablelabel_type').val(),
|
||||
title: $('#datatablelabel_title').val(),
|
||||
group: $('#datatablelabel_group').val(),
|
||||
hexcolor: $('#datatablelabel_hexcolor').val()
|
||||
},
|
||||
method: 'post',
|
||||
dataType: 'json',
|
||||
beforeSend: function () {
|
||||
App.loading.open();
|
||||
},
|
||||
success: function (data) {
|
||||
if (data.success === true) {
|
||||
me.resetEditDialog();
|
||||
me.reloadDataTable();
|
||||
me.closeEditDialog();
|
||||
}
|
||||
if (data.success === false) {
|
||||
alert(data.error);
|
||||
}
|
||||
},
|
||||
error: function (jqXhr) {
|
||||
alert('Fehler: ' + jqXhr.responseJSON.error);
|
||||
},
|
||||
complete: function () {
|
||||
App.loading.close();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {number} fieldId
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
deleteItem: function (fieldId) {
|
||||
var confirmValue = confirm('Wirklich löschen?');
|
||||
if (confirmValue === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: 'index.php?module=datatablelabels&action=edit&cmd=delete',
|
||||
data: {
|
||||
id: fieldId
|
||||
},
|
||||
method: 'post',
|
||||
dataType: 'json',
|
||||
beforeSend: function () {
|
||||
App.loading.open();
|
||||
},
|
||||
success: function (data) {
|
||||
if (data.success === true) {
|
||||
me.reloadDataTable();
|
||||
}
|
||||
if (data.success === false) {
|
||||
alert('Unbekannter Fehler beim Löschen.');
|
||||
}
|
||||
},
|
||||
error: function (jqXhr) {
|
||||
alert('Fehler: ' + jqXhr.responseJSON.error);
|
||||
},
|
||||
complete: function () {
|
||||
App.loading.close();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
openEditDialog: function () {
|
||||
me.storage.$editDialog.dialog('open');
|
||||
},
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
closeEditDialog: function () {
|
||||
me.storage.$editDialog.dialog('close');
|
||||
},
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
resetEditDialog: function () {
|
||||
me.storage.$editDialog.find('#datatablelabel_id').val('');
|
||||
me.storage.$editDialog.find('#datatablelabel_type').val('');
|
||||
me.storage.$editDialog.find('#datatablelabel_title').val('').off('keyup');
|
||||
me.storage.$editDialog.find('#datatablelabel_group').val(0);
|
||||
me.storage.$editDialog.find('#datatablelabel_hexcolor').val('');
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
reloadDataTable: function () {
|
||||
me.storage.dataTableApi.ajax.reload();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
init: me.init,
|
||||
createItem: me.createItem
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
||||
/**
|
||||
* Für die Bedienung der Modul-Oberfläche
|
||||
*/
|
||||
var DataTableLabelsAutomaticLabelsUi = (function ($) {
|
||||
'use strict';
|
||||
|
||||
var me = {
|
||||
|
||||
isInitialized: false,
|
||||
|
||||
storage: {
|
||||
$table: null,
|
||||
$editDialog: null,
|
||||
dataTableApi: null
|
||||
},
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
init: function () {
|
||||
if (me.isInitialized === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
me.storage.$table = $('#datatablelabels_automaticlabelslist');
|
||||
me.storage.$editDialog = $('#datatablelabels_automaticlabelsedit');
|
||||
me.storage.dataTableApi = me.storage.$table.dataTable().api();
|
||||
|
||||
if (me.storage.$table.length === 0 || me.storage.$editDialog.length === 0) {
|
||||
throw 'Could not initialize DataTableLabelsUi. Required elements are missing.';
|
||||
}
|
||||
|
||||
me.initDialog();
|
||||
me.registerEvents();
|
||||
|
||||
me.isInitialized = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
initDialog: function () {
|
||||
me.storage.$editDialog.dialog({
|
||||
modal: true,
|
||||
bgiframe: true,
|
||||
closeOnEscape: false,
|
||||
minWidth: 550,
|
||||
maxHeight: 400,
|
||||
autoOpen: false,
|
||||
buttons: [{
|
||||
text: 'ABBRECHEN',
|
||||
click: function () {
|
||||
me.resetEditDialog();
|
||||
me.closeEditDialog();
|
||||
}
|
||||
}, {
|
||||
text: 'SPEICHERN',
|
||||
click: function () {
|
||||
me.saveItem();
|
||||
}
|
||||
}],
|
||||
open: function () {
|
||||
// Fokus auf erstes Eingabefeld setzen
|
||||
$('#datatablelabel_automaticlabelname').trigger('focus');
|
||||
},
|
||||
close: function () {
|
||||
me.resetEditDialog();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
registerEvents: function () {
|
||||
|
||||
// Eintrag bearbeiten
|
||||
$(document).on('click', '.datatablelabels-automaticlabeledit', function (e) {
|
||||
e.preventDefault();
|
||||
var fieldId = $(this).data('id');
|
||||
me.editItem(fieldId);
|
||||
});
|
||||
|
||||
// Eintrag löschen
|
||||
$(document).on('click', '.datatablelabels-automaticlabeldelete', function (e) {
|
||||
e.preventDefault();
|
||||
var fieldId = $(this).data('id');
|
||||
me.deleteItem(fieldId);
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
createItem: function () {
|
||||
if (me.isInitialized === false) {
|
||||
me.init();
|
||||
}
|
||||
me.resetEditDialog();
|
||||
me.openEditDialog();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {number} automaticLabelId
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
editItem: function (automaticLabelId) {
|
||||
automaticLabelId = parseInt(automaticLabelId);
|
||||
if (isNaN(automaticLabelId) || automaticLabelId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: 'index.php?module=datatablelabels&action=automaticlabelsedit&cmd=get',
|
||||
data: {
|
||||
id: automaticLabelId
|
||||
},
|
||||
method: 'post',
|
||||
dataType: 'json',
|
||||
beforeSend: function () {
|
||||
App.loading.open();
|
||||
},
|
||||
success: function (result) {
|
||||
me.storage.$editDialog.find('#datatablelabel_automaticlabelid').val(result.data.id);
|
||||
me.storage.$editDialog.find('#datatablelabel_automaticlabelname').val(result.data.labelname);
|
||||
me.storage.$editDialog.find('#datatablelabel_automaticlabelaction').val(result.data.action);
|
||||
me.storage.$editDialog.find('#datatablelabel_automaticlabelselection').val(result.data.selection);
|
||||
me.storage.$editDialog.find('#datatablelabel_automaticlabelproject').val(result.data.project);
|
||||
me.storage.$editDialog.dialog('open');
|
||||
},
|
||||
error: function (jqXhr) {
|
||||
alert('Fehler: ' + jqXhr.responseJSON.error);
|
||||
},
|
||||
complete: function () {
|
||||
App.loading.close();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
saveItem: function () {
|
||||
$.ajax({
|
||||
url: 'index.php?module=datatablelabels&action=automaticlabelsedit&cmd=save',
|
||||
data: {
|
||||
id: $('#datatablelabel_automaticlabelid').val(),
|
||||
labelname: $('#datatablelabel_automaticlabelname').val(),
|
||||
action: $('#datatablelabel_automaticlabelaction').val(),
|
||||
selection: $('#datatablelabel_automaticlabelselection').val(),
|
||||
project: $('#datatablelabel_automaticlabelproject').val()
|
||||
},
|
||||
method: 'post',
|
||||
dataType: 'json',
|
||||
beforeSend: function () {
|
||||
App.loading.open();
|
||||
},
|
||||
success: function (data) {
|
||||
if (data.success === true) {
|
||||
me.resetEditDialog();
|
||||
me.reloadDataTable();
|
||||
me.closeEditDialog();
|
||||
}
|
||||
if (data.success === false) {
|
||||
alert(data.error);
|
||||
}
|
||||
},
|
||||
error: function (jqXhr) {
|
||||
alert('Fehler: ' + jqXhr.responseJSON.error);
|
||||
},
|
||||
complete: function () {
|
||||
App.loading.close();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {number} fieldId
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
deleteItem: function (fieldId) {
|
||||
var confirmValue = confirm('Wirklich löschen?');
|
||||
if (confirmValue === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: 'index.php?module=datatablelabels&action=automaticlabelsedit&cmd=delete',
|
||||
data: {
|
||||
id: fieldId
|
||||
},
|
||||
method: 'post',
|
||||
dataType: 'json',
|
||||
beforeSend: function () {
|
||||
App.loading.open();
|
||||
},
|
||||
success: function (data) {
|
||||
if (data.success === true) {
|
||||
me.reloadDataTable();
|
||||
}
|
||||
if (data.success === false) {
|
||||
alert('Unbekannter Fehler beim Löschen.');
|
||||
}
|
||||
},
|
||||
error: function (jqXhr) {
|
||||
alert('Fehler: ' + jqXhr.responseJSON.error);
|
||||
},
|
||||
complete: function () {
|
||||
App.loading.close();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
openEditDialog: function () {
|
||||
me.storage.$editDialog.dialog('open');
|
||||
},
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
closeEditDialog: function () {
|
||||
me.storage.$editDialog.dialog('close');
|
||||
},
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
resetEditDialog: function () {
|
||||
me.storage.$editDialog.find('#datatablelabel_automaticlabelid').val('');
|
||||
me.storage.$editDialog.find('#datatablelabel_automaticlabelname').val('');
|
||||
var action = document.getElementById('datatablelabel_automaticlabelaction');
|
||||
action.selectedIndex = 0;
|
||||
var selection = document.getElementById('datatablelabel_automaticlabelselection');
|
||||
selection.selectedIndex = 0;
|
||||
me.storage.$editDialog.find('#datatablelabel_automaticlabelproject').val('');
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
reloadDataTable: function () {
|
||||
me.storage.dataTableApi.ajax.reload();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
init: me.init,
|
||||
createItem: me.createItem
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
||||
$(document).ready(function () {
|
||||
if ($('#datatablelabels_list').length > 0) {
|
||||
DataTableLabelsUi.init();
|
||||
}
|
||||
|
||||
if ($('#datatablelabels_automaticlabelslist').length > 0) {
|
||||
DataTableLabelsAutomaticLabelsUi.init();
|
||||
}
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user