i need to check if user role is admin, append a <td>to the table. in other word i have a table as below in my jsp page:
title | description | action
-----------------------------------
.... ...... answer
i want when user role is admin, in the action column see is added. like this:
title | description | action
-----------------------------------
.... ...... answer|see
my jquery code for this is:
$('#my-rows').append($('<tr>')
.append($('<td>').text(poll.title))
.append($('<td>').text(poll.description))
.append($('<td>').append($('<a style="text-decoration: none">').attr({
'onclick' : 'VoteFor(' +poll.poll_id+ ')'}).text('answer'))).append(('${hasRoleAdmin}' == true ? $('<a>').attr({
'onclick' : 'ViewPoll(' +poll.poll_id+ ')'}).text('see'):'')))
and hasRoleAdmin is a variable that i have defined in my jsp page like this:
<sec:authorize access="hasRole('ROLE_ADMIN')" var="hasRoleAdmin"></sec:authorize>
but it doesn't work and my table is as what i showed first earlier above and i can't get see as it is in second table. how can i put my condition on append? can you help?
If I understood correctly -
Since you have Spring security in picture, you can simply:
Hard code your wherever you want.
wrap it in your spring security tags something like this:
<sec:authorize access="hasRole('ADMIN')"><td>your</td></sec:authorize>
Handle security in your SecurityConfig.
should do the trick. That means, no other role should be able to view that tag at all other than Admin. Let the spring security handle it for you. There is no need to hide/unhide/enable/disable using JS/JQ etc.
Related
I am making a page with soccer teams and leauges. Now i`m printing all Leagues that i want from the database.
League 1
League 2
League 3
etc.
As you can see each League has its own League_ID. In Database i also have a table of all teams, and each team has matched League (with League_ID). I also have a view, where i can print table of League that i want. This function in php looks like this.
public function leauge_table(){
$tables = $this->scoreTableRepository
->getScoreTable(1);
//TODO how to change this "1" static to generated
//TODO when pressing link
return $this->render('leauge_table', ['table' => $tables]);
And as you can see, when i go to this page i will always see the score table from leauge that has id=1.
And the question is how can i make that when i press for example at "League 2" i will open page but with table matching to League_ID = 2. Shall it be <button></button> or <a></a> in HTML. And how to pass there League_ID so my php back will see which table should render.
Thank you really for help.
PS
Or maybe do i have to make a seperate view for each leauge score table? And then just simply make buttons direct to these views with simple JS code. But would like to avoid it if it`s possible.
It can be a link or a button. A link with the league ID as a parameter in the URL is the simplest approach though, if you're new to the concept. e.g.
League 1
The ID would then be available in the php script via $_GET["id], once the link is clicked.
In your SoccerTeam page add a button in a form with the following :
<form action="youpage.php" method="post">
<input name="leagueId" type="hidden" value="<?php echo $leagueId;?>" >
</form>
And in order to process that information, since we passed an id, we can retrieve it with $_POST['leagueId'] and because it's a POST request it wont be visible in the url:
$leagueId = $_POST['leagueId'];
I'm doing an e-commerce site (learning purposes) with KeystoneJS. In the view where I display all the products I want to add a filter for sort the items by price and another one to show the products of only one brand. Two forms are needed but I don't get to submit only one
My products.pug looks like this
.container
form(method='post')
input(type='hidden', name='action', value='products')
button(type='submit').btn.btn-primary Send
And my products.js in routes/views/ looks like this
[...]
// Print a word when submit the form
view.on('post', { action: 'products' }, function(next) {
console.log('POST')
next()
})
// Get all products from db
view.on('init'...)
// Render
view.render('products')
So basically what I want to do is to print POST when I hit the button in the view. Instead of that, I receive a 404 error page. I would really appreciate if you guys can help me
Got it! In /routes/index.js I replaced
app.get('/products', route.views.products);
for
app.all('/products', route.views.products);
I feel dummy but happy.
My sign up form was previously working well. However, I had to add an acceptance page or terms and conditions before sign up can be successful. I thought it would be better to include it in sign up page rather than after sign up (before being presented with member's homepage). Problem is, it's having a lot of issues. It's not working properly.
Here's my code in view page: (i added this at the bottom of all fields before sign up button)
Please proceed only if you accept our <a target="blank" href="<?php site_url("in/terms_and_conditions");?>">terms and conditions</a>.
<input type='checkbox' name='terms' value='checked' id='terms' required autofocus/><br/>
Right now, it seems to work fine (codeigniter built in validation prompts up a message telling the user to click before he can proceed). Issue is 1. the link ("in/terms_and_conditions") does not show properly. Whenever the corresponding text is clicked, instead of showing the proper page, it just opens up a new sign up page.
Second issue is the presence of errors as follows:
Message: Undefined index: c_terms in model Line Number: 24
Line 24 is this:
'terms'=> $post_obj['c_terms']
I tried to add this to my array. Was it actually correct?
The second error shown is:
Column 'terms' cannot be null
INSERT INTO `client` (`first_name`, `last_name`, `email_address`, `password`, `address`, `tagline`, `profile`, `interests`, `billing_mode`, `terms`) VALUES ('dsfhkds', 'hfdskhflk', 'test#yahoo.com', '123456', 'fsdkfhsdk', 'sdkfhsdkf', 'sdklhfslkdhflsdhf', 'kdslhflks', 'Escrow', NULL)
What I did to my original table is I added column which I named "terms", set it to text type and no default value.
Please help me fix this.
Thanks!
Issue 1:
Did you create the page "in/terms_and_conditions" ? make sure?
Controller Name: in
Action Name : terms_and_conditions
Issue 2:
You have named checkbox as "terms". then, you should get the posted value as follows
'terms'=> $post_obj['terms']
Issue 3:
Set "terms" column default value as "NULL"
I see three problems:
You're not echoing the result of the site_url function. Just put echo in front of it.
If $post_obj is your '$_POSTarray you have to use thename` attribute of the HTML input as the key:
'terms' => $post_obj['terms']
Your problem is that you're not setting any text to be saved in terms. Add it to the second parameter of $this->db->insert('table', $data) like this: $data['terms'] = '...'
Hi I have been playing around with jqtouch today and I'm just wondering how to manage data.
I tried looking around but couldn't see much documentation.
If I had a list of links for say products? And I click on one i can navigate to the product 'view'. How to I pass variables like you would a $_GET variable to select THAT product?
Or even if I set the id of the link to the id of the record and use JS to grab the ID and somehow pass it to the next view?
Any help with this would be most appreciated!
NOTE: I also want to use it with the offline extension so I'm not sure get ajax would work
Regards,
Billy
You can use the referrer property for the data object. The link would look like:
Product #1
where the HTML ID would correspond to the product ID. Then in the "pageAnimationEnd" event you can retrieve the product details like this:
$('#view').bind('pageAnimationEnd', function (e, info) {
// get the id of the calling href
var id = $(this).data('referrer')[0].id;
$.getJSON('/products/' + id, function (data) {
// do something with the data
});
});
You could look at the demo to see how it does form submission, i.e. AJAX > POST Form Example. Essentially, you create a form and a jQT-style submit button:
<form id="ajax_demo" action="ajax_demo.php" method="POST" class="form">
...
<a class="submit whiteButton" href="#">Submit</a>
</form>
Then in your receiving page (i.e. ajax_demo.php), you can access the form fields, e.g. PHP's $_GET or JavaScript's location.search.
Another way is to store the data in the DOM with jQuery:
// in global level
$('body').data('ajax_demo', "some data for the page");
// in page/view level
$('#ajax_demo').data('key', 'value');
I have table enclosed by a div that looks similar to this.......
<div id="records">
10 | text1 | Delete
23 | test2 | Delete
24 | text3 | Delete
32 | text4 | Delete
</div>
I'd like to make the "Delete"s clickable which calls an ajax script to remove them from the database.
Each of the 'Delete's has a class of "delete_record"
The table is populated by an ajax script, so to avoid the rebinding issue, I'd like to use event bubbling on "records", so I added a click event on the div "records", and here I check for "delete_record" and currently just have an alert, which seems to work..
$('#records').click(function(event) {
if ($(event.target).is('.delete_record')) {
alert("clicked on CELL");
}
});
But what I really want is to access a record_id which the ajax script knows about, and pass this to the ajax script to delete the record.
I know how to call this ajax script with the correct values, what I don't know how to do is work out how to get this record _id
10 | text1 | Delete(20389)
23 | test2 | Delete(37474)
24 | text3 | Delete(2636)
32 | text4 | Delete(83731)
So when I click on the second line, the script will call....
$.getJSON("/ajax/delete_record.php",{id: 37474, ajax: 'true'}, function(j){ stuff }
You said the table is populated from ajax, so, you can actually store your metadata into the table, assuming the following html is generated:
<tr>
<td>23</td>
<td>test2</td>
<td><a>Delete</a></td>
<td class='id'>37474</td> <!-- Hide the id column in css if needed -->
</tr>
So, just to follow what you did, you if the 'cell' is clicked, then you just go back to parent of it and then look for the td.hasClass('id') and get the text within. Like:
var parentTR = $(event.target).parent('tr'); // Get the parent row
var id = $("td[class='id']", parentTR).html(); // Retrieve the id content
Now you have the id, you can just ajax it to server to delete it.
One more thing to add, I don't really agree on the event binding on the table or the parent div to locate the delete button, it sounds too indirect to me. JQ actually provide a good method to live binding events, try looking at Live Function in JQuery. It actually do a good job for your situation.