Call ordering in DWR - dwr

There is an option to make DWR AJAX calls to execute in sequence thru the following option
DWREngine.setOrdered(true)
But this is working globally (for entire application).
I want to make enable this option only to certain Classes.
Is it possible?

This can be done in the following way
DWREngine.beginBatch();
BatchCallClass.method1(testCallBatchingCallback1);
BatchCallClass.method2(testCallBatchingCallback2);
MathDelegate.multiply(8, 4, testCallBatchingCallback3);
DWREngine.endBatch();
in this way you avoid to change the behaivor of all you entire application.

Related

Custom child commands for UI elements

We're currently using Select2 for all our <select> elements and for obvious reasons cy.get("#element").select("foo") won't work. As per the docs we've created our own custom command cy.get("#element").select2("foo") which just wraps a number of steps to select "foo".
This works well when trying to select a value but we'd like to avoid adding custom commands for clear(), value(), etc.
We'd also like to avoid using the Select2 API because this would require someone to understand that API as opposed to just working in the Cypress API.
We'd like to create something a bit more flexible by instead having a Cypress friendly object. Something that would look like this:
cy.get("#element").select2().as("select2");
cy.get("#select2").select("foo");
cy.get("#select2").should("be.equal", "foo");
cy.get("#select2").clear();
Is it possible to create a child-command that returns an object that can then override these built in commands?
We're unable to return our custom object from our custom command without first cy.wraping it which defeats the purpose.

Dynamically changing template contents of a web form

Let's say I want to build a web app which would use templates in the form similar to the following:
<h1>
{ status_text[step] }
</h1>
<progress max="10" value="{ value[step] }">
</progress>
In other words, let's say that I have lists value[] and status_text[], change only the variable step over time and want the form to reflect these changes in the real-time (ideally, even without sending a notification from the code that changes step, so that I can use current_time instead of some artificial step). What technology should I use to implement such behaviour in the most elegant way? (for the main language, I'd prefer using Python but JS/PHP would also work if there's no Python-related solution)
Thanks in advance for any advice.
These kinds of task are always accomplished in the client side, In other words in JavaScript.
No matter you use PHP or Python for your backend logic, you need JavaScript to do that.
That said, if you want to use pure JavaScript or a library like jQuery, you will have to trigger an event on every change of the progress and update the value of the h1 Element. I don't think this is the best solution for you.
So I suggest you using AngularJs. it's one of the leading web development technologies. AngularJs data binding allows you to accomplish this very easily. No need to trigger events or any extra work. if you're interested in AngularJs, here is a link to get started.

MiniProfilerEF view results without RenderIncludes()

Is there another way to view the profiling results of MiniProfiler (I'm specifically interested in EF5 version)?
Every tutorial that I've seen uses MiniProfiler.RenderIncludes(); but since my MVC app mostly returns JSON, that is not an option for me.
Is there a way to write results to file or something like that?
You can read and write results to just about anywhere by changing the MiniProfiler.Settings.Storage to a different IStorage implementation from the default (which stores to http cache). If you wanted to, this could store to and read from a file pretty easily (you would have to write your own custom implementation for that).
The files served by RenderIncludes are the html templates for displaying the results and the script to retrieve the results from the server and render them on the client (all found here). But you are by no means obliged to use this mechanism. If you want to write your own logic for retrieving and displaying results, you should base this off of the logic found in MiniProfilerHandler.GetSingleProfilerResult. This function roughly performs the following (putting in the siginificant steps for your purposes):
Gets Id of next results to retrieve (through MiniProfiler.Settings.Storage.List())
Retrieves the actual results (MiniProfiler.Settings.Storage.Load(id))
Marks the results as viewed so that they wont be retrieved again (MiniProfiler.Settings.Storage.SetViewed(user, id))
Converts these to ResultsJson and returns it
With access to MiniProfiler.Settings.Storage, you should be able to retrieve, serve and consume the profile results in any way that you want. And if you are interested in using the RenderIncludes engine but want to mess around with the html/js being served, you can provide your own custom ui templates that will replace the default behavior.

Caching with codeigniter and twig

I'm trying to cache my output. I'm using Codeigniter's built-in feature $this->output->cache() but it doesn't work. My guess is because I'm using twig. Any ideas?
I found the answer, may it be useful for whoever pass here.
$output = $this->twig->render('template.html'); // use render instead of display
$this->output->set_output($output); // use CI's output (autoloaded by default) manually
$this->output->cache(5); // cache for 5 minutes, doesn't matter where this line is in the function.
As you discovered yourself, you should map output to the Output class via one of the appropriate methods in order to take advantage of its built-in caching features. Note that CI 3.0 currently in development on Github has some updates that you may like (gzipped cache files that retain all output headers, for example).
You could extend the Loader library with a customized view() method, and perform the logic there as well, rather than needing 2+ lines in each controller (if you wanted to load multiple files, you'd have to call render() then append_output() every time).
I did exactly that with the Smarty template library. Should be able to do something similar with Twig. (I've been meaning to port it over as well, but haven't had the time.)

Jquery/Ajax/HTML assistance needed

I am trying to build a very basic message center. My idea is to use Jquery to make an ajax call to a classic asp page that will build a Json array.
I then plan to use Jquery to grab that Json.
My main questions currently are:
Is it possible to empty out a multi select input list?
Would it be better to not use the input at all and build a nifty Jquery list?
Will using Ajax allow me to on the fly empty this list; replace with with different information and/or append items to this list all without a page refresh?
I need to be able to allow the client to select multiple people from this list. Is my outline above feasible?
Is it a good way to achieve what I am looking for?
I have very little experience with Json and Ajax, and was hoping someone could confirm if it was possible before I dive in.
Is it possible to empty out a multi select input list?
Yes
Would it be better to not use the input at all and build a nifty Jquery list?
You can have this work with any kind of element, including a standard input.
Will using Ajax allow me to on the fly empty this list; replace with with different information and/or append items to this list all without a page refresh?
Yes, in a function that handles the response of the Ajax call and uses call's result to populate the list. Since you're using Ajax, the call is asynchronous so the entire page will not be refreshed as a result of your call.

Resources