Class IBOX
========== Code completed and tested. Documentation about is done
This commit is contained in:
parent
bcea74076e
commit
7f0b0aa261
3 changed files with 142 additions and 18 deletions
|
|
@ -408,4 +408,69 @@ function add_div(obj) {
|
|||
*/
|
||||
function removeDiv(elt) {
|
||||
if (g(elt) ){ document.body.removeChild(g(elt)); }
|
||||
}
|
||||
/**
|
||||
*@brief call add_div to add a DIV and after call the ajax
|
||||
* the queryString, the callback for function for success and error management
|
||||
* the method is always GET
|
||||
*@param obj, the mandatory attributes are
|
||||
* - obj.qs querystring
|
||||
* - obj.js_success callback function in javascript for handling the xml answer
|
||||
* - obj.js_error callback function for error
|
||||
* - obj.callback the php file to call
|
||||
* - obj.fixed optional let you determine the position, otherwise works like IPopup
|
||||
*@see add_div IBox
|
||||
*/
|
||||
function show_box(obj) {
|
||||
add_div(obj) ;
|
||||
if ( ! obj.fixed ) {
|
||||
var sx=0;
|
||||
if ( window.scrollY) { sx=window.scrollY+40;}
|
||||
else { sx=document.body.scrollTop+40;}
|
||||
g(obj.id).style.top=sx;
|
||||
show(obj.id);
|
||||
} else {
|
||||
show(obj.id);
|
||||
}
|
||||
if ( obj.drag ) {
|
||||
new Draggable(obj.id,{starteffect:function(){
|
||||
new Effect.Highlight(obj.id,{scroll:window,queue:'end'}); } }
|
||||
);
|
||||
}
|
||||
var action=new Ajax.Request (
|
||||
obj.callback,
|
||||
{
|
||||
method:'GET',
|
||||
parameters:obj.qs,
|
||||
onFailure:eval(obj.js_error),
|
||||
onSuccess:eval(obj.js_success)
|
||||
});
|
||||
}
|
||||
/**
|
||||
*@brief receive answer from ajax and just display it into the IBox
|
||||
* XML must contains at least 2 fields : code is the ID of the IBOX and
|
||||
* html which is the contain
|
||||
*/
|
||||
function success_box(req,json)
|
||||
{
|
||||
try{
|
||||
var answer=req.responseXML;
|
||||
var a=answer.getElementsByTagName('ctl');
|
||||
var html=answer.getElementsByTagName('code');
|
||||
if ( a.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
|
||||
var name_ctl=a[0].firstChild.nodeValue;
|
||||
var code_html=getNodeText(html[0]);
|
||||
code_html=unescape_xml(code_html);
|
||||
g(name_ctl).innerHTML=code_html;
|
||||
}
|
||||
catch (e) {
|
||||
alert(e.message);}
|
||||
try{
|
||||
code_html.evalScripts();}
|
||||
catch(e){
|
||||
alert("answer_box Impossible executer script de la reponse\n"+e.message);}
|
||||
}
|
||||
|
||||
function error_box () {
|
||||
alert('IBOX : error_box ajax not implemented');
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
s<?php
|
||||
<?php
|
||||
/*
|
||||
* This file is part of PhpCompta.
|
||||
*
|
||||
|
|
@ -66,7 +66,8 @@ $array=array(
|
|||
array(27,'Card (class_fiche)'),
|
||||
array(28,'Extension'),
|
||||
array(29,'ITVA popup'),
|
||||
array(30,'Ereg and preg_match')
|
||||
array(30,'Ereg and preg_match'),
|
||||
array(31,'IBOX')
|
||||
);
|
||||
$r='<form method="get">';
|
||||
$r.='<select name="test_select" >';
|
||||
|
|
@ -256,7 +257,9 @@ case 30:
|
|||
// preg_match ("/^(\\$[a-zA-Z]+[0-9]*=){0,1}((\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})+ *([+-\*/])* *(\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})*)*(([+-\*/])*\\$([a-zA-Z])+[0-9]*([+-\*/])*)* *( *FROM=[0-9][0-0].20[0-9][0-9]){0,1}\$/",$str,$p_result);
|
||||
var_dump($p_result);
|
||||
}
|
||||
|
||||
case 31:
|
||||
require_once('class_ibox.php');
|
||||
IBox::test_me();
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,48 +27,104 @@
|
|||
*/
|
||||
require_once('function_javascript.php');
|
||||
require_once('class_html_input.php');
|
||||
/**
|
||||
*@brief create a DIV and call an ajax function
|
||||
\verbatim
|
||||
|
||||
exemple d'utilisation
|
||||
|
||||
$ibox=new ibox('id')
|
||||
$ibox->html='loading';
|
||||
$ibox->callback='ajax.php'; // uniquement fichier PHP (1)
|
||||
$ibox->queryString='?gDossier=15&id=5';
|
||||
$ibox->style='style_css',
|
||||
$ibox->cssclass='width:80%';
|
||||
$ibox->label='Cliquez moi';
|
||||
$ibox->onclick='add_div()'; // if you click
|
||||
$ibox->ajax_success='autre'; // fonction qui affiche traite le callback, par défault, il s'agit de la fonction refresh_box qui afficher seulement le contenu dans le div
|
||||
$ibox->ajax_error='ajax_error' // fonction pour traiter les erreurs ajax
|
||||
\endverbatim
|
||||
*/
|
||||
|
||||
class IBox extends HtmlInput
|
||||
{
|
||||
var $name; /*!< name name and id of the div */
|
||||
function __construct($p_name)
|
||||
function __construct($p_name,$label)
|
||||
{
|
||||
$this->name=$p_name;
|
||||
$this->parameter='';
|
||||
$this->attribute=array();
|
||||
$this->drag=false;
|
||||
$this->blocking=true;
|
||||
$this->queryString='';
|
||||
$this->html='<img src="image/loading.gif">';
|
||||
$this->callback='';
|
||||
$this->label=$label;
|
||||
$this->handle_callback='refresh_box';
|
||||
$this->cssclass='';
|
||||
$this->style='';
|
||||
$this->ajax_success='success_box';
|
||||
$this->ajax_error='error_box';
|
||||
|
||||
}
|
||||
/*!\brief set the attribute thanks javascript as the width, the position ...
|
||||
*\param $p_name attribute name valid value are id, cssclass and html
|
||||
*\param $p_val val of the attribute
|
||||
*\note add to the this->attribut, it will be used in input()
|
||||
*/
|
||||
function set_attribute($p_name,$p_val) {
|
||||
/* function set_attribute($p_name,$p_val) {
|
||||
$this->attribute[]=array($p_name,$p_val);
|
||||
}
|
||||
}*/
|
||||
function set_dragguable($p_value){
|
||||
$this->drag=$p_value;
|
||||
}
|
||||
|
||||
function input() {
|
||||
$r="";
|
||||
$object=$this->make_object();
|
||||
$r.=sprintf(" add_div (%s)",$object);
|
||||
$result=create_script($r);
|
||||
if ($this->drag==true){
|
||||
/* add draggable possibility */
|
||||
$r.=sprintf(" new Draggable('%s',{starteffect:function(){
|
||||
new Effect.Highlight('%s',{scroll:window,queue:'end'}); } });"
|
||||
,$this->name
|
||||
,$this->name);
|
||||
$this->set_attribute('id',$this->name);
|
||||
$this->set_attribute('html',$this->html);
|
||||
$this->set_attribute('cssclass',$this->cssclass);
|
||||
$this->set_attribute('style',$this->style);
|
||||
$this->set_attribute('js_success',$this->ajax_success);
|
||||
$this->set_attribute('js_error',$this->ajax_error);
|
||||
$this->set_attribute('qs',$this->queryString);
|
||||
$this->set_attribute('callback',$this->callback);
|
||||
$this->set_attribute('drag',$this->drag);
|
||||
$obj=$this->make_object();
|
||||
$obj=str_replace('"',""",$obj);
|
||||
$r='<a class="button" href="#" onclick="show_box(eval('.$obj.'))">'.$this->label.'</a>';
|
||||
|
||||
}
|
||||
return $resultxs;
|
||||
return $r;
|
||||
}
|
||||
|
||||
static function test_me() {
|
||||
echo js_include('js/scripts.js');
|
||||
echo js_include('prototype.js');
|
||||
echo js_include('scriptaculous.js');
|
||||
echo js_include('effects.js');
|
||||
echo js_include('dragdrop.js');
|
||||
echo js_include('scripts.js');
|
||||
|
||||
// Simple box no ajax
|
||||
$simple=new IBox('alert1','click-moi');
|
||||
$simple->html="Attention !!!";
|
||||
$simple->style="background:red;border:1px solid rose;width:200;height:50px;";
|
||||
$simple->drag=false;
|
||||
echo $simple->input();
|
||||
|
||||
// Dragguable
|
||||
echo '<div id="drag_content"></div>';
|
||||
$drag=new IBox('drag','drag');
|
||||
$drag->cssclass="popup_border_title";
|
||||
$drag->html=" Drag me ";
|
||||
$drag->drag=true;
|
||||
echo $drag->input();
|
||||
// with ajax
|
||||
$ajax=new IBox('ajax','ajax');
|
||||
$ajax->cssclass="popup_content";
|
||||
$ajax->style="width:1;left:1";
|
||||
$ajax->queryString="?gDossier=48&op=sf&c=av_text5&q=58&ctl=drag";
|
||||
$ajax->callback="ajax_poste.php";
|
||||
echo $ajax->input();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue