7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2012 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_s_jquery_initWidgetContainer.php 4647 2012-02-01 14:09:31Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
18 class admin_s_jquery_initWidgetContainer extends BaseAdminWidgetContainer
20 private $serialNo; // 選択中の項目のシリアル番号
21 private $serialArray = array(); // 表示中のシリアル番号
22 private $configId; // 定義ID
23 private $paramObj; // パラメータ保存用オブジェクト
24 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
25 const DEFAULT_SCRIPT = '// init script here.'; // デフォルトのスクリプト
30 function __construct()
33 parent::__construct();
38 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
39 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
41 * @param RequestManager $request HTTPリクエスト処理クラス
42 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
43 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
45 function _setTemplate($request, &$param)
47 $task = $request->trimValueOf('task');
48 if ($task == 'list'){ // 一覧画面
49 return 'admin_list.tmpl.html';
51 return 'admin.tmpl.html';
57 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
59 * @param RequestManager $request HTTPリクエスト処理クラス
60 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
63 function _assign($request, &$param)
65 $task = $request->trimValueOf('task');
66 if ($task == 'list'){ // 一覧画面
67 return $this->createList($request);
69 return $this->createDetail($request);
75 * @param RequestManager $request HTTPリクエスト処理クラス
78 function createDetail($request)
80 // ページ定義IDとページ定義のレコードシリアル番号を取得
81 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
83 $userId = $this->gEnv->getCurrentUserId();
84 $act = $request->trimValueOf('act');
85 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
86 $this->configId = $request->trimValueOf('item_id'); // 定義ID
87 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
90 $name = $request->trimValueOf('item_name'); // ヘッダタイトル
91 $script = $request->valueOf('item_script'); // スクリプト
93 $replaceNew = false; // データを再取得するかどうか
94 if ($act == 'add'){// 新規追加
96 $this->checkInput($name, '名前');
99 for ($i = 0; $i < count($this->paramObj); $i++){
100 $targetObj = $this->paramObj[$i]->object;
101 if ($defName == $targetObj->name){ // 定義名
102 $this->setUserErrorMsg('名前が重複しています');
108 if ($this->getMsgCount() == 0){
110 $newObj = new stdClass;
111 $newObj->id = $newConfigId;// 定義ID
112 $newObj->name = $name;// 表示名
113 $newObj->script = $script; // スクリプト
115 // ウィジェットパラメータオブジェクト更新
116 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
118 $this->setGuidanceMsg('データを追加しました');
120 $this->configId = $defConfigId; // 定義定義IDを更新
121 $replaceNew = true; // データ再取得
123 $this->setAppErrorMsg('データ追加に失敗しました');
126 } else if ($act == 'update'){ // 設定更新のとき
128 if ($this->getMsgCount() == 0){ // エラーのないとき
130 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
133 $targetObj->script = $script; // スクリプト
137 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
139 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
140 $replaceNew = true; // データ再取得
142 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
145 } else if ($act == 'select'){ // 定義IDを変更
146 $replaceNew = true; // データ再取得
149 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
150 $replaceNew = true; // データ再取得
154 $this->createItemMenu();
157 if (empty($this->configId)){ // 新規登録の場合
158 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
159 if ($replaceNew){ // データ再取得時
160 $name = $this->createDefaultName(); // デフォルト登録項目名
161 $script = self::DEFAULT_SCRIPT; // スクリプト
165 if ($replaceNew){// データ再取得時
166 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
168 $name = $targetObj->name; // 名前
169 $script = $targetObj->script; // スクリプト
172 $this->serialNo = $this->configId;
174 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
175 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
179 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId); // 定義ID
180 $this->tmpl->addVar("item_name_visible", "name", $name);
181 $this->tmpl->addVar("_widget", "script", $script); // スクリプト
182 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
185 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
186 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
188 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
191 // ページ定義IDとページ定義のレコードシリアル番号を更新
192 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
199 function createItemMenu()
201 for ($i = 0; $i < count($this->paramObj); $i++){
202 $id = $this->paramObj[$i]->id;// 定義ID
203 $targetObj = $this->paramObj[$i]->object;
204 $defName = $targetObj->name;// 定義名
206 if ($this->configId == $id) $selected = 'selected';
209 'name' => $defName, // 名前
210 'value' => $id, // 定義ID
211 'selected' => $selected // 選択中の項目かどうか
213 $this->tmpl->addVars('title_list', $row);
214 $this->tmpl->parseTemplate('title_list', 'a');
220 * @return string デフォルト名
222 function createDefaultName()
224 $name = self::DEFAULT_NAME_HEAD;
225 for ($j = 1; $j < 100; $j++){
226 $name = self::DEFAULT_NAME_HEAD . $j;
228 for ($i = 0; $i < count($this->paramObj); $i++){
229 $targetObj = $this->paramObj[$i]->object;
230 if ($name == $targetObj->name){ // 定義名
235 if ($i == count($this->paramObj)) break;
242 * @param RequestManager $request HTTPリクエスト処理クラス
245 function createList($request)
247 // ページ定義IDとページ定義のレコードシリアル番号を取得
248 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
250 $userId = $this->gEnv->getCurrentUserId();
251 $act = $request->trimValueOf('act');
253 if ($act == 'delete'){ // メニュー項目の削除
254 $listedItem = explode(',', $request->trimValueOf('seriallist'));
256 for ($i = 0; $i < count($listedItem); $i++){
258 $itemName = 'item' . $i . '_selected';
259 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
261 if ($itemValue){ // チェック項目
262 $delItems[] = $listedItem[$i];
265 if (count($delItems) > 0){
266 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
267 if ($ret){ // データ削除成功のとき
268 $this->setGuidanceMsg('データを削除しました');
270 $this->setAppErrorMsg('データ削除に失敗しました');
275 $this->createItemList();
276 if (count($this->serialArray) == 0) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');// 一覧項目がないときは、一覧を表示しない
278 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
280 // ページ定義IDとページ定義のレコードシリアル番号を更新
281 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
288 function createItemList()
290 for ($i = 0; $i < count($this->paramObj); $i++){
291 $id = $this->paramObj[$i]->id;// 定義ID
292 $targetObj = $this->paramObj[$i]->object;
293 $defName = $targetObj->name;// 定義名
298 $defCount = $this->_db->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
300 $operationDisagled = '';
301 if ($defCount > 0) $operationDisagled = 'disabled';
306 'ope_disabled' => $operationDisagled, // 選択可能かどうか
307 'name' => $this->convertToDispString($defName), // 名前
308 'def_count' => $defCount // 使用数
310 $this->tmpl->addVars('itemlist', $row);
311 $this->tmpl->parseTemplate('itemlist', 'a');
314 $this->serialArray[] = $id;