Sorting a view by dropdown - ajax

Hey, i've been looking around for a ajax dropdown sorter for my Views in Drupal.
Unfortunatly, i haven't found alot of usefull information about this subject.
Can anyone tell me if theres a solution already available or can help me started on a custom module by telling me which hooks i should use?

I had a similar issue. Unfortunately I wasn't able to sort the data from the database which is by far the best way. I was however able to take the data and sort it with PHP using a preprocessor function. Depending on the name of your view, setup a function similar to the following:
function templatename_preprocess_name_of__view(&$vars)
{
//Super sweet sorting code goes here
}
The name of your view needs to follow the name of the template file that it is driven by, if there isn't on you should create one. Make sure to change dashes to underscores in your function name. Hope this is helpful. If you find a way to do it from the DB I'm all ears because that would be super awesome.

Related

SCA SuiteScript query item to code

I need to add an non-inventory item by internal id to the cart in SCA, how would I go about pulling that item and then adding it? The code samples I find are for pulling data always refer to views, I am thinking I need to pull it as an item, as I need to add it as an item using methods in LiveOrder.Model
thanks for anyhelp you may give
Really depends on which version of SCA you are using.
The quick answer is to look in the ItemDetails.View.js file in the Modules directory and find the code for the addToCart method.
The longer answer is that SCA's architecture and performance leave much to be desired. If you have things like multiple add to or update cart I found that it was easier to write my own cart.ss service and then just forward to the cart or refresh the page on completion.
So I found out that the easiest way to do this is like this, the items are returns in a object array, so thanks for your help
$.get('/api/items?id=10779&fieldset=details', function(obj) {
}).done(function(obj) {
});

How to make wp plugin auto-refreshing on the public side of view (auto load page)

First have to say that almost every time when searching on technical solutions.. search engine will direct me to this site here. I admit that i have learned such A LOT here just by searching through for answers..
but also have to say that not being a coder.. so don't understand much here at all ;)
Ok, the Problem:
Want to update wordpress tables or calendar within wp admin. These changes should become updated on the public side automatically and more or less instantly (~ few seconds is perfectly fine).
I found solutions about manipulating header.php, i found some ajax plugins I found -too much to count- info on how to implement ajax into wp
Sadly.. none of these could help me through as the plugins mostly either not work, are outdated or require countless file edits. Manipulating header.php seems odd.. as i don't want to loop-refresh the whole page, post etc.. but only get e.g. table or calendar data updated.
So maybe any of you coders know of something to e.g. get the plugin "All-in-One Event Calendar by Timely" to update the public visible part of the calendar once data edited in wp admin?
Greatly appreciate pointers in any direction to solve this.
P.S.: What would you think of plugins like "ajaxify everything" ? don't know if this really the way to go..
Again, thanks for your help, time and contribution!!
update
additional question:
I now found such plugin to let me chose which parts i want to "ajaxify".
Such plugin would ask me for a specific function name.
Now, where do i start to gather this information?
Below is the instruction from the plugin context inside wordpress admin
Generate Ajaxized DIV for your function
Ajaxize will allow you to ajaxize almost any php function on your
site.
It can be a plugin, a function you wrote, or even a core wordpress
function.
There are some (obvious or less obvious) limitations currently:
Functions must return valid HTML - this will be called in php and returned via the
Ajax call
Functions cannot accept any parameters (at least at the moment)
Enter a function name below.
Function Name: xxx input field xxx what put in here? xxx
The generated div can be inserted to any page/post on the site and
will ajaxize the call to the function automatically.
Please make sure you enter a valid function name, that the function
does not require any parameters, and that it returns valid HTML.
In your context you want to refresh the calendar automaticaly when there is a change in the WP_Admin;
but you can't exactly do this.
You can write a Js method which will check the time of lastest modification of the calendar at the load of the page, stock it in Var.
After you'll have a constant (each 10seconds) Js "daemon" which will get the time of lastest modification of the calendar and compare it to the stocked Var; If change you reload the calendar.
PS: Ajaxify everything is not really a solution due of the developpement you need To Ajaxify and to code for people who has disabled Javascript.
Hope it helps

cakephp 2.1 view associated data across all add.ctp, edit.ctp, view.ctp

I have an "examinations" table, its consultation_id relates to "consulsations" table, which in turn its consulation_id relates to the "patients" table.
Now, when I am in the add.ctp, edit.ctp or view.ctp of the "Examinations" Views I need to pull the "patients" details in so that some patient info can appear as to who the form pertains to as patient.
I have tried joins. Not to say they dont work. I am new to cakephp and I really need help as to how it will appear within the controller and how the view.ctp will display it.
I thought of elements but they are just .ctp files right?
Please if anyone can help regarding this it would be so appreciated. I've been trying to do this now for a week and I know there is something simple I am dont doing or thinking rights about.
So you just want to pull in related data? Pretty simple.
In your ExaminationsController methods.
$patients = $this->Examination->Consultation->Patient->find('all',
array('conditions'=>array('consultation_id'=>$id,'examination_id'=>$e_id)));
Something similar to this, not quite sure on which id you need to pass, as it will depend on how your models are linked up. http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
However, if your models are linked up properly, you should get this data anyway. If not set your models recursion to be higher.
$this->Model->recursive = 2;

Vaadin custom table header

I want to build custom filtering header for Vaadin tables.
Can you please give some examples or solution to this problem.
I want to add a combo box or check box that will refine the search in the table like Excel columns.
We faced the problem of adding custom filters for Vaadin Table in our project as well.
As a solution we added a dynamic filter form above the table. It has become flexible and agile enough to apply filters.
We created Vaadin Addon in order to share our solution - Lexaden Grid.
You can find more information by the following link:
http://www.lexaden.com/main/entry/lexaden_grid
At the moment it is quite hard to add a custom component to do filtering with to the header of a table. It would require you to make your own version of Table by inheritance/copy&paste (not sure what is enough), and that is something most people wan't to avoid at the moment if anyway possible. The current implementation of the Table component is one of the most complicated components of Vaadin. It is doable if you insist putting components in header, but prepare for some serious thinking to get things to work.
I'd suggest making the filtering of data in containers with components just next/above your table. Hiding the table header is sometimes acceptable if there's no crucial information shown there. If you want something precisely on the header, it would require some empty headers and CSS positioning components on correct place.
You can always group table and other filtering components to one CustomComponent for easier abstraction.
Book of Vaadin is a very good reference for vaadin implementation. The link consist of an example code like:
// Define the properties
table.addContainerProperty("lastname", String.class, null);
table.addContainerProperty("born", Integer.class, null);
table.addContainerProperty("died", Integer.class, null);
// Set nicer header names
table.setColumnHeader("lastname", "Name");
table.setColumnHeader("born", "Born");
table.setColumnHeader("died", "Died");
Is this what you ask for? If it isn't, can you please specify your question a bit more clearly?
edit: Vaadin Sampler also contains handful code samples.

Modifying view based on ACL in CakePHP

I want to be able to show or hide certain elements in a view based on ACL. For instance, if a user is looking at my Users/index view, I don't want to show a 'Delete User' element if he doesn't have permission to delete users. If he does have permission to edit users, I do want to show a 'Edit User' link.
I can hack this together, but being very new to Cake I'm hoping that there is an elegant solution. The best I've done involves keeping logic in two places, so it's hell to maintain.
Thanks!
I know this is an old question now but for anyone looking for a way like I was...
In AppController::beforeFilter you can assign the ACL component to a view variable and then use it in your view:
$this->set('user', $this->Auth->user());
$this->set('acl', $this->Acl);
And then in you view just juse it like thie:
if($acl->check(array('User' => $user), 'controllers/groupd/admin_delete')) {
This is't necessarily the most correct way to do it but it does work nicely
There is no generic "elegant solution" :) I've always wanted to make such thing as well. Anyway how you could do it:
Overwrite the Html Helper in your app directory - make a copy from /cake/libs/views/helpers/html.php to /app/views/helpers/html.php and made some changes in the Html::link function.
For example you can check if the url contain action edit or delete.
The other part is to pass the proper parameters from the controller. In AppController::beforeFilter you can read the rights of the user (it's better to be cached) and to pass it in a special Auth variable to the View.
So when you have the rights in your View it's easy to modify the link. :)
As I said I haven't did it in real example, but this is the way I would do it.
There is 1 bad point in that - if the original Html helper is changed, your one will remain the same. But I believe that Html helper is mature enough so for me is not a big issue.
I do it like this in app_controller.php, although you could just as well do it in specific controllers. The view variables $usersIndexAllowed and $configureAllowed are then used in conditional statements in the view.
function beforeRender()
{
if($this->layout=='admin')
{
$usersIndexAllowed = $this->Acl->check($user,"users/index");
$configureAllowed = $this->Acl->check($user,"siteAdmins/configure");
}
$this->set(compact('usersIndexAllowed','configureAllowed'));
}
In case you don't want to mess around with overriding core helpers and you want a more automatic way of checking (without hard-coding user group names and users or setting separate link-specific variables) here's my suggestion:
Store all user permissions as session vars when the user logs in (clear on logout) and create a permissions helper to check if logged on user has permissions for a specific action.
code and example here
hope that helps
There's multiple approaches to this scenario. As Nik stated, using a helper to do the checks for you is a quick way to "outsource" the logic and centralize it for ease of use.
Actually, have a look at the AclLinkHelper - it does exactly what you're looking for, however restricted to links only.

Resources