Hi Marc,
I started working on improving the "*Add a new user in db-> privileges*" by providing a dialog such as in "*Add a new user in Server->privilege*" option. In that case I'm going to reuse the code in "(#fieldset_add_user).click" action in server_privileges.js file. The only modification I had to do is add the class="ajax" to link on db->privileges and now it pops up the dialog box. The next part is, after adding a new user we have to add that user to the list table in db->privileges and then sort it according to the alphabetical order of user names. In server->privileges, "*appendNewUser() in server_privileges.js" *method has used and it is sorting the rows be selecting the first character in the label and then according to that. It is okay because server->privileges table has same type of rows. But in "* db->privileges*" table it has used two type of rows where one shows columns related to "global" privileges and other is to database specific privileges corresponding to each user. So I cannot use the same "*appendNewUser() in server_privileges.js"* method to add and sort the table. I came up with some approaches to overcome this problem.
1. Change the table structure where do not use two rows but use same row and line break to get them down. In this case I'll be able to reuse the same method where I think more appropriate in this case. 2. Do a refresh to the "*db->privileges*" page so it reloads the table. 3. Keep the table as it is in current and develop a method to sort it.
I'm confused with what method to use. So please can you clarify me on this problem. Thank you.
Regards, Thilanka.
Le 2011-05-27 12:34, Thilanka Kaushalya a écrit :
Hi Marc,
I started working on improving the "*Add a new user in db-> privileges*" by providing a dialog such as in "*Add a new user in Server->privilege*" option. In that case I'm going to reuse the code in "(#fieldset_add_user).click" action in server_privileges.js file. The only modification I had to do is add the class="ajax" to link on db->privileges and now it pops up the dialog box.
Hi Thilanka, I assume that this class will be added only if $cfg['AjaxEnable'] is true.
The next part is, after adding a new user we have to add that user to the list table in db->privileges and then sort it according to the alphabetical order of user names. In server->privileges, "*appendNewUser() in server_privileges.js" *method has used and it is sorting the rows be selecting the first character in the label and then according to that. It is okay because server->privileges table has same type of rows. But in "* db->privileges*" table it has used two type of rows where one shows columns related to "global" privileges and other is to database specific privileges corresponding to each user. So I cannot use the same "*appendNewUser() in server_privileges.js"* method to add and sort the table. I came up with some approaches to overcome this problem.
- Change the table structure where do not use two rows but use same row
and line break to get them down. In this case I'll be able to reuse the same method where I think more appropriate in this case. 2. Do a refresh to the "*db->privileges*" page so it reloads the table. 3. Keep the table as it is in current and develop a method to sort it.
I'm confused with what method to use. So please can you clarify me on this problem. Thank you.
I suggest going for #2, provided this is done via AJAX (only refresh the usersForm by obtaining the new list from a call to server_privileges.js).
So in server_privileges.php starting at line 2142, instead of using echo to generate the form, it would be gathered in a variable using a logic similar to the one in server_privileges.php starting at line 1357. Then it's either echoed if not coming from an ajax request, or sent via PMA_ajaxResponse().
P.S. can you update http://wiki.phpmyadmin.net/pma/AJAXify_Interface when one of your features is implemented?
Hi Marc,
I assume that this class will be added only if $cfg['AjaxEnable'] is true.
Yes.
I suggest going for #2, provided this is done via AJAX (only refresh the usersForm by obtaining the new list from a call to server_privileges.js).
So in server_privileges.php starting at line 2142, instead of using echo to generate the form, it would be gathered in a variable using a logic similar to the one in server_privileges.php starting at line 1357. Then it's either echoed if not coming from an ajax request, or sent via PMA_ajaxResponse().
I went through the process which you have mentioned above. I have replaced echo with collecting variable called $user_form and then handled the ajax_enabeled action as follows.
if($GLOBALS['is_ajax_request'] == true){ $extra_data['user_form'] = $user_form; $message = PMA_Message::success(__('New user has been added.')); PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); }
And in my server_privileges.js file I have called the post method as follows. $testing_parameters = "db=super_store&server=1&token=c6ad5e8e3a8042287e401dc5e739280a&checkprivs=super_store&viewing_mode=db&ajax_request=true"; $.post( $form.attr('action'), $testing_parameters, function(mydata){ $("#usersForm").append(mydata); });
I have used hard coded parameters in $testing_parameters variable and the append the datafor $("#uerForm") for test the feature.
But the appended my data does not returns an json object. it just return a string containing the results. I have share screen shots of the alert and the UI which shows the returned $mydata string with this doc [1]. Can you help me on why this happens.
If I'm not going to use the PMA_ajaxResponse() method I can just take the whole post data and extract the new #usersForm out of that and repalace the old one.
Please help me on this issue. Thank you.
[1] - https://docs.google.com/document/d/1DLcwm4VJv-IrLBiwlRwFPs4oaSuC_bPOsxrJ99xW...
Regards, Thilanka.
Le 2011-05-29 01:38, Thilanka Kaushalya a écrit :
Hi Marc,
(...)
So in server_privileges.php starting at line 2142, instead of using echo to generate the form, it would be gathered in a variable using a logic similar to the one in server_privileges.php starting at line 1357. Then it's either echoed if not coming from an ajax request, or sent via PMA_ajaxResponse().
I went through the process which you have mentioned above. I have replaced echo with collecting variable called $user_form and then handled the ajax_enabeled action as follows.
if($GLOBALS['is_ajax_request'] == true){ $extra_data['user_form'] = $user_form; $message = PMA_Message::success(__('New user has been added.')); PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); }
And in my server_privileges.js file I have called the post method as follows. $testing_parameters = "db=super_store&server=1&token=c6ad5e8e3a8042287e401dc5e739280a&checkprivs=super_store&viewing_mode=db&ajax_request=true"; $.post( $form.attr('action'), $testing_parameters, function(mydata){ $("#usersForm").append(mydata); });
I have used hard coded parameters in $testing_parameters variable and the append the datafor $("#uerForm") for test the feature.
But the appended my data does not returns an json object. it just return a string containing the results. I have share screen shots of the alert and the UI which shows the returned $mydata string with this doc [1]. Can you help me on why this happens.
Thilanka, I don't understand why you are talking about a JSON object. JSON is a text-based notation and in your first screenshot, the text shown is in JSON. It contains a variable "message" with a large chunk of generated HTML. This is fine.
For an example on how this is handled, look in libraries/sql.js in the section $("#sqlqueryform.ajax") to see what is done with data.message.
Please use a similar logic for code consistency with the other parts already ajaxified.
If I'm not going to use the PMA_ajaxResponse() method I can just take the whole post data and extract the new #usersForm out of that and repalace the old one.
Please help me on this issue. Thank you.
[1] - https://docs.google.com/document/d/1DLcwm4VJv-IrLBiwlRwFPs4oaSuC_bPOsxrJ99xW...
Hi Marc,
I don't understand why you are talking about a JSON object. JSON is a text-based notation and in your first screenshot, the text shown is in JSON. It contains a variable "message" with a large chunk of generated HTML. This is fine.
This is pure text kind of thing. I cannot get the message by calling it mydata.message.
For an example on how this is handled, look in libraries/sql.js in the section $("#sqlqueryform.ajax") to see what is done with data.message.
I went through similar scenarios handled in functions.js and sql.js. But in all those cases the "data" variable returns an object. So we can call the elements such as data.sucess , data.message, data.sql_query out of that element. I attached the screenshot of the echo of that object within the function.sql $("#create_table_form input[name=do_save_data]").live('click') event here as the 1st image [1].
But the variable mydata in the server_privileges.js is not an object kind of thing. So we cannot call the elements such as mydata.sucess , mydata.message, mydata.user_form. When we call them it shows those are "undefined". Thats why I cannot handle this situation.
[1] - https://docs.google.com/document/d/1DLcwm4VJv-IrLBiwlRwFPs4oaSuC_bPOsxrJ99xW...
Regards, Thilanka.
Le 2011-05-29 12:41, Thilanka Kaushalya a écrit :
Hi Marc,
I don't understand why you are talking about a JSON object. JSON is a text-based notation and in your first screenshot, the text shown is in JSON. It contains a variable "message" with a large chunk of generated HTML. This is fine.
This is pure text kind of thing. I cannot get the message by calling it mydata.message.
For an example on how this is handled, look in libraries/sql.js in the section $("#sqlqueryform.ajax") to see what is done with data.message.
I went through similar scenarios handled in functions.js and sql.js. But in all those cases the "data" variable returns an object. So we can call the elements such as data.sucess , data.message, data.sql_query out of that element. I attached the screenshot of the echo of that object within the function.sql $("#create_table_form input[name=do_save_data]").live('click') event here as the 1st image [1].
But the variable mydata in the server_privileges.js is not an object kind of thing. So we cannot call the elements such as mydata.sucess , mydata.message, mydata.user_form. When we call them it shows those are "undefined". Thats why I cannot handle this situation.
[1] - https://docs.google.com/document/d/1DLcwm4VJv-IrLBiwlRwFPs4oaSuC_bPOsxrJ99xW...
Regards, Thilanka.
Thilanka, I'm not sure why sometimes the returned data is not considered to be an object. It might be because, in the case of long strings, we are not respecting JSON in some manner. In this case, you can use logic similar to the one in sql.js where we use typeof
if (typeof data.success != 'undefined') { ... } else { ... }
P.S. are you using Firebug? it's an invaluable tool to debug these kind of things.
Hi Marc,
I updated the repo with my latest changes to the "Add a new user" in db->privileges. Now it correctly popup the dialog when a user clicks on the "Add a new user" in db->privileges and then updates the userTable after submitting the form. Please check that.
I'm not sure why sometimes the returned data is not considered to be an object. It might be because, in the case of long strings, we are not respecting JSON in some manner. In this case, you can use logic similar to the one in sql.js where we use typeof
if (typeof data.success != 'undefined') { ... } else { ... }
I used the var obj = $.parseJSON(mydata); function to validate the json
string.
P.S. are you using Firebug? it's an invaluable tool to debug these kind of things.
I'm using the firebug tool.
Regards, Thilanka.
Thilanka Kaushalya a écrit :
Hi Marc,
I updated the repo with my latest changes to the "Add a new user" in db->privileges. Now it correctly popup the dialog when a user clicks on the "Add a new user" in db->privileges and then updates the userTable after submitting the form. Please check that.
It works fine, but after creating this user, if I click again on Privileges for this db, I get
Notice in ./server_privileges.php#1425 Undefined variable: message
I used the var obj = $.parseJSON(mydata); function to validate the json string.
Good idea.
Hi Marc,
It works fine, but after creating this user, if I click again on Privileges for this db, I get
Notice in ./server_privileges.php#1425 Undefined variable: message
When I test this I cannot find such an error. Is it occurs when after adding a new user and then click on the privileges tab in the "top_menu_container" in the same database. Please can you clarify my the scenario.
Regards, Thilanka.
On Wed, Jun 1, 2011 at 8:39 AM, Thilanka Kaushalya lgtkaushalya@gmail.comwrote:
Hi Marc,
It works fine, but after creating this user, if I click again on Privileges for this db, I get
Notice in ./server_privileges.php#1425 Undefined variable: message
When I test this I cannot find such an error. Is it occurs when after adding a new user and then click on the privileges tab in the "top_menu_container" in the same database. Please can you clarify my the scenario.
Regards, Thilanka.
Most probably you have not enabled displaying errors. Check whether you have $cfg['Error_Handler']['display'] = true; in your config.inc.php. If not pls add it there, so it will display notice level errors.
Hi Madura,
Most probably you have not enabled displaying errors. Check whether you have $cfg['Error_Handler']['display'] = true; in your config.inc.php. If not pls add it there, so it will display notice level errors.
Thanks for the tip. I'll check that.
Regards, Thilanka.
Hi Marc,
It works fine, but after creating this user, if I click again on Privileges for this db, I get
Notice in ./server_privileges.php#1425 Undefined variable: message
I fixed the bug and committed to the repo. Please check that. Thank you.
Regards, Thilanka.
Thilanka Kaushalya a écrit :
Hi Marc,
It works fine, but after creating this user, if I click again on Privileges for this db, I get Notice in ./server_privileges.php#1425 Undefined variable: message
I fixed the bug and committed to the repo. Please check that. Thank you.
Thilanka, with the same scenario, at the same point I now see:
Warning in ./libraries/common.lib.php#2917 Cannot modify header information - headers already sent by (output started at server_privileges.php:1440)
Backtrace
./libraries/common.lib.php#2917: header(string Cache-Control: no-cache) ./server_privileges.php#2296: PMA_ajaxResponse( object, boolean 1, array, )
Hi Marc,
Thilanka,
with the same scenario, at the same point I now see:
Warning in ./libraries/common.lib.php#2917 Cannot modify header information - headers already sent by (output started at server_privileges.php:1440)
Backtrace
./libraries/common.lib.php#2917: header(string Cache-Control: no-cache) ./server_privileges.php#2296: PMA_ajaxResponse( object, boolean 1, array, )
I fixed the issue of giving warnings regarding the header modification, and updated the repository. Please can you check that. Thank you.
Regards, Thilanka.
Le 2011-06-03 13:24, Thilanka Kaushalya a écrit :
Hi Marc,
Thilanka,
with the same scenario, at the same point I now see:
Warning in ./libraries/common.lib.php#2917 Cannot modify header information - headers already sent by (output started at server_privileges.php:1440)
Backtrace
./libraries/common.lib.php#2917: header(string Cache-Control: no-cache) ./server_privileges.php#2296: PMA_ajaxResponse( object, boolean 1, array, )
I fixed the issue of giving warnings regarding the header modification, and updated the repository. Please can you check that. Thank you.
Thilanka, I see a new problem and I'm not sure when it was introduced. I think it's better to fix this one, then I can continue evaluating the whole.
Here is the scenario (tested in FF 4.0.1 / Vista)
1. Click Databases 2. For a database, click Check Privileges 3. Click Add a new user 4. Fill minimum values in the popup (a name, generate password) and create the user 5. User gets created but Firebug tells me that there was a JSON parse error; the list of privileges for this db does not show up (I think I saw it in previous tests)
Hi Marc,
I see a new problem and I'm not sure when it was introduced. I think
it's better to fix this one, then I can continue evaluating the whole.
Here is the scenario (tested in FF 4.0.1 / Vista)
- Click Databases
- For a database, click Check Privileges
- Click Add a new user
- Fill minimum values in the popup (a name, generate password) and
create the user 5. User gets created but Firebug tells me that there was a JSON parse error; the list of privileges for this db does not show up (I think I saw it in previous tests)
I fixed the issue and updated the repo. Please check it. Sorry for troubling you many times. Thank you.
Regards, Thilanka.
Le 2011-06-04 13:57, Thilanka Kaushalya a écrit :
Hi Marc,
I see a new problem and I'm not sure when it was introduced. I think
it's better to fix this one, then I can continue evaluating the whole.
Here is the scenario (tested in FF 4.0.1 / Vista)
- Click Databases
- For a database, click Check Privileges
- Click Add a new user
- Fill minimum values in the popup (a name, generate password) and
create the user 5. User gets created but Firebug tells me that there was a JSON parse error; the list of privileges for this db does not show up (I think I saw it in previous tests)
I fixed the issue and updated the repo. Please check it. Sorry for troubling you many times. Thank you.
Works fine now. Are you done with this feature? Before I put it in production, please polish your code in js/server_privileges.js:
- remove tab characters (we use indents of four spaces)
- use spaces around operators "url.length-23" should be "url.length - 23"
- watch proper code indentations
- use more spaces around keywords "if(" should be "if (" "}else{" should be "} else {"
Thanks,
Hi Marc,
Works fine now. Are you done with this feature? Before I put it in
production, please polish your code in js/server_privileges.js:
- remove tab characters (we use indents of four spaces)
I'm using 4 space indentation . I checked the code but I cannot find where
have added tab characters.
- use spaces around operators
"url.length-23" should be "url.length - 23"
Okay I fixed that.
watch proper code indentations
use more spaces around keywords
"if(" should be "if (" "}else{" should be "} else {"
Okay I fixed that.
I fixed the above issues and pushed to the repo. Please check that.
Regards, Thilanka.
Le 2011-06-04 22:29, Thilanka Kaushalya a écrit :
Hi Marc,
Works fine now. Are you done with this feature? Before I put it in
production, please polish your code in js/server_privileges.js:
- remove tab characters (we use indents of four spaces)
I'm using 4 space indentation . I checked the code but I cannot find where
have added tab characters.
- use spaces around operators
"url.length-23" should be "url.length - 23"
Okay I fixed that.
watch proper code indentations
use more spaces around keywords
"if(" should be "if (" "}else{" should be "} else {"
Okay I fixed that.
I fixed the above issues and pushed to the repo. Please check that.
Regards, Thilanka.
Thanks, this feature is now part of origin/master. Please have a look at my commit a7a20980067c9c9dc436e59129cb420d0badafa3 because this time there were too many spaces :)
Hi Marc,
Thanks, this feature is now part of origin/master. Please have a look at my commit a7a20980067c9c9dc436e59129cb420d0badafa3 because this time there were too many spaces :)
I went through your commit. I'll follow that style in the future changes. Thanks for your help. I'll write the blog post at night.
Regards, Thilanka.
Hi Marc,
I wrote a blog post[1] on my second task which is ajaxify the ''Add a new user" option in in db->privileges.
Next week I'll start with ajaxify the "Insert for table" in db->structure.
[1] - http://coders-view.blogspot.com/2011/06/ajaxify-phpmyadmin-interface-gsoc-20...
Regards, Thilanka.