Commit 75477276 authored by Chenu Denis's avatar Chenu Denis

[fix] 3.0 compat

parent ff20470d
......@@ -13,20 +13,20 @@ Allow to use a multi text question to get Postal code, town name and Insee code.
## Setup and activation
- During activation an new table is created and data is set up in this table.
- If your hoster have very limited time for PHP scriot : this can break.
- If your hoster have very limited time for PHP script : you can send yourself the DB
- You can set yourself the DB : name must be lime_cpville_insee_cp (lime_ must be replaced by real prefix) and column insee, nom, cp, nomsimple.
- You can add another column : then this can prefill specific subquestion.
- You can add another column : this can prefill specific subquestion with same code.
- If needed : you can update the database your way.
## Documentation
In a multi text question type : set a Sub question with SaisieVille code launch a system to
In a multi text question type : set a Sub question with SaisieVille automatically launch a system to
- Allow user search for postal code or part of town name to fill the sub question
- Fill Extra sub question with code CodePostal with the postal code
- Fill Extra sub question with code Insee with the Insee code
- Fill Extra sub question with code Nom with the town name
- Fill Extra sub question with code as column name od the DB (you can test with region or departement)
Each code can be completed by some cararcter : this allow multiple SaisieVille in same question. For example SaisieVilleA, SaisieVilleB and InseeA, InseeB filled by insee code.
Plugin settings allow admin user to
Plugin settings allow admin user to
- Update the default sub question code and use awn code
- Choose the maximum number of lines returned
- Choose if extra sub question is shown or not
......@@ -34,15 +34,15 @@ Plugin settings allow admin user to
For user, some helper is done
- Search on postal code if only number is entered
- Search on multiple part : example `villen asc` for Villeneuve d'Ascq
- Search on multiple part : example villen asc
## Home page & Copyright
### Code
- HomePage <http://extensions.sondages.pro/cpville>
- HomePage <http://extensions.sondages.pro/>
- Copyright © 2015-2018 Denis Chenu <http://sondages.pro>
- Copyright © 2015 Observatoire Régional de la Santé (ORS) - Nord-Pas-de-Calais <http://www.orsnpdc.org/>
- copyright © 2016 Formations logiciels libres - 2i2l = 42 <http://2i2l.fr/>
- Copyright © 2015-2016 Denis Chenu <http://sondages.pro>
- Copyright © 2016 Formations logiciels libres - 2i2l = 42 <http://2i2l.fr/>
- Licence : GNU General Public License <https://www.gnu.org/licenses/gpl-3.0.html>
### Data
......
.saisieville input.text.readonly{
border:0 none;
box-shadow: 0 0 0 rgba(0, 0, 0, 0.2) inset;
}
.multiple-short-txt.saisieville .answers-wrapper{
overflow-x: visible;
}
.ui-autocomplete{z-index:2;position:absolute !important}
.ui-menu { list-style:none; padding: 2px; margin: 0; display:block; outline: none; }
.ui-menu .ui-menu { margin-top: -3px; position: absolute; }
.ui-menu .ui-menu-item { margin: 0; padding: 0; zoom: 1; width: 100%; }
.ui-menu .ui-menu-divider { margin: 5px -2px 5px -2px; height: 0; font-size: 0; line-height: 0; border-width: 1px 0 0 0; }
.ui-menu .ui-menu-item a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; }
.ui-menu .ui-menu-item a.ui-state-focus,
.ui-menu .ui-menu-item a.ui-state-active { font-weight: normal; margin: -1px; }
.ui-menu .ui-state-disabled { font-weight: normal; margin: .4em 0 .2em; line-height: 1.5; }
.ui-menu-icons { position: relative; }
.ui-menu-icons .ui-menu-item a { position: relative; padding-left: 2em; }
.ui-menu .ui-icon { position: absolute; top: .2em; left: .2em; }
.ui-menu .ui-menu-icon { position: static; float: right; }
.hidden {
display: none !important;
}
function autoCpVille(qId,options){
var answerLibels=$("#question"+qId+" input[name*='X"+qId+options.answerLibel+"']");
if(answerLibels.length>=1)
{
$(answerLibels).keypress(function(e) {
var code = e.keyCode || e.which;
if (code == 9) {
e.preventDefault();
}
});
var cache = {};
var baseLibel='X'+qId+options.answerLibel;
var baseLibelLength=baseLibel.length;
$(answerLibels).each(function(){
// Find final part
var thisid=$(this).attr("id");
var n=thisid.indexOf('X'+qId+options.answerLibel);
var endLibel=$(this).attr("id").substring($(this).attr("id").indexOf(baseLibel)+baseLibelLength);
// Set the options for each lines
var optionLines=[];
var optionShow=[];
if(options.answerCp){
optionLines.push("#question"+qId+" .answer-item[id$='X"+qId+options.answerCp+endLibel+"']");
optionShow.push(options.showCp);
}
if(options.answerInsee){
optionLines.push("#question"+qId+" .answer-item[id$='X"+qId+options.answerInsee+endLibel+"']");
optionShow.push(options.showInsee);
}
if(options.answerNom){
optionLines.push("#question"+qId+" .answer-item[id$='X"+qId+options.answerNom+endLibel+"']");
optionShow.push(0);
}
$.each(optionLines, function( index, value ) {
if(!optionShow[index])
{
$(value).hide();
$(value).addClass("hide").addClass("hidden");
}
$(value).find("input[type=text]").prop("readonly",true).addClass("readonly");
});
var parent=$(this).parent();
$(parent).css("position","relative");
$(this).autocomplete({
minLength: 1,
appendTo: parent,
position: {
my : "left top",
at: "left bottom",
collision: "flipfit"
},
source: function(request, response) {
$.ajax({
url: options.jsonurl,
dataType: "json",
data: {
term : request.term
},
success: function(data) {
response(data);
}
});
},
search: function (event, ui) {
$(this).addClass('autocomplete-search');
},
open: function (event, ui) {
$(this).removeClass('autocomplete-search');
},
change: function (event, ui) {
if(!ui.item){
$(this).val("");
$(optionLines.join(",")).each(function( index ) {
$(this).find("input[type=text]").val("").trigger('keyup').trigger('blur');
});
}
},
select: function( event, ui ) {
$.each(ui.item, function(key, value) {
$("input[type=text][name$='X"+qId+key+endLibel+"']").val(value).trigger('keyup').trigger('blur');
});
},
focus: function (event, ui) {
return false;
},
blur: function (event, ui) {
$(this).trigger("change");
return false;
}
});
});
}else{
$(optionLines.join(",")).each(function( index ) {
$(this).show();
});
}
}
.saisieville input.text.readonly{
border:0 none;
box-shadow: 0 0 0 rgba(0, 0, 0, 0.2) inset;
}
.ui-autocomplete{z-index:2;position:absolute !important}
.ui-menu { list-style:none; padding: 2px; margin: 0; display:block; outline: none; }
.ui-menu .ui-menu { margin-top: -3px; position: absolute; }
.ui-menu .ui-menu-item { margin: 0; padding: 0; zoom: 1; width: 100%; }
.ui-menu .ui-menu-divider { margin: 5px -2px 5px -2px; height: 0; font-size: 0; line-height: 0; border-width: 1px 0 0 0; }
.ui-menu .ui-menu-item a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; }
.ui-menu .ui-menu-item a.ui-state-focus,
.ui-menu .ui-menu-item a.ui-state-active { font-weight: normal; margin: -1px; }
.ui-menu .ui-state-disabled { font-weight: normal; margin: .4em 0 .2em; line-height: 1.5; }
.ui-menu-icons { position: relative; }
.ui-menu-icons .ui-menu-item a { position: relative; padding-left: 2em; }
.ui-menu .ui-icon { position: absolute; top: .2em; left: .2em; }
.ui-menu .ui-menu-icon { position: static; float: right; }
.hidden {
display: none !important;
}
.autocomplete-suggestions { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; border: 1px solid #999; background: #FFF; cursor: default; overflow: auto; -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); }
.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
.autocomplete-no-suggestion { padding: 2px 5px;}
.autocomplete-selected { background: #F0F0F0; }
.autocomplete-suggestions strong { font-weight: bold; color: #000; }
.autocomplete-group { padding: 2px 5px; }
.autocomplete-group strong { font-weight: bold; font-size: 16px; color: #000; display: block; border-bottom: 1px solid #000; }
......@@ -36,63 +36,40 @@ function autoCpVille(qId,options){
if(!optionShow[index])
{
$(value).hide();
$(value).addClass("hide").addClass("hidden");
$(value).addClass("hidden");
}
$(value).find("input[type=text]").prop("readonly",true).addClass("readonly");
});
var parent=$(this).parent();
$(parent).css("position","relative");
$(this).autocomplete({
minLength: 1,
appendTo: parent,
position: {
my : "left top",
at: "left bottom",
collision: "flipfit"
},
source: function(request, response) {
$.ajax({
url: options.jsonurl,
dataType: "json",
data: {
term : request.term
},
success: function(data) {
response(data);
serviceUrl : options.jsonurl,
dataType: "json",
paramName: 'term',
minChars: 1,
autoSelectFirst:true,
transformResult: function(responses) {
return {
suggestions: $.map(responses, function(ville) {
return { value: ville.label, data: ville };
})
};
},
onSearchStart: function(query) {
$( this ).prop("readonly",true);
},
onSearchComplete : function(query, suggestions) {
$( this ).prop("readonly",false);
},
onSelect : function(suggestion) {
if(suggestion.data) {
$.each(suggestion.data, function(key, value) {
$("input[type=text][name$='X"+qId+key+endLibel+"']").val(value).trigger('keyup');
});
}
});
},
search: function (event, ui) {
$(this).addClass('autocomplete-search');
},
open: function (event, ui) {
$(this).removeClass('autocomplete-search');
},
change: function (event, ui) {
if(!ui.item){
$(this).val("");
$(optionLines.join(",")).each(function( index ) {
$(this).find("input[type=text]").val("").trigger('keyup').trigger('blur');
});
}
},
select: function( event, ui ) {
$.each(ui.item, function(key, value) {
$("input[type=text][name$='X"+qId+key+endLibel+"']").val(value).trigger('keyup').trigger('blur');
});
},
focus: function (event, ui) {
return false;
},
blur: function (event, ui) {
$(this).trigger("change");
return false;
}
}
});
});
}else{
$(optionLines.join(",")).each(function( index ) {
$(this).show();
......
......@@ -4,11 +4,11 @@
* Allow user to enter part of postal code or town and get the insee code in survey
* Permet aux répondants de saisir une partie du code postal ou de la ville en choix, et récupérer le code postal
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2015 Denis Chenu <http://sondages.pro>
* @copyright 2015-2018 Denis Chenu <http://sondages.pro>
* @copyright 2015 Observatoire Régional de la Santé (ORS) - Nord-Pas-de-Calais <http://www.orsnpdc.org/>
* @copyright 2016 Formations logiciels libres - 2i2l = 42 <http://2i2l.fr/>
* @license GPL v3
* @version 2.1.1
* @version 3.0.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,7 +21,7 @@
* GNU General Public License for more details.
*
*/
class cpVille extends \ls\pluginmanager\PluginBase {
class cpVille extends PluginBase {
protected $storage = 'DbStorage';
static protected $description = 'Insee, code postaux et ville';
......@@ -252,7 +252,11 @@ class cpVille extends \ls\pluginmanager\PluginBase {
$oEvent->set('man_message',"<strong><br /><span class='errormandatory'>".gT('This question is mandatory').". </span></strong>\n");
}
}
$assetUrl=Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets/');
$assetUrl=Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets-legacy/');
if(array_key_exists('devbridge-autocomplete',Yii::app()->getClientScript()->packages)) {
Yii::app()->getClientScript()->registerPackage('devbridge-autocomplete');
$assetUrl=Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets/');
}
Yii::app()->clientScript->registerScriptFile($assetUrl.'/cpville.js');
Yii::app()->clientScript->registerCssFile($assetUrl.'/cpville.css');
$aOption['jsonurl']=$this->api->createUrl('plugins/direct', array('plugin' => get_class($this),'function' => 'auto'));
......@@ -266,34 +270,42 @@ class cpVille extends \ls\pluginmanager\PluginBase {
public function newDirectRequest()
{
$oEvent = $this->event;
$sAction=$oEvent->get('function');
if ($oEvent->get('target') == "cpVille")
{
if($sAction=='auto')
$this->actionAuto();
else
throw new CHttpException(404,'Unknow action');
if ($oEvent->get('target') == "cpVille") {
$this->actionAuto();
}
}
private function actionAuto()
{
$iSurveyId=Yii::app()->session['LEMsid'];
if(!$iSurveyId) {
$this->displayJson(null);
}
$sParametre=trim(Yii::app()->request->getParam('term'));
// Some update directly
$sParametre=strtr($sParametre,array(
"/"=>" SUR ",
));
/* get the collation according to db */
switch (App()->getDb()->charset) {
case 'utf8':
$collate = " COLLATE utf8_general_ci";
break;
case 'utf8mb4':
$collate = "";
switch (Yii::app()->db->driverName){
case 'mysql':
case 'mysqli':
$collate = " COLLATE utf8mb4_general_ci";
if(Yii::app()->getConfig('DBVersion') < 257) {
$collate = " COLLATE utf8_general_ci";
}
break;
case 'pgsql':
// Not tested
break;
case 'sqlsrv':
case 'dblib':
case 'mssql':
// Not tested
break;
default:
$collate = "";
// Unknow DB
break;
}
$iLimit=(int)$this->get('limitliste');
......@@ -419,6 +431,7 @@ class cpVille extends \ls\pluginmanager\PluginBase {
}
$this->displayJson($aReturnArray);
}
$this->displayJson(null);
}
private function displayJson($aArray)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment