Skip to content

Commit

Permalink
Ticket unacms#2878 - Selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Jul 22, 2020
1 parent b9d9a30 commit 4abc14e
Show file tree
Hide file tree
Showing 24 changed files with 759 additions and 103 deletions.
44 changes: 42 additions & 2 deletions inc/classes/BxDolLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ class BxDolLabel extends BxDolFactory implements iBxDolSingleton
{
protected $_oDb;

protected $_sForm;
protected $_sFormDisplaySelect;

protected function __construct()
{
parent::__construct();

$this->_oDb = new BxDolLabelQuery();

$this->_sForm= 'sys_labels';
$this->_sFormDisplaySelect = 'sys_labels_select';
}

public function __clone()
Expand All @@ -24,14 +30,48 @@ public function __clone()
trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
}

public static function getInstance()
public static function getInstance($oTemplate = false)
{
if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
$GLOBALS['bxDolClasses'][__CLASS__] = new BxDolLabel();
$GLOBALS['bxDolClasses'][__CLASS__] = new BxTemplLabel($oTemplate);

return $GLOBALS['bxDolClasses'][__CLASS__];
}

public function actionSelectLabels()
{
return echoJson($this->selectLabels(array(
'list' => bx_get('value')
)));
}

public function actionLabelsList()
{
$sTerm = bx_get('term');

$aLabels = $this->getLabels(array('type' => 'term', 'term' => $sTerm));

$aResult = array();
foreach($aLabels as $aLabel)
$aResult[] = array (
'label' => $aLabel['value'],
'value' => $aLabel['value'],
);

echoJson($aResult);
}

public function getElementLabels($aInput = array())
{
$oForm = BxDolForm::getObjectInstance($this->_sForm, $this->_sFormDisplaySelect);
if(!$oForm)
return '';

$aInput['attrs']['id'] = $this->_aHtmlIds['labels_element'];

return $oForm->getElementLabels($aInput);
}

public function getLabels($aParams = array())
{
return $this->_oDb->getLabels($aParams);
Expand Down
11 changes: 9 additions & 2 deletions inc/classes/BxDolLabelQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public function getLabels($aParams = array())
$sWhereClause .= " AND `tl`.`id` NOT IN(" . $this->implode_escape($aParams['exclude']) . ")";
break;

case 'term':
$aMethod['params'][1] = array(
'term' => '%' . $aParams['term'] . '%'
);

$sWhereClause = " AND `tl`.`value` LIKE :term";
break;

case 'parent_order':
$aMethod['name'] = 'getOne';
$aMethod['params'][1] = array(
Expand All @@ -92,8 +100,7 @@ public function getLabels($aParams = array())
WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause;

return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
}

}
}

/** @} */
91 changes: 91 additions & 0 deletions inc/js/classes/BxDolLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCore UNA Core
* @{
*/

function BxDolLabel(oOptions) {
this._sObjName = oOptions.sObjName == undefined ? 'oBxDolLabel' : oOptions.sObjName;

this._sRootUrl = oOptions.sRootUrl == undefined ? sUrlRoot : oOptions.sRootUrl;
this._sActionsUrl = this._sRootUrl + 'label.php'; // actions url address

this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;

this._sClassItem = 'sys-labels-list-item';
this._sClassSublist = 'sys-labels-li-sublist';
}

// TODO: Continue from here: preload selected.
BxDolLabel.prototype.selectLabels = function(oElement, aParams)
{
var $this = this;

var aValue = new Array();
$(oElement).find('input:hidden').each(function() {
aValue.push($(this).val());
});

var oData = $.extend({}, $this._getDefaultParams(), {action: 'select_labels', value: aValue}, (aParams || {}));

this._loadingInFormElement(oElement, true);

$.get(
this._sActionsUrl,
oData,
function(oData) {
$this._loadingInFormElement(oElement, false);

processJsonData(oData);
},
'json'
);
};

BxDolLabel.prototype.onSelectLabels = function(oData)
{
if(oData.content != undefined)
$('#' + this._aHtmlIds['labels_element']).replaceWith(oData.content);
};

BxDolLabel.prototype.showSublist = function(oLink)
{
$(oLink).find('.sys-icon').toggleClass('chevron-down').toggleClass('chevron-up').parents('.' + this._sClassItem + ':first').find('.' + this._sClassSublist + ':first').bx_anim('toggle', this._sAnimationEffect, this._iAnimationSpeed);
};

BxDolLabel.prototype._loading = function(e, bShow)
{
var oParent = $(e).length ? $(e) : $('body');
bx_loading(oParent, bShow);
};

BxDolLabel.prototype._loadingInBlock = function(e, bShow)
{
var oParent = $(e).length ? $(e).parents('.bx-db-content:first') : $('body');
bx_loading(oParent, bShow);
};

BxDolLabel.prototype._loadingInFormElement = function(e, bShow)
{
var oParent = $(e).length ? $(e).parents('.bx-form-element:first') : $('body');
bx_loading(oParent, bShow);
};

BxDolLabel.prototype._getSelectLabelsElement = function()
{
return $('#' + this._aHtmlIds['form'] + ' #' + this._aHtmlIds['labels_element'] + ' input');
};

BxDolLabel.prototype._getDefaultParams = function()
{
var oDate = new Date();
return {
_t: oDate.getTime()
};
};

/** @} */
16 changes: 16 additions & 0 deletions install/sql/system.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3104,6 +3104,7 @@ INSERT INTO `sys_objects_form` (`object`, `module`, `title`, `action`, `form_att
('sys_review', 'system', '_sys_form_review', 'cmts.php', 'a:3:{s:2:"id";s:17:"cmt-%s-form-%s-%d";s:4:"name";s:17:"cmt-%s-form-%s-%d";s:5:"class";s:14:"cmt-post-reply";}', 'cmt_submit', '', 'cmt_id', '', '', '', 0, 1, 'BxTemplCmtsReviewsForm', ''),
('sys_report', 'system', '_sys_form_report', 'report.php', 'a:3:{s:2:"id";s:0:"";s:4:"name";s:0:"";s:5:"class";s:17:"bx-report-do-form";}', 'submit', '', 'id', '', '', '', 0, 1, '', ''),
('sys_privacy_group_custom', 'system', '_sys_form_ps_group_custom', 'privacy.php', '', 'do_submit', 'sys_privacy_groups_custom', 'id', '', '', '', 0, 1, 'BxTemplPrivacyFormGroupCustom', ''),
('sys_labels', 'system', '_sys_form_labels', 'label.php', '', 'do_submit', '', '', '', '', '', 0, 1, 'BxTemplLabelForm', ''),
('sys_wiki', 'system', '_sys_form_wiki', '', '', 'do_submit', 'sys_pages_wiki_blocks', 'id', '', '', '', 0, 1, 'BxTemplFormWiki', '');

CREATE TABLE IF NOT EXISTS `sys_form_displays` (
Expand Down Expand Up @@ -3138,6 +3139,7 @@ INSERT INTO `sys_form_displays` (`display_name`, `module`, `object`, `title`, `v
('sys_review_edit', 'system', 'sys_review', '_sys_form_review_display_edit', 0),
('sys_report_post', 'system', 'sys_report', '_sys_form_display_report_post', 0),
('sys_privacy_group_custom_manage', 'system', 'sys_privacy_group_custom', '_sys_form_display_ps_gc_manage', 0),
('sys_labels_select', 'system', 'sys_labels', '_sys_form_labels_display_select', 0),
('sys_wiki_edit', 'system', 'sys_wiki', '_sys_form_display_wiki_edit', 0),
('sys_wiki_translate', 'system', 'sys_wiki', '_sys_form_display_wiki_translate', 0);

Expand Down Expand Up @@ -3261,6 +3263,13 @@ INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `c
('sys_privacy_group_custom', 'system', 'do_submit', '_sys_form_ps_gc_input_caption_do_submit', '', 0, 'submit', '_sys_form_ps_gc_input_caption_system_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
('sys_privacy_group_custom', 'system', 'do_cancel', '_sys_form_ps_gc_input_caption_do_cancel', '', 0, 'button', '_sys_form_ps_gc_input_caption_system_do_cancel', '', '', 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', '', '', '', '', '', 0, 0),

('sys_labels', 'system', 'action', '', '', 0, 'hidden', '_sys_form_labels_input_caption_system_action', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
('sys_labels', 'system', 'search', '', '', 0, 'custom', '_sys_form_labels_input_caption_system_search', '_sys_form_labels_input_caption_search', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
('sys_labels', 'system', 'list', '', '', 0, 'custom', '_sys_form_labels_input_caption_system_list', '_sys_form_labels_input_caption_list', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
('sys_labels', 'system', 'controls', '', 'do_submit,do_cancel', 0, 'input_set', '', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
('sys_labels', 'system', 'do_submit', '_sys_form_labels_input_caption_do_submit', '', 0, 'submit', '_sys_form_labels_input_caption_system_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
('sys_labels', 'system', 'do_cancel', '_sys_form_labels_input_caption_do_cancel', '', 0, 'button', '_sys_form_labels_input_caption_system_do_cancel', '', '', 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', '', '', '', '', '', 0, 0),

('sys_wiki', 'system', 'block_id', '', '', 0, 'hidden', '', '_sys_form_wiki_input_caption_block_id', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 0, 0),
('sys_wiki', 'system', 'language', '', '', 0, 'radio_set', '', '_sys_form_wiki_input_caption_lang', '_sys_form_wiki_input_caption_lang_info', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 0),
('sys_wiki', 'system', 'content_main', '', '', 0, 'custom', '', '_sys_form_wiki_input_caption_content_main', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
Expand Down Expand Up @@ -3417,6 +3426,13 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
('sys_privacy_group_custom_manage', 'do_submit', 2147483647, 1, 9),
('sys_privacy_group_custom_manage', 'do_cancel', 2147483647, 1, 10),

('sys_labels_select', 'action', 2147483647, 1, 1),
('sys_labels_select', 'search', 2147483647, 1, 2),
('sys_labels_select', 'list', 2147483647, 1, 3),
('sys_labels_select', 'controls', 2147483647, 1, 4),
('sys_labels_select', 'do_submit', 2147483647, 1, 5),
('sys_labels_select', 'do_cancel', 2147483647, 1, 6),

('sys_wiki_edit', 'block_id', 2147483647, 1, 1),
('sys_wiki_edit', 'language', 2147483647, 1, 2),
('sys_wiki_edit', 'content', 2147483647, 1, 3),
Expand Down
28 changes: 28 additions & 0 deletions label.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCore UNA Core
* @{
*/

require_once('./inc/header.inc.php');
require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");

bx_import('BxDolLanguages');

check_logged();

$sAction = isset($_REQUEST['action']) && preg_match ('/^[A-Za-z_-]+$/', $_REQUEST['action']) ? bx_process_input($_REQUEST['action']) : '';

$oLabel = BxDolLabel::getInstance();

if($oLabel && $sAction) {
header('Content-Type: text/html; charset=utf-8');
$sMethod = 'action' . bx_gen_method_name($sAction);
if(method_exists($oLabel, $sMethod))
echo $oLabel->$sMethod();
}

/** @} */
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaTemplate UNA Template Classes
* @{
*/

/**
* @see BxDolLabel
*/
class BxTemplLabel extends BxBaseLabel
{
}

/** @} */
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaTemplate UNA Template Classes
* @{
*/

class BxTemplLabelForm extends BxBaseLabelForm
{
}

/** @} */
11 changes: 11 additions & 0 deletions modules/boonex/english/data/langs/system/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,17 @@ If it is not enabled then please consider implement this optimization, since it
<string name="_sys_form_input_labels"><![CDATA[Labels]]></string>
<string name="_sys_form_input_sys_anonymous"><![CDATA[Post as anonymous]]></string>
<string name="_sys_form_input_anonymous"><![CDATA[Post as anonymous]]></string>
<string name="_sys_form_labels"><![CDATA[Labels]]></string>
<string name="_sys_form_labels_display_select"><![CDATA[Select labels display]]></string>
<string name="_sys_form_labels_input_caption_system_action"><![CDATA[Action]]></string>
<string name="_sys_form_labels_input_caption_system_search"><![CDATA[Search]]></string>
<string name="_sys_form_labels_input_caption_search"><![CDATA[Search]]></string>
<string name="_sys_form_labels_input_caption_system_list"><![CDATA[List]]></string>
<string name="_sys_form_labels_input_caption_list"><![CDATA[or select]]></string>
<string name="_sys_form_labels_input_caption_do_submit"><![CDATA[Submit]]></string>
<string name="_sys_form_labels_input_caption_system_do_submit"><![CDATA[Submit]]></string>
<string name="_sys_form_labels_input_caption_do_cancel"><![CDATA[Cancel]]></string>
<string name="_sys_form_labels_input_caption_system_do_cancel"><![CDATA[Cancel]]></string>
<string name="_sys_form_login"><![CDATA[Log in]]></string>
<string name="_sys_form_login_input_caption_system_agreement"><![CDATA[Agreement]]></string>
<string name="_sys_form_login_input_caption_system_captcha"><![CDATA[Captcha]]></string>
Expand Down
17 changes: 17 additions & 0 deletions modules/boonex/lucid/data/template/system/scripts/BxTemplLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaTemplate UNA Template Classes
* @{
*/

/**
* @see BxDolLabel
*/
class BxTemplLabel extends BxBaseLabel
{
}

/** @} */
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaTemplate UNA Template Classes
* @{
*/

class BxTemplLabelForm extends BxBaseLabelForm
{
}

/** @} */
17 changes: 17 additions & 0 deletions modules/boonex/ocean/data/template/system/scripts/BxTemplLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaTemplate UNA Template Classes
* @{
*/

/**
* @see BxDolLabel
*/
class BxTemplLabel extends BxBaseLabel
{
}

/** @} */
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaTemplate UNA Template Classes
* @{
*/

class BxTemplLabelForm extends BxBaseLabelForm
{
}

/** @} */
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaTemplate UNA Template Classes
* @{
*/

/**
* @see BxDolLabel
*/
class BxTemplLabel extends BxBaseLabel
{
}

/** @} */
Loading

0 comments on commit 4abc14e

Please sign in to comment.