source: branches/comu-ver2/html/user_data/packages/default/js/file_manager.js @ 17406

Revision 17406, 7.3 KB checked in by pineray, 16 years ago (diff)

Firefoxだとファイル管理でフォルダの展開ができない不具合を修正

Line 
1/*
2 * This file is part of EC-CUBE
3 *
4 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
5 *
6 * http://www.lockon.co.jp/
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 */
22var IMG_FOLDER_CLOSE   = "../../user_data/packages/default/img/admin/contents/folder_close.gif";        // フォルダクローズ時画像
23var IMG_FOLDER_OPEN    = "../../user_data/packages/default/img/admin/contents/folder_open.gif";     // フォルダオープン時画像
24var IMG_PLUS           = "../../user_data/packages/default/img/admin/contents/plus.gif";                // プラスライン
25var IMG_MINUS          = "../../user_data/packages/default/img/admin/contents/minus.gif";               // マイナスライン
26var IMG_NORMAL         = "../../user_data/packages/default/img/admin/contents/space.gif";               // スペース
27
28var tree = "";                      // 生成HTML格納
29var count = 0;                      // ループカウンタ
30var arrTreeStatus = new Array();    // ツリー状態保持
31var old_select_id = '';             // 前回選択していたファイル
32var selectFileHidden = "";          // 選択したファイルのhidden名
33var treeStatusHidden = "";          // ツリー状態保存用のhidden名
34var modeHidden = "";                // modeセットhidden名
35
36// ツリー表示
37function fnTreeView(view_id, arrTree, openFolder, selectHidden, treeHidden, mode) {
38    selectFileHidden = selectHidden;
39    treeStatusHidden = treeHidden;
40    modeHidden = mode;
41
42    for(i = 0; i < arrTree.length; i++) {
43
44        id = arrTree[i][0];
45        level = arrTree[i][3];
46
47        if(i == 0) {
48            old_id = "0";
49            old_level = 0;
50        } else {
51            old_id = arrTree[i-1][0];
52            old_level = arrTree[i-1][3];
53        }
54
55        // 階層上へ戻る
56        if(level <= (old_level - 1)) {
57            tmp_level = old_level - level;
58            for(up_roop = 0; up_roop <= tmp_level; up_roop++) {
59                tree += '</div>';
60            }
61        }
62
63        // 同一階層で次のフォルダへ
64        if(id != old_id && level == old_level) tree += '</div>';
65
66        // 階層の分だけスペースを入れる
67        for(space_cnt = 0; space_cnt < arrTree[i][3]; space_cnt++) {
68            tree += "&nbsp;&nbsp;&nbsp;";
69        }
70
71        // 階層画像の表示・非表示処理
72        if(arrTree[i][4]) {
73            if(arrTree[i][1] == '_parent') {
74                rank_img = IMG_MINUS;
75            } else {
76                rank_img = IMG_NORMAL;
77            }
78            // 開き状態を保持
79            arrTreeStatus.push(arrTree[i][2]);
80            display = 'block';
81        } else {
82            if(arrTree[i][1] == '_parent') {
83                rank_img = IMG_PLUS;
84            } else {
85                rank_img = IMG_NORMAL;
86            }
87            display = 'none';
88        }
89
90        arrFileSplit = arrTree[i][2].split("/");
91        file_name = arrFileSplit[arrFileSplit.length-1];
92
93        // フォルダの画像を選択
94        if(arrTree[i][2] == openFolder) {
95            folder_img = IMG_FOLDER_OPEN;
96            file_name = "<b>" + file_name + "</b>";
97        } else {
98            folder_img = IMG_FOLDER_CLOSE;
99        }
100
101        // 階層画像に子供がいたらオンクリック処理をつける
102        if(rank_img != IMG_NORMAL) {
103            tree += '<a href="javascript:fnTreeMenu(\'tree'+ i +'\',\'rank_img'+ i +'\',\''+ arrTree[i][2] +'\')"><img src="'+ rank_img +'" border="0" name="rank_img'+ i +'" id="rank_img'+ i +'">';
104        } else {
105            tree += '<img src="'+ rank_img +'" border="0" name="rank_img'+ i +'" id="rank_img'+ i +'">';
106        }
107        tree += '<a href="javascript:fnFolderOpen(\''+ arrTree[i][2] +'\')"><img src="'+ folder_img +'" border="0" name="tree_img'+ i +'" id="tree_img'+ i +'">&nbsp;'+ file_name +'</a><br/>';
108        tree += '<div id="tree'+ i +'" style="display:'+ display +'">';
109
110    }
111    fnDrow(view_id, tree);
112    //document.tree_form.tree_test2.focus();
113}
114
115// Tree状態をhiddenにセット
116function setTreeStatus(name) {
117    var tree_status = "";
118    for(i=0; i < arrTreeStatus.length ;i++) {
119        if(i != 0) tree_status += '|';
120        tree_status += arrTreeStatus[i];
121    }
122    document.form1[name].value = tree_status;
123}
124
125// Tree状態を削除する(閉じる状態へ)
126function fnDelTreeStatus(path) {
127    for(i=0; i < arrTreeStatus.length ;i++) {
128        if(arrTreeStatus[i] == path) {
129            arrTreeStatus[i] = "";
130        }
131    }
132}
133// ツリー描画
134function fnDrow(id, tree) {
135    // ブラウザ取得
136    MyBR = fnGetMyBrowser();
137    // ブラウザ事に処理を切り分け
138    switch(myBR) {
139        // IE4の時の表示
140        case 'I4':
141            document.all(id).innerHTML = tree;
142            break;
143        // NN4の時の表示
144        case 'N4':
145            document.layers[id].document.open();
146            document.layers[id].document.write("<div>");
147            document.layers[id].document.write(tree);
148            document.layers[id].document.write("</div>");
149            document.layers[id].document.close();
150            break;
151        default:
152            document.getElementById(id).innerHTML=tree;
153            break;
154    }
155}
156
157// 階層ツリーメニュー表示・非表示処理
158function fnTreeMenu(tName, imgName, path) {
159
160    tMenu = $("#" + tName);
161
162    if(tMenu.css("display") == 'none') {
163        fnChgImg(IMG_MINUS, imgName);
164        tMenu.show();
165        // 階層の開いた状態を保持
166        arrTreeStatus.push(path);
167
168    } else {
169        fnChgImg(IMG_PLUS, imgName);
170        tMenu.hide();
171        // 閉じ状態を保持
172        fnDelTreeStatus(path);
173    }
174}
175
176// ファイルリストダブルクリック処理
177function fnDbClick(arrTree, path, is_dir, now_dir, is_parent) {
178
179    if(is_dir) {
180        if(!is_parent) {
181            for(cnt = 0; cnt < arrTree.length; cnt++) {
182                if(now_dir == arrTree[cnt][2]) {
183                    open_flag = false;
184                    for(status_cnt = 0; status_cnt < arrTreeStatus.length; status_cnt++) {
185                        if(arrTreeStatus[status_cnt] == arrTree[cnt][2]) open_flag = true;
186                    }
187                    if(!open_flag) fnTreeMenu('tree'+cnt, 'rank_img'+cnt, arrTree[cnt][2]);
188                }
189            }
190        }
191        fnFolderOpen(path);
192    } else {
193        // Download
194        fnModeSubmit('download','','');
195    }
196}
197
198// フォルダオープン処理
199function fnFolderOpen(path) {
200
201    // クリックしたフォルダ情報を保持
202    document.form1[selectFileHidden].value = path;
203    // treeの状態をセット
204    setTreeStatus(treeStatusHidden);
205    // submit
206    fnModeSubmit(modeHidden,'','');
207}
208
209
210// 閲覧ブラウザ取得
211function fnGetMyBrowser() {
212    myOP = window.opera;            // OP
213    myN6 = document.getElementById; // N6
214    myIE = document.all;            // IE
215    myN4 = document.layers;         // N4
216    if      (myOP) myBR="O6";       // OP6以上
217    else if (myIE) myBR="I4";       // IE4以上
218    else if (myN6) myBR="N6";       // NS6以上
219    else if (myN4) myBR="N4";       // NN4
220    else           myBR="";         // その他
221
222    return myBR;
223}
224
225// imgタグの画像変更
226function fnChgImg(fileName,imgName){
227    document.getElementById(imgName).src = fileName;
228}
229
230// ファイル選択
231function fnSelectFile(id, val) {
232    if(old_select_id != '') document.getElementById(old_select_id).style.backgroundColor = '';
233    document.getElementById(id).style.backgroundColor = val;
234    old_select_id = id;
235}
236
237// 背景色を変える
238function fnChangeBgColor(id, val) {
239    if (old_select_id != id) {
240        document.getElementById(id).style.backgroundColor = val;
241    }
242}
243
244// test
245function view_test(id) {
246    document.getElementById(id).value=tree
247}
Note: See TracBrowser for help on using the repository browser.