Search The ForumSearch   RegisterRegister  LoginLogin

AfterLogic WebMail Pro

 AfterLogic Forum : AfterLogic WebMail Pro
Subject Topic: Access to AppData and Utils objects Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
mcoelho80
Newbie
Newbie


Joined: 03 April 2014
Location: Brazil
Online Status: Offline
Posts: 28
Posted: 09 April 2014 at 6:10am | IP Logged Quote mcoelho80

Hi,

I'm writing a plugin that will add a setting tab with another set of tabs:
http://picpaste.com/Screen_Shot_2014-04-09_at_10.05.11_AM-6wk8cj3E.png

I noticed that AppData and Utils javascript objects aren't available when I try to call them from a plugin .js file:

Example

CAntiSpamSettings.prototype.TabTitle = Utils.i18n('PLUGINS/ANTISPAM_TITLE');

The same code above works if used in app.js file.

How to make AppData and Utils objects available to plugin scripts?

Thank you in advance.
Back to Top View mcoelho80's Profile Search for other posts by mcoelho80
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 10 April 2014 at 2:53am | IP Logged Quote Igor

We certainly agree that i18n function should be available to plugins. To enable that, insert the following code to app.js file:

Code:
/**
* @param {string} sKey
* @param {?Object=} oValueList
* @param {?string=} sDefaultValue
* @param {number=} nPluralCount
*
* @return {string}
*/
AfterLogicApi.i18n = function (sKey, oValueList, sDefaultValue, nPluralCount)
{
  return Utils.i18n(sKey);
};


It's recommended to insert it somewhere after this:

Code:
/**
* @param {string} sRecipients
*
* @return {Array}
*/

AfterLogicApi.getArrayRecipients = function (sRecipients)
{
  return Utils.getArrayRecipients(sRecipients);
};


Of course, this will be included in next product update.

For security reasons, we believe plugins shouldn't have access to entire AppData and Utils objects available. But if you need some particular properties or method available externally, that can be done similarly to the above item.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
mcoelho80
Newbie
Newbie


Joined: 03 April 2014
Location: Brazil
Online Status: Offline
Posts: 28
Posted: 11 April 2014 at 2:26pm | IP Logged Quote mcoelho80

Thank you for your response.

You could create a method to allow a plugin specify an extra language directory to be processed.

That would help us to create a multi-language plugin without having to modify the main language files directly, making the webmail easier to get updates in the future.
Back to Top View mcoelho80's Profile Search for other posts by mcoelho80
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 14 April 2014 at 4:35am | IP Logged Quote Igor

Sure, I've forwarded the suggestion to the developers team, they will consider adding that in subsequent releases.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
whuhacker
Newbie
Newbie


Joined: 12 May 2014
Location: Hong Kong
Online Status: Offline
Posts: 10
Posted: 14 May 2014 at 2:35am | IP Logged Quote whuhacker

Is plugin language directory added to version 7.3?
Back to Top View whuhacker's Profile Search for other posts by whuhacker
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 14 May 2014 at 2:40am | IP Logged Quote Igor

No, that wasn't added to it, will probably become available in next version.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
whuhacker
Newbie
Newbie


Joined: 12 May 2014
Location: Hong Kong
Online Status: Offline
Posts: 10
Posted: 14 May 2014 at 7:11pm | IP Logged Quote whuhacker

Igor wrote:
No, that wasn't added to it, will probably become available in next version.

Could you post the plugin folder structure while the i18n is ready? I want my codebase be compatible with the future updates.

Currently my plugin folder is
antispam-setting/
├── index.php
├── js
│   ├── antispamSetting.js
│   └── include.js
└── templates
    └── antispamSetting.html

Will it be the following?
antispam-setting/
├── index.php
├── js
│   ├── antispamSetting.js
│   └── include.js
└── templates
    └── antispamSetting.html
└── i18n
    └── English.ini
    └── French.ini
Back to Top View whuhacker's Profile Search for other posts by whuhacker
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 14 May 2014 at 11:48pm | IP Logged Quote Igor

Sorry, I've rechecked that and looks like the feature is there in 7.3 indeed. Shortly we'll publish a sample plugin which demonstrates how to set different texts based on the current interface language, the key property is set in the plugin as follows:

Code:
$this->SetI18N(true);


and method used for getting localized text is AfterLogicApi.i18n('text-constant-name').

And yes, it's i18n subdirectory with language-name.ini files there.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
whuhacker
Newbie
Newbie


Joined: 12 May 2014
Location: Hong Kong
Online Status: Offline
Posts: 10
Posted: 15 May 2014 at 2:44am | IP Logged Quote whuhacker

Igor, thanks for your reply. Looking forward to the sample plugin.

I would also like to know what is the proper way to post form data to server with my plugin, and how plugin's php script can get such form data. It looks like that you are using frontend MVC framework, which is not quite straight forward. More documentation and sample code is in great need.

Thank you so much.
Back to Top View whuhacker's Profile Search for other posts by whuhacker
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 15 May 2014 at 2:49am | IP Logged Quote Igor

That kind of things is achieved by sending AJAX calls, and we plan to provide documentation on using AJAX in plugins in the near future.

Sample plugin demonstrating localization in plugins will probably become available later today or tomorrow.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
whuhacker
Newbie
Newbie


Joined: 12 May 2014
Location: Hong Kong
Online Status: Offline
Posts: 10
Posted: 15 May 2014 at 7:33pm | IP Logged Quote whuhacker

Hi Igor, is the sample plugin ready?
Where can I download it?
Back to Top View whuhacker's Profile Search for other posts by whuhacker
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 15 May 2014 at 11:50pm | IP Logged Quote Igor

Yes, have just published it:

Add and override language constants

Hope it helps!

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
whuhacker
Newbie
Newbie


Joined: 12 May 2014
Location: Hong Kong
Online Status: Offline
Posts: 10
Posted: 16 May 2014 at 12:07am | IP Logged Quote whuhacker

Excellent! It works and helps me a lot. Thanks a lot.
Looking forward to the AJAX form demo.
Back to Top View whuhacker's Profile Search for other posts by whuhacker
 
whuhacker
Newbie
Newbie


Joined: 12 May 2014
Location: Hong Kong
Online Status: Offline
Posts: 10
Posted: 18 May 2014 at 7:39pm | IP Logged Quote whuhacker

Hi, I am able to make Ajax request with my plugin finally. The request looks like the following:

Request URL:http://mydomain.com/aurora/?/Ajax/
Request Method:POST
Status Code:200 OK

Form Data
Action:UpdateAntispamUserSettings
ReceiveReport:1
ReportLanguage:1
DeliveryAddress:1
UsharkAntispam:1
EnableAutoDelete:1
AccountID:7
Token:284551d6bb7091820cdbe2dd2e2f14a9


However, I still don't know how to get such data with PHP code of plugin. Seems that I need add some hooks?

Please help~ Thank you
Back to Top View whuhacker's Profile Search for other posts by whuhacker
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 19 May 2014 at 4:34am | IP Logged Quote Igor

Indeed, you'll need to add a hook, and new sample plugin shows how to achieve that.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
whuhacker
Newbie
Newbie


Joined: 12 May 2014
Location: Hong Kong
Online Status: Offline
Posts: 10
Posted: 20 May 2014 at 2:28am | IP Logged Quote whuhacker

Thank you.
I found a bug that caused javascript error in the new plugin.

"getAjaxData" in CAboutViewModel.js should be "getVersion".

BTW, can I pass parameters to the callback function in AddJsonHook('hookName', 'callback')?
Back to Top View whuhacker's Profile Search for other posts by whuhacker
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 20 May 2014 at 2:41am | IP Logged Quote Igor

Code:
"getAjaxData" in CAboutViewModel.js should be "getVersion".


Good point, thanks. Fixed.

Code:
can I pass parameters to the callback function in AddJsonHook('hookName', 'callback')?


No, but you can pass data using properties of CAboutPlugin class.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
iSofia
Newbie
Newbie
Avatar

Joined: 24 May 2014
Location: Singapore
Online Status: Offline
Posts: 35
Posted: 16 October 2014 at 9:50am | IP Logged Quote iSofia

Igor wrote:
Code:
can I pass parameters to the callback function in AddJsonHook('hookName', 'callback')?

No, but you can pass data using properties of CAboutPlugin class.

Hello Igor. How do we pass values between JavaScript and the PHP class through properties? I tried setting up a public property in the PHP class:
Code:
public $classVar;

Then I tried setting it's value from JavaScript like this:
Code:
$this->classVar = "Hello";

but the class variable is not set.
Back to Top View iSofia's Profile Search for other posts by iSofia
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6043
Posted: 17 October 2014 at 3:38am | IP Logged Quote Igor

It doesn't work that way, you'll need to use AJAX calls as shown here:

http://www.afterlogic.com/forum/forum_posts.asp?TID=5904

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
iSofia
Newbie
Newbie
Avatar

Joined: 24 May 2014
Location: Singapore
Online Status: Offline
Posts: 35
Posted: 17 October 2014 at 4:00am | IP Logged Quote iSofia

Igor wrote:
It doesn't work that way, you'll need to use AJAX calls as shown here:

http://www.afterlogic.com/forum/forum_posts.asp?TID=5904

I know, it's embarrassing. Some of the other stuff that I've been trying out is even more embarrassing; in fact downright pathetic.

Thank you.
Back to Top View iSofia's Profile Search for other posts by iSofia
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide