Set data from database to generated popup window in CakePHP - cakephp

I have created a popup window in cakephp.
<div id="pop_box">
<span id="close">×</span>
<h2>This is the Popup Box</h2>
<span id="selected_content"></span>
</div>
Now I want to set data to this popup window by getting data from database(MySql). Normally we are getting data from database for a new page using functions in controller. Here it is not a new page. How can I do this with that popup window?

first create a view for your controller action. the view file name has to be conventionally named i.e underscored version of the cooresponding controller action e.g if you have action named viewArticle the view file w'd be view_article.ctp
public function viewArticle(){
$data = $this->{$this->modelClass}->find('all',$conditions);
// here set your data to view
$this->set(compact('data'));
}
now create the view file (view_article.ctp)and paste your popup window code and your data from controller sh'd be readily accessible with $data
PS: the data to use with js popup window was preloaded. if you need your popup to get its data asynchronously then checkout cakephp + ajax usage they sh'd be couple them here on stackoverflow.

Related

How to get the current URL in Robot framework?

When the 'apply' link is clicked, it opens a new browser in Robot framework. How to get current url of that page? Here is the code:
Open Server
Set Browser Implicit Wait 60
Go To ${server}/jobs
Element Should Be Visible xpath=.//*[#id='txtjobsearch']
Input Text xpath=.//*[#id='txtjobsearch'] ${job Title search}
Element Should Contain xpath=(.//*[#class='clearfix tit-job']/div)[1] ${Job title}
Element Should Be Visible xpath=(.//*[#class='btn btn-sm btn-primary btnApply'])[1]
Click Element xpath=(.//*[#class='btn btn-sm btn-primary btnApply'])[1]
After this line, it opens a new window. How to get url of newly opened page and do actions like input text?
Set Browser Implicit Wait 20
Wait Until Page Contains Element xpath=.//*[#class='text-primary']
Try this:
${url}= Get Location
getting the current URL is easy using the Execute Javascript SeleniumLibrary keyword:
${url} = Execute Javascript return window.location.href;
Have you tried using the Select Window keyword?
http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html#Select%20Window
Click Link popup_link # opens new window
Select Window popupName
Title Should Be Popup Title
Select Window # Chooses the main window again
It seems like you wish to verify the url of the new window which should be easily possible with the following:
Select Window | url=https://google.com
Obviously you need to replace the above url with what you're expecting. Let us know how you get on.

Angular click for new page with infomation from clicked item JSON

I have a product page, and there is an option for a 'quick view' which opens the product description and images in a modal. I also have a 'full details' button where I would like the user to be taken to a new URL based on the item code, but also display the information from my JSON for that clicked product. This is what I have:
<a ng-click="store.selected = product" ng-href="{{store.selected.code}}.html" class="btn btn-sm">Full details</a>
Everything works great for the Modal, so I am presuming there is a problem moving onto a different page and carrying this information across? I have mocked it up in Plunker to show the problem:
Plunker here
Any help would be much appreciated.
You should consider using ng-route to switch the view to a different html file. But you can also use ng-include with a little less set up.
When the Full details link is clicked, toggle a variable that tracks whether the gallery or the details should be visible. And, construct the path to the html template you want to display:
$scope.setSelection = function(product) {
$scope.store.selected = product;
$scope.detail.show = !$scope.detail.show;
$scope.detail.source = product.code + '.html'
}
Then, use ng-include to display the template:
<div ng-if="detail.show" ng-include="detail.source">
</div>
Here is an update of your plunker: http://plnkr.co/edit/zhsY6TAjONewyInGiwUC?p=preview
Note that the template should just be a snippet of html.. you don't need to include scripts like angular again.

Open embedded Visualforce charts in new window

I have two embedded charts in a custom VF page that is then displayed on the Account detail screen. I'm passing the correct parameters and the reports work fine and display fine on the Account detail page.
<div class="col-md-6">
<analytics:reportChart reportId="00Oi0000005jhBz" cacheResults="true" size="medium" filter="[{column:'Order.Account.Id', operator:'equals', value:'{!Account.Id}'}]"></analytics:reportChart>
</div>
What I would like to do, however, is instead have a text link and those reports open up in a new window. Can embedded charts open in a new window and I pass the correct parameters via the URL?
I can get the reports to display in a new window fine, but I am unclear how to pass the correct filters in my link so the reports actually display the correct data:
<a href="/apex/getIndustryAccountReports?vID={!Account.ID}" target="_blank">
Are there certain ways I have to do this, so that the reports in the new window get passed the correct filters?
your Visualforce page can call on action
"init" would be a function on your controller like so:
public void init() {
String vid = ApexPages.currentPage.getParameters.get('vid');
}
You can now use "vid" to embed the report in your visualforce page.

Grails: save to Database without page reloading

How can i save the textfields and checkboxes to the DB without reloading the page?
Just to click on the button and then its in the DB. Nothing more. I don't get it. This means when I have a textfield where I type in a content -> then click the button, the content from the textfield should be in the DB and should do nothing more (not reloading the page, or go to top for example).
I don't get it.
EDIT:
When I have a a <div> tag with the id="testid" in the standard create.gsp:
def create() {
def mytestInstance = new Mytest(params)
}
and the <g:remoteLink> which should save this part looks like:
<g:remoteLink class="button" name="myForm" update="testid"
url="[controller:'mytest', action: 'create']" value="....." />
That does not work because the page is refreshing or something like this and the things are not stored in the DB, plus they are not in the textfields any more.
Use <g:formRemote> or <g:submitToRemote> to do the form submission with an Ajax call.
You should be able to use the formRemote tag to send the data to a controller via Ajax
Edit
As it says on that page;
This tag also requires the use of either the <g:javascript/>(link) or <g:setProvider/>(link) tags. See the AJAX section of the user guide to find out more.
Have you done that?

web2py - Dropdown menu

I'm trying to have a dropdown menu for the user to select the database table. I have defined few tables in db.py and I want the user the to select a particular table from a dropdown menu and insert entries. Right now I use SQLFORM:
def index():
form=SQLFORM(db.selectedtable) #want to change the table name#
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill out the form'
return dict(form=form)
I need the user to select 'selectedtable' value from a dropdown list that shows all the available tables in the DB. I do not necessarily want to retrieve the table values from DB. I am OK with defining a list with the available tables and the dropdown menu can pull the table names from that list.
So far I only found IS_IN_DB to automatically create a dropdown and PluginDropdown() but that does not serve my purpose. If soemebody can direct me to the proper way of handling this task I'd be really thankful.
Regards.
Update:
After Anthony's suggession I tried the following with , as I'm not that familiar with JS.
{{extend 'layout.html'}}
{{select='NONE'}}
<form>
<select>
{{for item in TOOLS:}}
<option value="{{select=item}}">{{=item}}</option>{{pass}}
</select>
<input type="submit" value="Go!"/>
</form>
<h2>Input form</h2>
{{=form}}
<h2>{{=select}}</h2>
As you might see this doesn't work properly. What I tried to do is to get the user chose value to 'select' variable. But it doesn't work. It always gets the last element in ITEMS (this list is defined in db.py). My next option would be to be call another controller function, passing the user selected value as an argument. Then it can prepare the form with the passed value and send to a view to display
<h2>Input form</h2>
{{=form}}
But I'm not sure how I can assign the user chosen value to an argument and then call another controller function with that arugument value.
If you have any suggestion how I can modify this to get the user chosen value thats very much appreciated. Thank you.
You could create a <select> element listing all the tables, and then load the form associated with the selected table as a web2py component via Ajax. In the view of the main page (e.g., /views/default/index.html):
<script>
jQuery(function() {
jQuery('#table').change(function() {
web2py_component("{{=URL('default', 'form.load')}}" + "/" +
jQuery(this).val(), target='form')
})
})
</script>
{{=SELECT('Select a table', *db.tables, _id='table')}}
<div id="form"></div>
And in a controller (e.g., default.py):
def form():
if request.args(0) in db.tables:
response.generic_patterns = ['load']
return dict(form=SQLFORM(db[request.args(0)]).process())
else:
raise HTTP(404)
Note, db.tables is a list of all the tables defined on the db connection object -- it is used in the SELECT() helper in the view to generate a <select> list of all the tables. The script in the view registers a jQuery event handler that fires whenever a different table is selected from the dropdown. The handler calls the web2py_component() function (which is in /static/js/web2py.js), which loads the form component via Ajax into the div with id="form". It appends the value of the selected table to the URL.
In the controller, the form() function checks for the db table name in request.args(0). It then sets response.generic_patterns so the "generic.load" view will be allowed (by default, generic views are only enabled for local requests). Alternatively, you could define your own "form.load" view, or even use a different extension (e.g., "form.html").
Because the form is loaded as a web2py Ajax component, the form submission will be trapped and submitted via Ajax as well, so it will not result in a full page reload.

Resources