Web Components: model property type "function"?

Forum to discuss the new web client version of Servoy.

Web Components: model property type "function"?

Postby sergei.sheinin » Fri Mar 31, 2017 5:00 pm

In integrating web component "TinyMCE" I came across a property type that is "function" according to that component API:

Code: Select all
tinymce.init({
  toolbar: 'mybutton',
  setup: function (editor) {
    editor.addButton('mybutton', {
      text: 'My button',
      icon: false,
      onclick: function () {
        editor.insertContent('&nbsp;<b>It\'s my button!</b>&nbsp;');
      }
    });
  },
...
}


Above there are two properties: toolbar and setup. It's all clear with "toolbar", I define it as a string parameter in .spec file:
Code: Select all
"model": {
    "toolbar": {
      "type": "string",
      "default": "undo redo | etc, etc..."
    },
...
}


What is the right way to configure a property of type "function"? I didn't find a mention of it in the manual. Moreover the aforementioned "setup" function can only be called at time of initialization. It doesn't appear possible to call "tinymce.init({})" after the component has been initialized.


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

Re: Web Components: model property type "function"?

Postby sergei.sheinin » Sat Apr 01, 2017 7:56 am

I was able to find a workaround for this. It's very specific to TinyMCE component and one of its features. If interested I may post my solution here.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Web Components: model property type "function"?

Postby patrick » Sat Apr 01, 2017 6:36 pm

We are always interested in solutions :-). Please post!

We also hope that you make the component you are working on available to the community when finished!
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Web Components: model property type "function"?

Postby tgs » Sun Apr 02, 2017 11:22 am

+1
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: Web Components: model property type "function"?

Postby sergei.sheinin » Sun Apr 02, 2017 7:10 pm

The workaround was quite simple. A function is executed in component controller upon a condition based on setting of a model property:


Code: Select all
controller: function($scope, $element, $attrs, $window) {

    $scope.tinymceOptions = {
            .....
           setup : function ( editor ) {
              
             if (!$scope.model.to_execute_function) return
              else
                 ... function logic..
            }
   }



So for example let's specify a model parameter "to_execute_function": {type:"boolean"}. Thus we don't need to provide the function body in a web component's .spec file. Instead it's written in plain JavaScript with a condition that decides whether to run it or not. I think future versions of Servoy will need to support model parameters like "setup" : {"function":"<reference to function body>"} to make it more straightforward while my workaround seems a bit of a hack.

I'm new to Servoy web components while there is little documentation on types of model parameters NG Client supports. Imo Servoy should support non-basic model parameters of type "function", "array[]" and "json". Unless I'm missing it those types are not yet supported while they are widely used in NG dev. Are there plans to include support for these? In particular support of "array[]", "json" and "array[json]" would be very welcome.

For example like so:

Code: Select all
"model":{
  "my_param": {
      "type" : "array[json]",
      "default": {
            "key": "_mykey",
            "value": "_myvalue",
             "etc": "_myetc"
         }
    }
  }


And properties window in Eclipse would then enable developers to add array elements of "my_param" one-by-one.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Web Components: model property type "function"?

Postby patrick » Sun Apr 02, 2017 9:36 pm

There is support for all of that. function is "function", array is "string[]", "int[]", ... or even "yourOwnType[]", json is "object". Have you read this https://wiki.servoy.com/display/DOCS/Property+Types and its sub pages?
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Web Components: model property type "function"?

Postby Gabi Boros » Mon Apr 03, 2017 7:39 am

Servoy's default 'Html Area' component is also based on TinyMCE, maybe it can be useful to have a look how it is used there https://github.com/Servoy/servoy-client ... t/htmlarea
Gabi Boros
Servoy
Gabi Boros
 
Posts: 404
Joined: Tue Jun 26, 2007 4:03 pm
Location: Timisoara, Romania

Re: Web Components: model property type "function"?

Postby sergei.sheinin » Mon Apr 03, 2017 10:21 am

patrick wrote:There is support for all of that. function is "function", array is "string[]", "int[]", ... or even "yourOwnType[]", json is "object". Have you read this https://wiki.servoy.com/display/DOCS/Property+Types and its sub pages?



It worked beautifully! My mistake was in typing "array[]" in model parameter type.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Web Components: model property type "function"?

Postby patrick » Mon Apr 03, 2017 10:26 am

It worked beautifully!
It's Servoy :wink:
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 6 guests