Topic: A new idea for implement Xajax...

Hi,

Im Paulo, from Brasil... I have a function that i think can be implemented in xajax.

Me and i think someone, want to do a CONFIRM calls in some projects, and we have to do it directly on javascript, but i thinking in my house, we can implement the class, i think in a method like this :

Example:

{example.php}

$objResponse->Confirm("Are you sure?","xajax_DeleteRegister();","xajax_NextPage();")

{output to the browser}

<script language="javascript">
    if (confirm("Are you sure?")){
           xajax_DeleteRegister();
    } else {
           xajax_NextPage();
    }   
</script>



Now i will explain. When you call "$objResponse->Confirm" , you have to especify 3 arguments, but the third is optional. The first argument is the question, the second argument is the commands for true return of confirm and the third argument is for the false return of confirm.

When the xajax will construct if, only need construct on this structure:

      if ( confirm(first_argument) ) {
          second_argument
      } else {
          third_argument
     }

It will facility too much to anyone here and others places too...

Stay here my sugestion...waiting for comments...

Thanks for all...sorry for my bad english...
God bless everybody...
Paulo...

Re: A new idea for implement Xajax...

Paulo,

I think this is a great idea.  Let me throw out another option for how this can be implemented:

currently $objResponse has function confirmCommands:

function confirmCommands($iCmdNumber, $sMessage)
* @param integer the number of commands to skip if the user presses
* @param string  the message to show in the browser's confirm dialog

If we simply add a third optional parameter $iElseNumber, then the user could specify a number of commands to skip on the else condition (this would automatically insert a "skip" command after $iCmdNumber number of commands in the response command queue)

In addition, we could add a $objResponse->skip($iNumberOfCommands) function which would simply skip the next $iNumberOfCommands

This could lead the way to more advanced flow control structures (later) like switch ... case, for ... next and do ... while.

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: A new idea for implement Xajax...

Hi joe,


Yeah...its an exit for it... but in my opnion, that method is more easy and faster...

And , im really dont understand your opnion, can you post a sample code showing  what you say in action ?


God bless all...
Bye,
Paulo.

Re: A new idea for implement Xajax...

Your idea is not so new and everybody who use xajax implements the method he needs.

There are a lot of ways out. They all are different and there is no sense to create a universal one. Because there is no such an implementation.

Just a notice: if i want to have asynchronous confirmation and synchronous as well in the same project,- what then? Or if i want a scrolling confirmation div?

So my advice: don't invent a new bicycle because there are a lot of such bicycles already implemented and this topic was several times discussed here on this forum.

Re: A new idea for implement Xajax...

i don´t think the idea is too bad, the question is not the "if", the question is the "how".

Re: A new idea for implement Xajax...

Look, mans,

I dont re-invent the bicycle, and you are so ignorant, if anyone have to implement all things dont need exist updates.

I dont wanna do a simple thing, but i want implement a problem that can be solved with a simple function. The method "addAlert" or now on 5.1 "alert" is more simple that my idea, if the xajax have "alert", why not "confirm" ?

Only need create $objResponde->"Question","javascript code block if true","javascript code block if false";

The xajax have $objResponse->alert("Message"), why not CONFIRM ?

This will facility much more than create :

METHOD_1

$script = " if confirm('are you sure?') {
                    xajax_delete_record() ;
                } else {
                    xajax_next_page();
                }";

$objResponse->script($script);

What you think that is more easy ?

METHOD_2 (my idea)

$objResponse->confirm('are you sure?' , 'xajax_delte_record()' , 'xajax_new_page()' );

(  ) Method 1 -> by script

(  ) Method 2 -> by new idea

I want believe in this words :
xajax PHP Class Library - The easiest way to develop asynchronous Ajax applications with PHP

So this a new method to facility the coders life, it will decrease the work, and it not hard to develop and implement, is +/- the same of alert, oly need write :

IF (CONFIRM (parameter1)) { PARAMETER2 } ELSE { PARAMETER3 }

Anyone can do it, so i think that is a valid idea, and will facility the life of everybody and will decrease the work.

And my vote is to :

( X ) Method 2 -> new ideia

And i request that anyone vote too.

Thanks for all,
God bless everybody,
Paulo.

7 (edited by prchakal 2007-01-11 12:41:21 PM)

Re: A new idea for implement Xajax...

Ah,

I forget more one think,

my email is : paulo@7soft.info
my msn is   : seven-software@hotmail.com

Thanks again and sorry for my bad english.
God bless everybody,
Paulo.

Re: A new idea for implement Xajax...

prchakal wrote:

And , im really dont understand your opnion, can you post a sample code showing  what you say in action ?

In xajax 0.5 beta's is the function xajaxResponse->confirmCommands()
You can use it like

$objResponse->confirmCommands(1, "Do you want to preview the new data?");
$objResponse->script('data_preview();');

which will only call the data_preview() function if the user presses ok
or if you want a true/false kind of response

$objResponse->script('confirmValue=false;');
$objResponse->confirmCommands(2, "Do you want to preview the new data?");
$objResponse->script('confirmValue=true;');
$objResponse->script('data_preview();');
$objResponse->script('if (!confirmValue) do_something_else();');

which will call the data_preview() function if they press ok, or do_something_else() if they click cancel

Re: A new idea for implement Xajax...

Nice example BBC.  I guess it is already possible to do if/then/else, I just didn't think of it that way!  big_smile

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: A new idea for implement Xajax...

I'm just gonna move this over to the feature requests page, since it's not really a release testing thing

Re: A new idea for implement Xajax...

Shortly: confirmation stuff is a client side stuff. And xajax is a client server communication tool.

So my opinion your idea is not so bad, but it's not for xajax. Maybe as a separate plugin. If there is a sample or manual on how to create such xajax plugins.

Re: A new idea for implement Xajax...

Aff...

Why have to write 5 lines, if you want write in one line?

We have $objResponse->alert(message);    Why not confirm? Whats the problem with it? Its an implentation... Its much more than necessary.

With it this will help everybody here...now we have various implementation that write javascript, like :
    $objResponse->alert(message);
    $objResponse->assign(object,propertie,value);

and others, so, why not :
    $objResponse->confirm(question,true_code,false_code);

Dont be more easy? Its object oriented class that return javascript automatically ansychronus, dont need create javascript/html code, if i have to write 5 lines instead of  1 line, where is the facility to use xajax?

Xajax will have more 1 easy method if you implement it.

I want understand why not implement it... have to many thinks to implement, look:

$objResponse->timeout(5000,"refresh_data()");

This will return javascript code:
setTimeout(5000,"refresh_data()")

Other thing that we can do is :
$objResponse->prompt("Write your name:", "default_message", "code_block_1", "code_block_2");

This will return a javascript code like it:
if ( prompt("Write your name:","default_message") != "" ){
    code_block_1
} else {
    code_block_2
}

See? Sure we can create with $objResponse->script, but if we create this methods, the class will be more organized, understand? We dont will need write javascript/html codes.

With this and some more method that decrease our work, Xajax will win more and more fans...users...here on my work and city everybody want this methods, and dont do a inherits to implement a class that can be go with it already implemented... its so simple...

( X ) METHOD 2
God bless everybody,
Thanks,

Paulo.

Re: A new idea for implement Xajax...

Paulo, did you think why your ideas are not implemented yet?

And another question: do you see any disadvantages when implementing a lot of undefined methdos (read "unknown" for users).

You know, when i overlooked all the ajax frameworks i chose xajax due to its simplicity. But i can write javascipt and anybody who use xajax can read javascript manuals, and there is no troubles with.

But, all the things is just IMHO. Nothing more.

Re: A new idea for implement Xajax...

I understand and respect your comments, mstar, there is a compromise... too many functions with little benefit clutter up the project and make it sluggish / bloated.  However, I agree with prchakal in this case...  I would like to see:

$objResponse->confirm("message", "javascript onOK", "javascript onCancel");

and the reason is:  the javascript implementations using ->script require multiple commands, each are passed as strings from the server to the browser.  Instead, by using the above mentioned syntax on the server side, the xajax engine can optimize the response as is the case with ->assign, ->append, etc... (which could all be implemented in javascript with ->script, but that gets ugly quick)

I would prefer that a different function name be used... perhaps ->ask('question', 'onOk', 'onCancel'); since this would essentially be a new command (different than the existing ->confirm('message', numberOfCommandsToSkip);

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: A new idea for implement Xajax...

Thanks CtC...


The name is not too much import, but the functionality is...

ask or confirm, you decide...

You can do a function called for example "timer", $objResponse->timer(1000,"comands"); , that will return that function "setTimeout(1000,comands)"... What you think about?

the more implemented, more simplified and powerful it will be the class..


Thansk for all...
God love everybody,
Paulo

Re: A new idea for implement Xajax...

In it's basic form (as you've shown above), the timer functions (setTimeout, clearTimeout, setInterval, clearInterval) would not be on my list of features to add to xajax... since they are pretty straightforward.

However, you've got me thinking about it.  Perhaps xajax could support ->timer('functionName', duration, arrayOfParameters, count); which would generate some code on the browser like so:

xajax.timers[functionName] = {}
xajax.timers[functionName].count = count;
xajax.timers[functionName].parameters = parameters;
xajax.timers[functionName].timer = setInterval('xajax.timers.fire("' + functionName + '");', duration);

with:

xajax.timers.fire = function(functionName) {
    var fire = true;
    var count = xajax.timers[functionName].count;
    if (count > 0) {
        count -= 1;
        if (0 == count) {
            clearInterval(xajax.timers[functionName].timer);
            xajax.timers[functionName] = {}
            fire = false;
        }
    } else {
        // never ending
    }

    if (fire) {
        var parameters = xajax.timers[functionName].parameters;
        eval(functionName + '(parameters);');
    }
}

This would add a good bit of functionality with minimum bandwidth usage.  I might be wrong, but I believe this (and the previous feature) fit into the design of xajax in that they help the php developer drive the remote scripting process from the server.

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

17 (edited by prchakal 2007-01-12 8:37:32 PM)

Re: A new idea for implement Xajax...

Ok...


So i dont understand ensligh too much, so , this already exist or is a future feature?

I have another feature...i think... smile

You know the function "prompt" of javascript correct?
You can implemtn Xajax with a function like :

$objResponse->prompt("phrase","default","code if prompt return filled","code if prompt return blank");

This have a javascript return like:

if ( prompt("phrase","default") != "" ) {
    "code if prompt return filled"
} else {
    "code if prompt return blank"
}


What do you think about ?

Thansk for all...
God love everybody,
Paulo