Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
feat(ui,api): enhance entity configuration user interface and API
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jul 5, 2017
1 parent ab7113b commit c4b02a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
20 changes: 19 additions & 1 deletion inc/entityconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class PluginFlyvemdmEntityconfig extends CommonDBTM {
const RIGHT_FLYVEMDM_DEVICE_COUNT_LIMIT = 128;
const RIGHT_FLYVEMDM_APP_DOWNLOAD_URL = 256;
const RIGHT_FLYVEMDM_INVITATION_TOKEN_LIFE = 512;

const CONFIG_DEFINED = -3;
const CONFIG_PARENT = -2;

/**
* @var bool $dohistory maintain history
*/
Expand Down Expand Up @@ -83,6 +87,9 @@ public function post_getFromDB() {
foreach ($fieldsToRecurse as $field => $default) {
if (empty($this->fields[$field])) {
$this->fields[$field] = $this->getUsedConfig($field, $parentEntityId, $field, $default);
$this->fields["_$field"] = self::CONFIG_PARENT;
} else {
$this->fields["_$field"] = self::CONFIG_DEFINED;
}
}
}
Expand Down Expand Up @@ -298,7 +305,18 @@ static function isNewID($ID) {

public function showFormForEntity(Entity $item) {
$ID = $item->fields['id'];
$this->getFromDBByCrit(['entities_id' => $ID]);
if (!$this->getFromDBByCrit(['entities_id' => $ID])) {
$this->add([
'id' => $ID,
'support_name' => self::CONFIG_PARENT,
'support_phone' => self::CONFIG_PARENT,
'support_website' => self::CONFIG_PARENT,
'support_email' => self::CONFIG_PARENT,
'support_address' => self::CONFIG_PARENT,
]);
// To set virtual fields about inheritance
$this->post_getFromDB();
}
$this->initForm($ID);
$this->showFormHeader(['formtitle' => __('Helpdesk information', 'flyvemdm')]);
$canedit = static::canUpdate();
Expand Down
15 changes: 15 additions & 0 deletions tpl/entity_entityconfig.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
</td>
<td>
<input name="support_name" value="{{ entityConfig.support_name }}" />
{% if entityConfig._support_name == -2 %}
<div class="green">{{ __('Inheritance of the parent entity') }}</div>
{% endif %}
</td>
<td rowspan="4">
{{ __('Support address', 'flyvemdm') }}
</td>
<td rowspan="4">
<textarea cols="45" rows="8" name="support_address">{{ entityConfig.support_address }}</textarea>
{% if entityConfig._support_address == -2 %}
<div class="green">{{ __('Inheritance of the parent entity') }}</div>
{% endif %}
</td>
</tr>
<tr class='tab_bg_1'>
Expand All @@ -18,6 +24,9 @@
</td>
<td>
<input name="support_phone" value="{{ entityConfig.support_phone }}" />
{% if entityConfig._support_phone == -2 %}
<div class="green">{{ __('Inheritance of the parent entity') }}</div>
{% endif %}
</td>
</tr>
<tr class='tab_bg_1'>
Expand All @@ -26,6 +35,9 @@
</td>
<td>
<input name="support_website" value="{{ entityConfig.support_website }}" />
{% if entityConfig._support_website == -2 %}
<div class="green">{{ __('Inheritance of the parent entity') }}</div>
{% endif %}
</td>
</tr>
<tr class='tab_bg_1'>
Expand All @@ -34,6 +46,9 @@
</td>
<td>
<input name="support_email" value="{{ entityConfig.support_email }}" />
{% if entityConfig._support_email == -2 %}
<div class="green">{{ __('Inheritance of the parent entity') }}</div>
{% endif %}
</td>
<td>
</td>
Expand Down

0 comments on commit c4b02a3

Please sign in to comment.