Layout properties in Web Component controller

Forum to discuss the new web client version of Servoy.

Layout properties in Web Component controller

Postby sergei.sheinin » Wed Apr 05, 2017 9:55 am

What is the proper command for accessing properties of an element's layout from Web Component "controller"? Attached are screenshots of properties in Servoy designer and result of console.log($scope) from browser window. I need to get for example "height="172px"" from "console.log(??)".

Sorry this may seem like a simple question, I wasn't able to look up relevant documentation.


Thanks.
You do not have the required permissions to view the files attached to this post.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Layout properties in Web Component controller

Postby patrick » Wed Apr 05, 2017 2:25 pm

I think it's easiest you expose them on the model in your spec file. For example add something like this

Code: Select all
"size": { "type" :"dimension",  "default" : {"width": 600, "height": 400} }


@see https://wiki.servoy.com/display/DOCS/Property+Types
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Layout properties in Web Component controller

Postby patrick » Wed Apr 05, 2017 2:26 pm

This will also allow you to specify the defaults used when you drag your component to a form...
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Layout properties in Web Component controller

Postby sergei.sheinin » Wed Apr 05, 2017 5:42 pm

I was aware of this one. Web component I'm coding has special API call to set height/width, it doesn't respond to Servoy settings. Thus I was wondering if there was a way to access Layout properties in "controller" so the size can be set programmatically.

Any suggestions?
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Layout properties in Web Component controller

Postby paronne » Wed Apr 05, 2017 6:25 pm

Hi,

Which is your use case, why do you need to retrieve height and width ?

In non-responsive form components are wrapped within a div which automatically gets the proper posizion/size depending on the Layout settings of the element.
Most of the time would be enough to style properly your component so that will use 100% of height and width of it's container: (width:100%, height:100%).

Each webcomponents in non responsive form supports the API elements.yourComponent.setSize(x,y);
You will see a warning in the code editor but this API is available for all components since operate with the container of the component, not with the component itself.

In rare occasion you may need to know the exact width and height; for example if your webcomponent contains a canvas, a chart or similar.
In this case you can retrieve the exact width/height from it's parent wrapper.

You may want to listen for changes in the window size to recalculate the height width.

Code: Select all
    function resize() {
     if ($element.parent().hasClass('svy-wrapper')) { // if doesn't have a .svy-wrapper class you are not in an anchored form.
      var height =  $element.parent().height();
      var width =  $element.parent().width();
      // do something with width and height
     }
    }

// width/height changes when the window is resized.
$(window).on('resize', resizeButton);

// remove the resize listener when the component is destroyed
$scope.$on("$destroy", function() {
      $(window).off('resize', resize);
});


Regards,
Paolo
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: Layout properties in Web Component controller

Postby sergei.sheinin » Wed Apr 05, 2017 7:28 pm

paronne wrote:Hi,

Which is your use case, why do you need to retrieve height and width ?




If I can retrieve w/h - I can call appropriate functions in controller to set the size. Imo it ought to be possible to get Layout properties, for example through $scope. In fact they are visible in $scope as shown in attachment in first message. Maybe Servoy will include such functionality if it isn't there already?
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Layout properties in Web Component controller

Postby sergei.sheinin » Sat Apr 08, 2017 3:42 am

I was looking for this:

Code: Select all
$scope.$parent.layout[$attrs.name].height


All works well now.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 3 guests

cron