Skip to content
Code-Schnipsel Gruppen Projekte
Commit 34903ac8 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: comments class into ERP

Übergeordneter 3639e323
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
.quiqqer-erp-comments {
float: left;
width: 100%;
}
.quiqqer-erp-comments-comment {
background: #f7f7f7;
float: left;
margin-bottom: 5px;
padding: 10px;
width: 100%;
}
.quiqqer-erp-comments-comment-date {
float: left;
}
.quiqqer-erp-comments-comment-message {
clear: both;
float: left;
width: 100%;
}
\ No newline at end of file
{{#comments}}
<div class="quiqqer-erp-comments-comment">
<span class="quiqqer-erp-comments-comment-date">{{time}}</span>
<span class="quiqqer-erp-comments-comment-message">{{message}}</span>
</div>
{{/comments}}
{{^comments}}
{{textNoComments}}
{{/comments}}
\ No newline at end of file
/**
* @module package/quiqqer/erp/bin/backend/controls/Comments
*
* Comments / History Display
*/
define('package/quiqqer/erp/bin/backend/controls/Comments', [
'qui/QUI',
'qui/controls/Control',
'Mustache',
'Locale',
'text!package/quiqqer/erp/bin/backend/controls/Comments.html',
'css!package/quiqqer/erp/bin/backend/controls/Comments.css'
], function (QUI, QUIControl, Mustache, QUILocale, template) {
"use strict";
var lg = 'quiqqer/erp';
return new Class({
Extends: QUIControl,
Type : 'package/quiqqer/erp/bin/backend/controls/Comments',
Binds: [
'$onCreate'
],
options: {
comments: false
},
initialize: function (options) {
this.parent(options);
this.addEvents({
onCreate: this.$onCreate
});
},
/**
* Create the DomNode element
*
* @returns {HTMLDivElement}
*/
create: function () {
this.$Elm = this.parent();
this.$Elm.addClass('quiqqer-erp-comments');
this.unserialize(this.getAttribute('comments'));
return this.$Elm;
},
/**
*
* @param {String|Object} comments
*/
unserialize: function (comments) {
if (typeOf(comments) === 'string') {
try {
comments = JSON.decode(comments);
} catch (e) {
}
}
if (!comments) {
return;
}
var Formatter = this.$getFormatter();
comments.sort(function (a, b) {
return a.time < b.time;
});
comments = comments.map(function (entry) {
var date = new Date(entry.time * 1000);
return {
time : Formatter.format(date),
message: entry.message
};
});
this.$Elm.set({
html: Mustache.render(template, {
comments : comments,
textNoComments: QUILocale.get(lg, 'comments.message.no.comments')
})
});
},
/**
* Return the date formatter
*
* @return {window.Intl.DateTimeFormat}
*/
$getFormatter: function () {
var locale = QUILocale.getCurrent();
var options = {
year : 'numeric',
month : 'numeric',
day : 'numeric',
hour : 'numeric',
minute: 'numeric',
second: 'numeric'
};
if (!locale.match('_')) {
locale = locale.toLowerCase() + '_' + locale.toUpperCase();
}
locale = locale.replace('_', '-');
try {
return window.Intl.DateTimeFormat(locale, options);
} catch (e) {
return window.Intl.DateTimeFormat('de-DE', options);
}
}
});
});
\ No newline at end of file
......@@ -81,4 +81,11 @@
</locale>
</groups>
<groups name="quiqqer/erp" datatype="js">
<locale name="comments.message.no.comments">
<de><![CDATA[Keine Daten vorhanden]]></de>
<en><![CDATA[No data available]]></en>
</locale>
</groups>
</locales>
\ No newline at end of file
<?php
/**
* This file contains QUI\ERP\Comments
*/
namespace QUI\ERP;
use QUI;
/**
* Class Comments
* - Invoice comments
* - order comments
*
* Helper class to manage comment arrays
*
* @package QUI\ERP
*/
class Comments
{
/**
* @var array
*/
protected $comments = array();
/**
* Comments constructor.
*
* @param array $comments
*/
public function __construct($comments = array())
{
foreach ($comments as $comment) {
if (isset($comment['message']) && isset($comment['time'])) {
$this->comments[] = $comment;
}
}
}
/**
* Creates a comment list from a stored representation
*
* @param string $data
* @return Comments
*/
public static function unserialize($data)
{
if (is_string($data)) {
$data = json_decode($data, true);
}
if (!is_array($data)) {
return new self();
}
return new self($data);
}
/**
* Generates a storable representation of the list
*
* @return string
*/
public function serialize()
{
return json_encode($this->toArray());
}
/**
* Generates a storable json representation of the list
* Alias for serialize()
*
* @return string
*/
public function toJSON()
{
return $this->serialize();
}
/**
* Return the list as an array
*
* @return array
*/
public function toArray()
{
return $this->comments;
}
/**
* Add a comment
*
* @param string $message
*/
public function addComment($message)
{
$this->comments[] = array(
'message' => $message,
'time' => time()
);
}
}
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren