last update: Mon, 26 Aug 2013 08:08:07 GMT ( 11 years ago )
Explanation of this sample
(1)
名前空間window.Synquery.ext.Workflow.Activities
に、アクティビティクラスを定義します。
(2)
コンストラクタにおいて、親クラスのコンストラクタ関数を呼び出し、インスタンスを初期化します。
(3)window.Synquery.ext.Workflow.Activity
クラスを継承します。
継承するためにユーティリティー関数inherit
を使用します。
(4)
ワークフローエディタのアクション
の種類として表示される文字列を記述します。
(5)
ワークフローエディタのアクション
の説明として表示される文字列を記述します。
(6)
(1) で定義したアクティビティクラスのプロトタイプ関数action
を上書きすることで、アクション実行前の処理を拡張することができます。
引数はワークフローとして保存されるデータオブジェクトです。
このサンプルでは、BOOK
インスタンスのPrintForm
関数を呼び出すことで印刷機能を実行します。
(7)
(1) で定義したアクティビティクラスのプロトタイプ関数save
を上書きすることで、アクション実行後の処理を拡張することができます。
このサンプルでは、アクション実行後に配信先を指定してメールを送信する機能を実現しています。
(注意)save
関数内でもアクション実行前の処理を記述できますが、データの不整合を起こさないために アクション実行前の処理はaction
関数内で行ってください。Including this sample module
Sample of extending Activity
以下のサンプル(PrintAndSendMailActivity)では、アクション実行前にプリント機能を実行し、アクション実行後にメールを送信します。
(function() {
var Workflow = Synquery.ext.Workflow;
var Activities = Workflow.Activities;
var Activity = Activities.Activity;
var util = Workflow.Utilities;
// (1)
Activities.PrintAndSendMailActivity = PrintAndSendMailActivity;
// (2)
function PrintAndSendMailActivity() {
Activity.apply(this, arguments);
};
// (3)
util.inherit(PrintAndSendMailActivity, Activity);
// (4)
PrintAndSendMailActivity.display = 'Print and Send mail';
// (5)
PrintAndSendMailActivity.explain = 'Outputs a voucher of this workflow with sending mail.';
// (6)
PrintAndSendMailActivity.prototype.action = function(data) {
this.book.PrintForm();
return Activity.prototype.action.apply(this, arguments);
};
// (7)
PrintAndSendMailActivity.prototype.save = function(data) {
var x = this.book;
return Activity.prototype.save.apply(this, arguments).pipe(function() {
var def = $.Deferred();
x.top.BOOK({
'title': 'Send Mail',
'structure': [
['to[]', '', [
['email', 'Email', 'email', '', {'fill': true}, 90]
], 100, {}, 10]
],
'style': {'modal': true, 'editForm': true, 'noSearch': true},
'table': false,
'formButton': {
'send': function(x) {
var form = x.GetForm();
if(x.CheckForm())
return;
x.RemoveForm();
var param = {'subject': 'Action is executed', 'contents': 'Please check it.'};
param.to = form.to.email;
x.top.sendMail(param, function(info, err) {
if(err || !info['success'])
return def.reject(err);
def.resolve();
});
}}
}, x).ShowForm();
return def.promise();
});
};
}).call();