Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: How do I can load a new intraweb form with javascript/jquery?



Permlink Replies: 6 - Last Post: Jan 2, 2017 1:41 PM Last Post By: Luiz Oliveira
Luiz Oliveira

Posts: 133
Registered: 8/19/09
How do I can load a new intraweb form with javascript/jquery?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 31, 2016 6:45 AM
How could I load a new intraweb form into javascript with a link?
I have the next javascript that fill some links in runtime:
<script>
	 			function update_html(data){ 
				  	for (i=0; i<data.length; i++){
					 var title =$("<a></a>").html(imageInfo.nome).attr("href","what I put here to load a new intraweb form, such as IWMyForm?");
					 // I have used attr("href","IWMyForm.html") but it doesnt work
                                         $("#tab_body").append(div);
					 }
				}
 
</script>


Edited by: Luiz Oliveira on Dec 31, 2016 6:46 AM

Edited by: Luiz Oliveira on Dec 31, 2016 6:47 AM
Daniel Fields

Posts: 595
Registered: 11/29/04
Re: How do I can load a new intraweb form with javascript/jquery?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 31, 2016 1:56 PM   in response to: Luiz Oliveira in response to: Luiz Oliveira
I'm just curious, why you are doing it in java script? It seems like a lot of unnecessary work. It would be easier to do all of that in straight Delphi code.
Luiz Oliveira

Posts: 133
Registered: 8/19/09
Re: How do I can load a new intraweb form with javascript/jquery?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 31, 2016 3:06 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
I'm just curious, why you are doing it in java script? It seems like a lot of unnecessary work. It would be easier to do all of that in straight Delphi code.

I am using templates with bootstrap and javascript in my pages.

I have used bootstrap sometimes with wordpress.

I am doing it because I am using bootstrap to layout my pages(No IW bootstrap).

I am doing an appointment app and I have a firebird database where I need loop into a table and shows the result (for sample, i need to show photo and name of the physicians).

I am using a datasnap rest server and I get the results of the database using it.

After several days I just managed to do it using something as:

ServerController unit:
procedure TIWServerController.IWServerControllerBaseBeforeRender(
  ASession: TIWApplication; AForm: TIWBaseForm; var VNewForm: TIWBaseForm);
var FParams:TStrings;
begin
    FParams := ASession.Request.QueryFields;
    if (FParams.Count > 1) and (FParams.Values['aparam']='planos') then begin
       VNewForm:=TIWBaseForm(UserSession.ShowForm(TIWFormPlanos));
    end else if (FParams.Count > 1) and (FParams.Values['aparam']='medicos') then begin
       VNewForm:=TIWBaseForm(UserSession.ShowForm(TIWFormMedicos));
    end else if (FParams.Count > 1) and (FParams.Values['aparam']='convenios') then begin
       VNewForm:=TIWBaseForm(UserSession.ShowForm(TIWFormConvenios));
    end else if (FParams.Count > 1) and (FParams.Values['aparam']='calendar') then begin
       VNewForm:=TIWBaseForm(UserSession.ShowForm(TIWFormCalendar));
    end;
end;


and

Usersession Unit
 
//Thanks to Alexandre - code posted in the other  topic
function TIWUserSession.ShowForm(AFormClass: TIWAppFormClass):TComponent;
var
  myFormInstance: TComponent;
begin
  myFormInstance :=  WebApplication.FindFormByClassName(AFormClass.ClassName);
  if not Assigned(myFormInstance) then begin
    myFormInstance := AFormClass.Create(WebApplication);
  end;
  TIWAppForm(myFormInstance).Show;
  result:=myFormInstance;
end;


I also use the next when the for is created to get the parameter and pass to javascript of a new page(form):
procedure TIWFormCalendar.IWAppFormCreate(Sender: TObject);
var req:THttpRequest;
    s:string;
begin
  WebApplication.RegisterCallBack('OnCalendarClick', OnCalendarClick);
  req:=WebApplication.Request;
  s:=req.queryfields.Values['nm'];
  JavaScript.Text:='var nr_med='+s+';';
end;

After that, I can use the parameter in the next form with html template and javascirpts.

I have read your post, I am a newbie, but I can see you are a expert.

I am using ajax to fill the database data into my pages.

Using delphi code directly, as I am a newbie, I don´t know how create a beatiful screen without to use Bootstrap. I will have much more work to do.

Do you can see something wrong in my approach?

Edited by: Luiz Oliveira on Dec 31, 2016 3:20 PM

Daniel Fields

Posts: 595
Registered: 11/29/04
Re: How do I can load a new intraweb form with javascript/jquery?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 31, 2016 10:30 PM   in response to: Luiz Oliveira in response to: Luiz Oliveira
I do not see anything wrong with your approach. IW was designed so you could mix code and Java script. I was curious because I use far more code than java script. I consider myself to be in learning mode when it comes to java script. Knowing it will make you a better Intraweb developer. I would point out two things:

1. You might want to use IWBootstrap to make things easier from a design perspective. See this post on the library http://www.atozed.com/intraweb/Blog/20151028.EN.aspx .

2. You might also be able to use an IWLabel with its RawText property set to True. You could create your link in code by putting straight HTML in the caption. When the page is rendered it will appear and function as a normal link. You can use that technique for many things, such as displaying PDFs.
Luiz Oliveira

Posts: 133
Registered: 8/19/09
Re: How do I can load a new intraweb form with javascript/jquery?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 1, 2017 4:02 AM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
I do not see anything wrong with your approach. IW was designed so you could mix code and Java script. I was curious because I use far more code than java script. I consider myself to be in learning mode when it comes to java script. Knowing it will make you a better Intraweb developer. I would point out two things:

1. You might want to use IWBootstrap to make things easier from a design perspective. See this post on the library http://www.atozed.com/intraweb/Blog/20151028.EN.aspx .

2. You might also be able to use an IWLabel with its RawText property set to True. You could create your link in code by putting straight HTML in the caption. When the page is rendered it will appear and function as a normal link. You can use that technique for many things, such as displaying PDFs.

Thank you.
I think with IW bootstrap I can´t use html templates. Am I sure?

It becomes difficult to use IW bootstrap when the page has many controls. There is no space to put many components in a single form.

I like your tip about IWlabel.

Could you help with how put the image blob(jpg) from database into IWlabel?
And, can I use the next code in async mode?
I need something as:

var s,t:string;
    ds:TDataset;
begin
   ds:=DataSource1.DataSet;
   if not ds.Active then ds.open;
   ds.First;
   i:=0;
   while not ds.Eof do begin
    img_blob:=GetStreamBlob(ds.fieldbyname('logo'); //get logo image from local database
    t:=t+ '<div class="" col-md-4''>';
    t:=t+ '<a href="#" #''>';
    t:=t+ '<img src='''+img_blob+''' width=''75px'' height=''50px'' alt=''Ortocenter''  >'+ds.FieldByName('nome').AsString;;
    t:=t+'</a><br>';
    t:=t+ '</div>';
    ds.Next;
   end;
   ds.Close;
   s:=t;
  IWLabel.Text:=s;
end;


Edited by: Luiz Oliveira on Jan 1, 2017 4:10 AM
Jose Nilton Pace

Posts: 90
Registered: 5/15/98
Re: How do I can load a new intraweb form with javascript/jquery?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 2, 2017 4:57 AM   in response to: Luiz Oliveira in response to: Luiz Oliveira
Hi Luiz, put a componente TIWDBImage on your form, don't need to put nothing on CSS.
DataSource := DataSource1.DataSet;
DataField := ds.fieldbyname('logo');

and in your template file, something like this:
<div class="col-md-4 col-xs-4">
  <div class="form-group">
    {%IWDBImage%}
  </div>
</div>
Luiz Oliveira

Posts: 133
Registered: 8/19/09
Re: How do I can load a new intraweb form with javascript/jquery?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 2, 2017 1:41 PM   in response to: Jose Nilton Pace in response to: Jose Nilton Pace
Jose Nilton Pace wrote:
Hi Luiz, put a componente TIWDBImage on your form, don't need to put nothing on CSS.
DataSource := DataSource1.DataSet;
DataField := ds.fieldbyname('logo');

and in your template file, something like this:
<div class="col-md-4 col-xs-4">
  <div class="form-group">
    {%IWDBImage%}
  </div>
</div>

Ok, thank you.

But I need to create a thumbnail with the database images. Each Image with photo and name, as a image Gallery.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02