Skip to content

Commit

Permalink
Translations and new custom forms
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Apr 9, 2015
1 parent 321214b commit a547aa9
Show file tree
Hide file tree
Showing 41 changed files with 1,271 additions and 668 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
lhcAppControllers.controller('StartChatFormCtrl',['$scope','$http','$location','$rootScope', '$log', function($scope, $http, $location, $rootScope, $log) {

this.startchatfields = [];
this.size = 6;
this.fieldtype = 'text';
this.visibility = 'all';

var that = this;

this.move = function(element, offset) {
index = that.startchatfields.indexOf(element);
newIndex = index + offset;
if (newIndex > -1 && newIndex < that.startchatfields.length){
removedElement = that.startchatfields.splice(index, 1)[0];
that.startchatfields.splice(newIndex, 0, removedElement)
}
};

this.addField = function() {
that.startchatfields.push({
'fieldname' : that.fieldname,
'defaultvalue' : that.defaultvalue,
'fieldtype' : that.fieldtype,
'visibility' : that.visibility,
'size' : that.size,
'isrequired' : that.isrequired
});
};

this.deleteField = function(field) {
that.startchatfields.splice(that.startchatfields.indexOf(field),1);
};

this.deleteField = function(field) {
that.startchatfields.splice(that.startchatfields.indexOf(field),1);
};

this.moveLeftField = function(field) {
that.move(field,-1);
}

this.moveRightField = function(field) {
that.move(field,1);
}


}]);
3 changes: 3 additions & 0 deletions lhc_web/design/defaulttheme/tpl/lhchat/chatwidget.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<?php endif; ?>
<?php else : $hasExtraField = true; endif; ?>

<?php $adminCustomFieldsMode = 'on';?>
<?php include(erLhcoreClassDesign::designtpl('lhchat/part/admin_form_variables.tpl.php'));?>

<?php include_once(erLhcoreClassDesign::designtpl('lhchat/part/user_variables.tpl.php'));?>

<?php if ($department === false) : ?>
Expand Down
3 changes: 3 additions & 0 deletions lhc_web/design/defaulttheme/tpl/lhchat/offline_form.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<?php endif; ?>
<?php endif; ?>

<?php $adminCustomFieldsMode = 'off';?>
<?php include(erLhcoreClassDesign::designtpl('lhchat/part/admin_form_variables.tpl.php'));?>

<?php $modeUserVariables = 'off'; ?>
<?php include_once(erLhcoreClassDesign::designtpl('lhchat/part/user_variables.tpl.php'));?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<?php endif;?>
<?php endif;?>

<?php $adminCustomFieldsMode = 'off';?>
<?php include(erLhcoreClassDesign::designtpl('lhchat/part/admin_form_variables.tpl.php'));?>

<?php include_once(erLhcoreClassDesign::designtpl('lhchat/part/user_variables.tpl.php'));?>

<?php if ($department === false) : ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php if (isset($start_data_fields['custom_fields']) && $start_data_fields['custom_fields'] != '') :
$customAdminfields = json_decode($start_data_fields['custom_fields'],true);
if (is_array($customAdminfields)) : ?>
<div class="row">
<?php foreach ($customAdminfields as $key => $adminField) : if ($adminField['visibility'] == 'all' || $adminCustomFieldsMode == $adminField['visibility']) : ?>
<?php if ($adminField['fieldtype'] == 'hidden') : ?>
<input class="form-control" type="hidden" name="value_items_admin[<?php echo $key?>]" value="<?php isset($input_data->value_items_admin[$key]) ? print htmlspecialchars($input_data->value_items_admin[$key]) : print htmlspecialchars($adminField['defaultvalue'])?>" />
<?php else : $hasExtraField = true; ?>
<div class="col-xs-<?php echo htmlspecialchars($adminField['size'])?>">
<div class="form-group">
<label><?php echo htmlspecialchars($adminField['fieldname'])?>&nbsp;<?php $adminField['isrequired'] == 'true' ? print '*' : ''?></label>
<input class="form-control" type="text" name="value_items_admin[<?php echo $key?>]" value="<?php isset($input_data->value_items_admin[$key]) ? print htmlspecialchars($input_data->value_items_admin[$key]) : print htmlspecialchars($adminField['defaultvalue'])?>" />
</div>
</div>
<?php endif; endif; endforeach;?>
</div>
<?php endif; endif;?>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@

<?php if ($visitor->requires_username == 1 || $visitor->requires_email == 1 || $visitor->requires_phone == 1) : ?></div><?php endif;?>

<?php include_once(erLhcoreClassDesign::designtpl('lhchat/part/user_variables.tpl.php'));?>
<?php $adminCustomFieldsMode = 'on';?>
<?php include(erLhcoreClassDesign::designtpl('lhchat/part/admin_form_variables.tpl.php'));?>

<?php include(erLhcoreClassDesign::designtpl('lhchat/part/user_variables.tpl.php'));?>

<?php if ($department === false) : ?>
<?php include_once(erLhcoreClassDesign::designtpl('lhchat/part/department.tpl.php'));?>
Expand Down
5 changes: 4 additions & 1 deletion lhc_web/design/defaulttheme/tpl/lhchat/startchat.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
<?php endif; ?>
<?php endif; ?>

<?php include_once(erLhcoreClassDesign::designtpl('lhchat/part/user_variables.tpl.php'));?>
<?php $adminCustomFieldsMode = 'on';?>
<?php include(erLhcoreClassDesign::designtpl('lhchat/part/admin_form_variables.tpl.php'));?>

<?php include(erLhcoreClassDesign::designtpl('lhchat/part/user_variables.tpl.php'));?>

<?php include(erLhcoreClassDesign::designtpl('lhchat/part/user_timezone.tpl.php'));?>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<p><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Custom fields generator, these fields will be visible in start chat forms')?></p>

<div ng-controller="StartChatFormCtrl as startChat" <?php if (isset($start_chat_data['custom_fields']) && $start_chat_data['custom_fields'] != '') : ?> ng-init='startChat.startchatfields = <?php echo $start_chat_data['custom_fields']?>'<?php endif;?>>

<div class="row">
<div class="col-xs-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Field label')?></label> <input ng-model="startChat.fieldname" class="form-control" ng-model="" type="text" name="" value="" />
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Default value')?></label> <input ng-model="startChat.defaultvalue" class="form-control" type="text" name="" value="" />
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Type')?></label> <select ng-model="startChat.fieldtype" class="form-control">
<option value="text"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Text')?></option>
<option value="hidden"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Hidden')?></option>
</select>
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Visible on')?></label> <select ng-model="startChat.visibility" class="form-control">
<option value="all"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Offline and online form')?></option>
<option value="off"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Only offline')?></option>
<option value="on"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Only online')?></option>
</select>
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Size (between 1 and 12)')?></label> <input ng-model="startChat.size" class="form-control" type="text" name="" value="6" />
</div>
</div>
<div class="col-xs-3">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Is required')?> <input ng-model="startChat.isrequired" type="checkbox" name="isRequired" /></label>
</div>

<div class="col-xs-6">
<input type="button" class="btn btn-default col-xs-12" ng-click="startChat.addField()" value="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Add a field')?>" />
</div>
</div>
<hr>

<div class="row">
<div ng-repeat="field in startChat.startchatfields" class="col-xs-{{field.size}}">
<div class="form-group">
<div class="btn-group pull-right" role="group" aria-label="...">
<button ng-if="$index > 0" type="button" class="btn btn-default btn-xs" ng-click="startChat.moveLeftField(field)">&laquo; <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','left')?></button>
<button ng-if="$index < startChat.startchatfields.length-1" type="button" class="btn btn-default btn-xs" ng-click="startChat.moveRightField(field)"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','right')?> &raquo;</button>
</div>
<label>{{field.fieldname}}{{field.isrequired ? '*' : ''}}</label> <input class="form-control" type="text" value="{{field.defaultvalue}}" readonly="readonly">
<ul class="list-unstyled pt10">
<li ng-if="field.visibility == 'off'"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Visible only in offline form')?></li>
<li ng-if="field.visibility == 'on'"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Visible only in online form')?></li>
<li><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Size')?> - {{field.size}}</li>
<li><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Type')?> - {{field.fieldtype}}</li>
</ul>
<button type="button" class="btn btn-danger btn-xs" ng-click="startChat.deleteField(field)"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Remove')?></button>
</div>
<input type="hidden" name="customFieldLabel[]" value="{{field.fieldname}}" />
<input type="hidden" name="customFieldType[]" value="{{field.fieldtype}}" />
<input type="hidden" name="customFieldSize[]" value="{{field.size}}" />
<input type="hidden" name="customFieldVisibility[]" value="{{field.visibility}}" />
<input type="hidden" name="customFieldIsrequired[]" value="{{field.isrequired}}" />
<input type="hidden" name="customFieldDefaultValue[]" value="{{field.defaultvalue}}" />
</div>
</div>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<li role="presentation" class="active"><a href="#panel1" aria-controls="panel1" role="tab" data-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Online form settings');?></a></li>
<li role="presentation"><a href="#panel2" aria-controls="panel12" role="tab" data-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Offline form settings');?></a></li>
<li role="presentation"><a href="#panel3" aria-controls="panel13" role="tab" data-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Additional form settings');?></a></li>
<li role="presentation"><a href="#customfields" aria-controls="customfields" role="tab" data-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Custom fields');?></a></li>
</ul>

<!-- Tab panes -->
Expand Down Expand Up @@ -170,5 +171,10 @@
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchatformsettings','Initial user message height in pixels');?></label> <input class="form-control" type="text" name="UserMessageHeight" value="<?php (isset($start_chat_data['user_msg_height'])) ? print htmlspecialchars($start_chat_data['user_msg_height']) : ''?>" />
</div>
</div>

<div role="tabpanel" class="tab-pane" id="customfields">
<?php include(erLhcoreClassDesign::designtpl('lhchat/startchatformsettings/custom_fields.tpl.php'));?>
</div>

</div>
</div>
46 changes: 41 additions & 5 deletions lhc_web/lib/core/lhchat/lhchatvalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ public static function validateStartChat(& $inputForm, & $start_data_fields, & $
$validationFields[$nameField] = new ezcInputFormDefinitionElement( ezcInputFormDefinitionElement::OPTIONAL, 'string' );
}

// Custom start chat fields
$validationFields['value_items_admin'] = new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw',
null,
FILTER_REQUIRE_ARRAY
);


$form = new ezcInputForm( INPUT_POST, $validationFields );
$Errors = array();

Expand Down Expand Up @@ -218,7 +226,7 @@ public static function validateStartChat(& $inputForm, & $start_data_fields, & $
$chat->email = $inputForm->email = $_POST['Email'];
}
}

// Validate question
if (isset($validationFields['Question'])) {

Expand Down Expand Up @@ -339,6 +347,7 @@ public static function validateStartChat(& $inputForm, & $start_data_fields, & $
}
}

$stringParts = array();

if ( $form->hasValidData( 'name_items' ) && !empty($form->name_items))
{
Expand Down Expand Up @@ -374,17 +383,44 @@ public static function validateStartChat(& $inputForm, & $start_data_fields, & $
}

$inputForm->name_items = $form->name_items;

$stringParts = array();

foreach ($form->name_items as $key => $name_item) {
if (isset($inputForm->values_req[$key]) && $inputForm->values_req[$key] == 't' && ($inputForm->value_show[$key] == 'b' || $inputForm->value_show[$key] == (isset($additionalParams['offline']) ? 'off' : 'on')) && (!isset($valuesArray[$key]) || trim($valuesArray[$key]) == '')) {
$Errors[] = trim($name_item).' : '.erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat','is required');
}
$stringParts[] = array('key' => $name_item,'value' => (isset($valuesArray[$key]) ? trim($valuesArray[$key]) : ''));
}
}
}


$chat->additional_data = json_encode($stringParts);
if (isset($start_data_fields['custom_fields']) && $start_data_fields['custom_fields'] != '') {
$customAdminfields = json_decode($start_data_fields['custom_fields'],true);

$valuesArray = array();

// Fill values if exists
if ($form->hasValidData( 'value_items_admin' )){
$inputForm->value_items_admin = $valuesArray = $form->value_items_admin;
}

if (is_array($customAdminfields)){
foreach ($customAdminfields as $key => $adminField) {

if (isset($inputForm->value_items_admin[$key]) && isset($adminField['isrequired']) && $adminField['isrequired'] == 'true' && ($adminField['visibility'] == 'all' || $adminField['visibility'] == (isset($additionalParams['offline']) ? 'off' : 'on')) && (!isset($valuesArray[$key]) || trim($valuesArray[$key]) == '')) {
$Errors[] = trim($adminField['fieldname']).': '.erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat','is required');
}

if (isset($valuesArray[$key]) && $valuesArray[$key] != '') {
$stringParts[] = array('key' => $adminField['fieldname'], 'value' => (isset($valuesArray[$key]) ? trim($valuesArray[$key]) : ''));
}
}
}
}

if (!empty($stringParts)) {
$chat->additional_data = json_encode($stringParts);
}


erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.validate_start_chat',array('errors' => & $Errors, 'input_form' => & $inputForm, 'start_data_fields' => & $start_data_fields, 'chat' => & $chat,'additional_params' => & $additionalParams));

Expand Down
1 change: 1 addition & 0 deletions lhc_web/modules/lhchat/chatwidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
$inputData->value_items = array();
$inputData->value_sizes = array();
$inputData->value_types = array();
$inputData->value_items_admin = array(); // These variables get's filled from start chat form settings
$inputData->hattr = array();
$inputData->ua = $Params['user_parameters_unordered']['ua'];
$inputData->priority = is_numeric($Params['user_parameters_unordered']['priority']) ? (int)$Params['user_parameters_unordered']['priority'] : false;
Expand Down
Loading

0 comments on commit a547aa9

Please sign in to comment.