Tools plugin for everybody

Tools plugin for everybody

Hello forum,

Just for the fun of it I wanted to be the first (I hope or else one of the first) to give you the taste of a homebrew Plugin for Servoy.

Not too much but for me very convenient with three methods:

  • dateFormat: very much like the Java dateFormat class to convert a date to a string and the other way around with (or without) a formatting string;
  • secondsFormat: to make a number of seconds a string formatted like HH:mm:ss
  • validateEmail: based on a method I posted earlier on this forum now as a method in this plugin. It takes a string with one or more email adresses and checks if the format is right.

The reason I made them (initially for my own use) was that I needed to do the same calculation over and over again on different forms. However you can’t reach a method via a calculation field.

I didn’t want to ask for a feature since the guys at Servoy are already busy enough and to trigger myself to learn Java and making a Plugin.

The result is attached. Just drop it in your plugins folder and restart Servoy.

Feel free to use it and distribute it.

Any suggestions? Please let me know!
Any bugs? Please tell me!
Any new features needed? Please ask me?
Any questions? I don’t know if we are allowed to use this forum for it but for now: Ask me!
Happpy? Don’t hasitate to share it with me…

Cheers

BTW you need at least Servoy v2.0b6

Marcel,

EXCELLENT JOB! Inspiring!

I love your idea of the email validation. Would be cool to have a plug-in that did validations (isNumeric, isTextOnly, isInRange, etc.).

Now if only I could find the time… :lol:

Cheers,

Bob Cusick

Well, this is a glove I have to pick up (is this know in English? In Duch it is “deze handschoen moet ik oppakken”) :lol:

OK here it is. v2 with 5 new functions:

  1. getMaxDay: returns the last day of the given month;
  2. isInteger: returns a boolean value, checks a string;
  3. isNumber: returns a boolean value after checking a string;
    = localized but will return false when you input thousand seperators…
  4. numberFormat: formats the number to the formatString;
    = localized
  5. getIT2Be: returns my name, email and GSM :lol:

And Bob, what exactly do you expect of isInRange and isTextOnly?
And what further suggestions do you have?

IT2BE:
OK here it is. v2 with 5 new functions:

  1. getMaxDay: returns the last day of the given month;
  2. isInteger: returns a boolean value, checks a string;
  3. isNumber: returns a boolean value after checking a string;
    = localized but will return false when you input thousand seperators…
  4. numberFormat: formats the number to the formatString;
    = localized
  5. getIT2Be: returns my name, email and GSM :lol:

WOW! EXCELLENT JOB!! :o

IT2BE:
And Bob, what exactly do you expect of isInRange and isTextOnly?
And what further suggestions do you have?

isInRange would return a boolean and would allow you to specify:

isInRange(checkValue, dataType, lowerValue, upperValue)

For Example:
isInRange(elements.dateField, ‘date’, ‘1/30/2003|M/d/yyyy’, ‘3/20/2003|M/d/yyyy’)

isInRange(elements.numberField, ‘number’, ‘975.12’, ‘1576.4885’)

isInRange(elements.numberField, ‘integer’, ‘1000’, ‘1576’)

The isTextOnly() function would only take the string to compare. So, for example:

var isText = plugins.myplug.isTextOnly(‘This has 1 num in it’);
//returns FALSE

var isText = plugins.myplug.isTextOnly(‘This has zero nums in it’);
//returns TRUE

This will help tell if the user entered a number where text only is required. (needs to check if there is a numeric character in the passed string)

Again - GREAT JOB!

Bob

Here it is, version 3 of the tools plugin. I added the following 4 new methods:

  • isExpired
    takes a year, month and (optional) day and returns a boolean when expired. Can be used to check the expiration date of a credit card…

  • isInRange
    takes dates, numbers/integers and strings and returns true or false…

  • dates: dates need to be set with new Date() not a db timestamp
  • string: there is an option to be set to true if you want to ignore cases
  • isTextOnly
    takes a string and returns false if it finds numbers…

  • modulus10
    takes a string, filters all numbers and tells you the result of a modulus10 check. Can be used to check a credit card number…

Cheers

Nice plugin, well done, one remark:

We are setting up a plugin registry (web page) to list all available plugins and prevent JavaScript plugin name collisions in future.
On that page will suggest to use names like “Company name” abbreviation followed with “_” and the goal of the plugin (and also name the jar that way)

So a nice JavaScript name for your plugin whould be:
“it2be_tools” packed in a file it2be_tools.jar

You might consider updating your plugin (before its widely used), also seen the fact your name get more exposure (it’s in all the scripts :-) )

Hai Jan,

No problemo. But I personally don’t like very long plugin names. Makes me type more or chances that a line falls off a screen are bigger.

Why not put the name in the .jar file and for the name usage in Servoy just “first-come-first-serve”?

Just a suggestion, otherwise I will upload the renamed version this morning…

BTW do you know how to ‘lock-out’ the .jar from reading the code?

Well it a suggestion, not a requirement, good practice like Java code package naming…
Most people will use “move” code anyway or use code completion (CTRL-SPACE), so typing will not be the problem.

At least name your plugin that way.

Tip: do only pack the files needed in the jar (.class/.gif)

To obscurify your code have a look at: [u]retroguard[/u]

Version 4 of the Tools plugin is now renamed to it2be_tools upon request of Servoy.

PLEASE ONLY USE THIS RELEASE AND DELETE THE OLD ONE…

I optimized some code, corrected an error in the isModulus10 function and renamed validateEmail into isEmail and modulus10 into isModulus10…

The tools plugin holds the following twelve functions:

CALCULATION

  1. getMaxDay
    returns the last day of the given month.

  2. getIT2Be
    returns my name, email and GSM :lol:

(STRING) FORMATTING

  1. dateFormat
    very much like the Java dateFormat class to convert a date to a string and the other way around with (or without) a formatting string.

  2. numberFormat
    formats the (localized) number to the formatString.

  3. secondsFormat
    to make a number of seconds a string and the other way around. formatting like HH:mm:ss.

VALIDATION

  1. isEmail
    based on a method I posted earlier on this forum now available in this plugin. It takes a string with one or more email adresses and checks if the format is correct.

  2. isExpired
    takes a year, month and (optional) day and returns a boolean when expired. Can be used to check the expiration date of a credit card.

  3. isInteger
    returns a boolean value, checks a string.

  4. isInRange
    takes dates, numbers/integers and strings and returns true or false.

  • dates: dates need to be set with new Date() not a db timestamp
  • string: there is an option to be set to true if you want to ignore cases
  1. isModulus10
    takes a string, filters all numbers and tells you the result of a modulus10 check. Can be used to check a credit card number.

  2. isNumber
    returns a boolean value after checking a string.

  • localized but will return false when you input thousand seperators.
  1. isTextOnly
    takes a string and returns false if it finds numbers.

The result is attached. Just drop it in your plugins folder and restart Servoy.

REMARK: When you used my old plugin please do a global search and replace for:

plugins.tools = plugins.it2be_tools
tools.modulus10 = tools.isModulus10
tools.validateEmail = tools.isEmail

Feel free to use it and distribute it but give me credit for it.
The plugin is provided M-^Qas isM-^R and I can not take any responsibility for the way it behaves or works

Any suggestions? Please let me know!
Any bugs? Please tell me!
Any new features needed? Please ask me?
Any questions? I don’t know if we are allowed to use this forum for it but for now: Ask me!
Happpy? Don’t hesitate to share it with me…

Cheers

BTW the tools plugin is written to work with Servoy v2M-^E

Congrats!

This is a great plugin Marcel!
Especially taking into consideration that untill recently you were a newby to Java and Javascripting.
I did’nt test all features but the I can’t get the secondsFormat working.
I set the variable to a datefield.
I get an error saying: ‘seconds2time is not a function’
I assume I do something wrong, can you give me a script example?
BTW maybe it is a good ID to give a little bit more info in your sample info.

TIA

Ron

Oh, I am sorry. seconds2time is the first name I gave secondsFormat and forgot to update it in the tooltip. So change the example to secondsFormat, input an integer and it will work… Or just transfer the function without example.

As for the examples. I tried to make a compromise between the amount of work an self expanatory examples… Not enough so it seems.

I will try to make this a little better in a next version…

Thanks for the compliments. Keep complimenting and challenging me and I will proceed with the plugin…

Ciao

Well, you also got my compliments… :D

I asked one question and next thing I know you have made the function I was looking for! :D Great job

Paul

I love the date ↔ string functions

Keep up the good work!