Skip to content

Commit

Permalink
Merge pull request #1686 from LiveHelperChat/master-forms
Browse files Browse the repository at this point in the history
Forms tight integration
  • Loading branch information
remdex committed Sep 10, 2021
2 parents 6379404 + 0e64cf5 commit b6128de
Show file tree
Hide file tree
Showing 17 changed files with 451 additions and 182 deletions.
2 changes: 1 addition & 1 deletion lhc_web/design/defaulttheme/js/widgetv2/react.app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lhc_web/design/defaulttheme/js/widgetv2/react.app.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php if ((isset($async_call) && $async_call == true) || (isset($chat_started_now) && isset($chat_started_now) == true)) : ?>

<?php if (!(isset($react) && $react == true)) : ?>
<div class="meta-message-<?php echo $messageId?>">
<script data-bot-action="execute-js" <?php if (isset($metaMessage['chat_emit'])) : ?>data-bot-emit='<?php echo $metaMessage['chat_emit']?>'<?php endif; ?> <?php if (isset($metaMessage['chat_event'])) : ?>data-bot-event='<?php echo $metaMessage['chat_event']?>'<?php endif; ?> <?php if (isset($metaMessage['ext_args'])) : ?>data-bot-args='<?php echo $metaMessage['ext_args']?>'<?php endif; ?> <?php if (isset($metaMessage['ext_execute'])) : ?>data-bot-extension="<?php echo $metaMessage['ext_execute']?>"<?php endif;?> >
<?php endif; ?>

<script class="meta-message-<?php echo $messageId?>" data-bot-action="execute-js" <?php if (isset($metaMessage['chat_emit'])) : ?>data-bot-emit='<?php echo $metaMessage['chat_emit']?>'<?php endif; ?> <?php if (isset($metaMessage['chat_event'])) : ?>data-bot-event='<?php echo $metaMessage['chat_event']?>'<?php endif; ?> <?php if (isset($metaMessage['ext_args'])) : ?>data-bot-args='<?php echo $metaMessage['ext_args']?>'<?php endif; ?> <?php if (isset($metaMessage['ext_execute'])) : ?>data-bot-extension="<?php echo $metaMessage['ext_execute']?>"<?php endif;?> >
<?php if (isset($metaMessage['ext_execute'])) : ?>
lhinst.executeExtension(<?php echo json_encode($metaMessage['ext_execute'])?>,<?php echo json_encode(json_decode($metaMessage['ext_args'],true))?>);
<?php elseif (isset($metaMessage['payload'])) : ?>
<?php echo $metaMessage['payload']?>
<?php endif; ?>
</script>

<?php if (!(isset($react) && $react == true)) : ?>
</div>
<?php endif; ?>

<?php endif; ?>
4 changes: 2 additions & 2 deletions lhc_web/design/defaulttheme/tpl/pagelayouts/userchat2.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@
($detect->version('Firefox') !== false && $detect->version('Firefox',Mobile_Detect::VERSION_TYPE_FLOAT) < 35)
) : ?>
<?php if (!isset($Result['voice_call'])) : ?>
<script <?php isset($Result['app_scope']) ? print 'scope="' . htmlspecialchars($Result['app_scope']) . '"' : '' ?> src="<?php echo erLhcoreClassDesign::design('js/widgetv2/react.app.ie.js')?>?t=207"></script>
<script <?php isset($Result['app_scope']) ? print 'scope="' . htmlspecialchars($Result['app_scope']) . '"' : '' ?> src="<?php echo erLhcoreClassDesign::design('js/widgetv2/react.app.ie.js')?>?t=208"></script>
<?php else : ?>
<script <?php isset($Result['app_scope']) ? print 'scope="' . htmlspecialchars($Result['app_scope']) . '"' : '' ?> src="<?php echo erLhcoreClassDesign::design('js/voice/voice.call.js')?>?t=2"></script>
<?php endif; ?>
<?php else : ?>
<?php if (!isset($Result['voice_call'])) : ?>
<script <?php isset($Result['app_scope']) ? print 'scope="' . htmlspecialchars($Result['app_scope']) . '"' : '' ?> src="<?php echo erLhcoreClassDesign::design('js/widgetv2/react.app.js')?>?t=207"></script>
<script <?php isset($Result['app_scope']) ? print 'scope="' . htmlspecialchars($Result['app_scope']) . '"' : '' ?> src="<?php echo erLhcoreClassDesign::design('js/widgetv2/react.app.js')?>?t=208"></script>
<?php else : ?>
<script <?php isset($Result['app_scope']) ? print 'scope="' . htmlspecialchars($Result['app_scope']) . '"' : '' ?> src="<?php echo erLhcoreClassDesign::design('js/voice/voice.call.js')?>?t=2"></script>
<?php endif; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { helperFunctions } from "../lib/helperFunctions";

class ChatMessage extends PureComponent {

state = {
jsExecuted : false
}

constructor(props) {
super(props);
this.abstractClick = this.abstractClick.bind(this);
Expand Down Expand Up @@ -280,7 +284,19 @@ class ChatMessage extends PureComponent {
}

} else if (domNode.name && domNode.name === 'script' && domNode.attribs['data-bot-action']) {

// Execute JS only once
// Happens if new message indicator is passed
// We rerender elements, but we should execute JS
if (this.state.jsExecuted == true) {
return <React.Fragment></React.Fragment>;
}

this.setState({jsExecuted : true});
parseScript(domNode, this);

// Return empty element
return <React.Fragment></React.Fragment>;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ class OnlineChat extends Component {
}
var lastChild = block.lastChild;

if (lastChild) {
// Checking not null not enough, because element can be text type
if (lastChild && typeof lastChild.getElementsByClassName !== 'undefined') {
x = lastChild.getElementsByClassName("meta-auto-hide");
var i;
for (i = 0; i < x.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { endChat, initChatUI, pageUnload, storeSubscriber, initProactive, checkChatStatus, fetchMessages, addMessage } from "../actions/chatActions"
import { endChat, initChatUI, pageUnload, storeSubscriber, initProactive, checkChatStatus, fetchMessages, addMessage, updateTriggerClicked } from "../actions/chatActions"
import { helperFunctions } from "../lib/helperFunctions";
import i18n from "../i18n";

Expand Down Expand Up @@ -201,6 +201,26 @@ export default function (dispatch, getState) {
} else if (action == 'lhc_load_ext') {
const parts = e.data.replace('lhc_load_ext:','').split('::');
executeExtension(parts[0],JSON.parse(parts[1]));
} else if (action == 'lhc_trigger_click') {
const parts = e.data.replace('lhc_trigger_click:','').split('::');
dispatch(updateTriggerClicked(
{'type': '/(type)/manualtrigger'},
{'payload':parts[0]}
)).then((data) => {
if (data.data.t) {
helperFunctions.sendMessageParent('botTrigger', [{'trigger' : data.data.t}]);
// Update messages
const state = getState();
if (state.chatwidget.hasIn(['chatData','id'])) {
dispatch(fetchMessages({
'chat_id': state.chatwidget.getIn(['chatData','id']),
'hash' : state.chatwidget.getIn(['chatData','hash']),
'lmgsid' : state.chatwidget.getIn(['chatLiveData','lmsgid']),
'theme' : state.chatwidget.get('theme')
}));
}
}
});
} else if (action == 'lhc_event') {
const parts = e.data.replace('lhc_event:','').split('::');
let args = JSON.parse(parts[1]);
Expand Down
82 changes: 82 additions & 0 deletions lhc_web/lib/core/lhabstract/fields/erlhabstractmodelform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

return array(
'name' => array(
'type' => 'text',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','Name for personal purposes'),
'required' => true,
'link' => erLhcoreClassDesign::baseurl('form/collected'),
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
)),
'content' => array(
'type' => 'textarea',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','Content'),
'required' => false,
'ace_editor' => 'html',
'hidden' => true,
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
)),
'name_attr' => array (
'type' => 'text',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','Name attributes'),
'required' => false,
'hidden' => true,
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
)),
'intro_attr' => array (
'type' => 'text',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','Introduction attributes'),
'required' => false,
'hidden' => true,
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
)),
'xls_columns' => array (
'type' => 'textarea',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','XLS Columns'),
'required' => false,
'height' => '100px',
'hidden' => true,
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
)),
'recipient' => array (
'type' => 'text',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','Recipient'),
'required' => false,
'hidden' => true,
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
)),
'post_content' => array(
'type' => 'textarea',
'ace_editor' => 'html',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','Post content after form is submitted'),
'required' => false,
'hidden' => true,
'height' => '150px',
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
)),
'pagelayout' => array (
'type' => 'text',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','Custom pagelayout'),
'required' => false,
'hidden' => true,
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
)),
'active' => array (
'type' => 'checkbox',
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation','Active'),
'required' => false,
'hidden' => true,
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'boolean'
))
);

?>
2 changes: 0 additions & 2 deletions lhc_web/lib/core/lhabstract/lhabstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ public static function renderInput($name, $attr, $object, $defaultValue = '')

$ngModel = isset($attr['nginit']) ? ' ng-init=\'ngModelAbstractInput_' . $name . '=' . json_encode($value, JSON_HEX_APOS) . '\' ng-model="ngModelAbstractInput_' . $name . '" ' : 'ng-non-bindable';



$aceEditor = isset($attr['ace_editor']) ? ' data-editor="'.$attr['ace_editor'].'" ' : '';

return '<textarea style="height:' . $height . ';" ' . $placeholder . ' ' . $ngModel . ' ' . $aceEditor . ' class="form-control' . (isset($attr['css_class']) ? ' '.$attr['css_class'] : '') . '" name="AbstractInput_' . $name . '">' . htmlspecialchars($value) . '</textarea>';
Expand Down
10 changes: 6 additions & 4 deletions lhc_web/lib/core/lhcore/lhfileupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
$msg->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0;

// We save instantly as message only visitors files
if ($msg->user_id == 0) {
if ($msg->user_id == 0 || (isset($this->options['as_form']) && $this->options['as_form'] == true)) {

$chat->last_user_msg_time = $msg->time = time();

Expand All @@ -110,11 +110,13 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
$chat->last_msg_id = $msg->id;
}

if ($chat->gbot_id > 0 && (!isset($chat->chat_variables_array['gbot_disabled']) || $chat->chat_variables_array['gbot_disabled'] == 0)) {
erLhcoreClassGenericBotWorkflow::userMessageAdded($chat, $msg);
if ($msg->user_id == 0) {
if ($chat->gbot_id > 0 && (!isset($chat->chat_variables_array['gbot_disabled']) || $chat->chat_variables_array['gbot_disabled'] == 0)) {
erLhcoreClassGenericBotWorkflow::userMessageAdded($chat, $msg);
}
$chat->has_unread_messages = 1;
}

$chat->has_unread_messages = 1;
$chat->updateThis(array('update' => array('last_user_msg_time','last_msg_id','has_unread_messages')));

erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.addmsguser',array('file' => $fileUpload, 'msg' => & $msg, 'chat' => & $chat));
Expand Down
Loading

0 comments on commit b6128de

Please sign in to comment.