source: pro-violet-viettel/refs/LectureEditor/scene.as @ 921

Last change on this file since 921 was 698, checked in by dungnv, 10 years ago
File size: 53.1 KB
Line 
1////////////////////////////////////////////////////////////////////////////////
2// File:    SCENE.AS
3// Mô tả:   File chứa các biến, các hàm phục vụ việc xử lý các thao tác trên
4//          3 đối tượng của giao diện chính (gồm TreeView, Preview, FileList)
5//          và cập nhật dữ liệu dùng chung (biến dataXML)
6//
7// Tác giả: Đinh Hải Minh, VicoSoft
8// Ngày:    02/12/2003
9////////////////////////////////////////////////////////////////////////////////
10
11//******************************************************************************
12// Khởi tạo các biến toàn cục và thuộc tính ban đầu của các đối tượng
13// Nạp file Player để hiển thị PREVIEW của bài giảng
14//******************************************************************************
15
16version = "1.81";
17if (language == undefined) language = "Vietnamese";
18if (vietType == undefined) vietType = false;
19if (tokenPassword == undefined) tokenPassword = "violet";
20if (applicationId == undefined) applicationId = "Violet";
21slash = "\\";
22
23btnSemitrans.count = 0;
24btnSemitrans._visible = false;
25btnSceneBkGnd._visible = false;
26btnSemitrans.useHandCursor = false;
27btnSceneBkGnd.useHandCursor = false;
28scpFileList.content.movFileItem._visible = false;
29treItem.addEventListener("change", onTreeViewChange);
30
31if (_url.substr(0, 7)=="http://") { rootPath = _url.substr(0, -25); slash = "/"; webbase = true; }
32else if (_url.substr(0, 8)=="file:///") { rootPath = _url.substr(8, -33).split("|").join(":"); slash = "/"; }
33else if (_url.substr(0, 7)=="file://") rootPath = _url.substr(7, -32).split("|").join(":");
34
35dataDir = 'Data';
36commonDir = 'Common';
37commonLibDir = 'Addins';
38maxUndo = 10;
39dataID = "[VIOLET Data]";
40dataChanged = "false";
41commonXML = new XML();
42currentFile = "";
43defXmlDecl = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
44packagePlayer = "Player.exe";
45playerMovie = rootPath + "Frame" + slash + "Player.swf";
46appPath = rootPath + "Lecture" + slash;
47commonPath = appPath + "Layout" + slash;
48
49pluginUrl = "http://edustore.vn/violet/";
50userUrl = "http://api.violet.vn/user/";
51spaceUrl = "http://api.violet.vn/space/";
52userInfoUrl = "/ajax/user/login/xml"; // the server domain/IP will be passed via flashvars
53//online = true; fileId = 2877; userInfoUrl = "userinfo.xml"; // TEST
54userId = 0;
55
56curPos = new Array();
57repPos = new Array();
58undoData = new Array();
59undoPos = 0;
60
61if( !command ) command = "";
62onEnterFrame = WaitForAppCommand;
63wndDialog.contentPath = appPath + "Dialogs.swf";
64wndDialog.addEventListener("click", function(){this.content.gotoAndStop(1)});
65createEmptyMovieClip("lang", 0);
66InitTreeContextMenu();
67
68#include "scorm.as"
69#include "versions.as"
70#include "utils.as"
71
72//******************************************************************************
73// Hàm khởi động ứng dụng Flash, được gọi sau khi các biến của Flash đã được
74// khởi tạo trong hàm OnInitDialog của chương trình C++. Hàm này sẽ được
75// thực hiện khi chương trình C++ gửi message "Init OK" hoặc "Init&Open File"
76// Tác dụng:
77//   - Nạp cấu hình (cửa sổ và các tùy chọn của Violet)
78//   - Nạp dữ liệu ngôn ngữ giao tiếp
79//   - Nạp module Player, để hiển thị bài giảng đang soạn
80//   - Nạp bộ gõ tiếng Việt (nếu cần)
81//******************************************************************************
82
83function InitFlashApp(execFunc) {
84        LoadPluginInfo();
85        LoadConfig();
86        LoadLanguage();
87        if( !vietType ) {
88                onLoadTypingObj = function() {
89                        typingObj.deactive();
90                        delete typingObj;
91                }
92        }
93        var loader = new MovieClipLoader();
94        loader.loadClip(playerMovie, movPlayer);
95        loader.addListener({onLoadInit: function() {
96                movScene = movPlayer.scene;
97                LoadCommonLibs(commonLibList, appPath + commonLibDir);
98                if( fullscreen == true ) btnPreview.onRelease();
99                if (execFunc) execFunc();
100                else {
101                        movScene.dataXML = dataXML;
102                        movScene.onLoadXMLData();
103                }
104        }});
105
106        if( autoDemoTime ) setInterval(function() {
107                if( movScene.NextScreen() == -1 ) {
108                        SaveConfig();
109                        fscommand("Quit", "");
110                }
111        }, Number(autoDemoTime)*1000);
112}
113
114//******************************************************************************
115// Hàm xử lý các lệnh (chứa trong biến command) nhận về từ chương trình C++
116// Tác dụng:
117//   - Xử lý lệnh khi người dùng nhấn nút CLOSE trên cửa sổ chương trình C++
118//   - Xử lý phím Enter và Esc, chủ yếu thực hiện khi đang hiện các Dialog
119//   - Xử lý các phím tắt của chương trình tương ứng với các mục menu
120//******************************************************************************
121
122function WaitForAppCommand() {
123        if( messageShowing ) command = "";
124        if( command == "" ) return;
125
126        if( command == "Init OK" ) {
127                dataXML = new XML(defXmlDecl);
128                InitializeDataXML();
129                InitFlashApp();
130                if (online) InitFlashKeys();
131        }
132        if( command == "Press Delete" ) onPressDelete();
133        if( command == "Press Enter" ) onPressEnter();
134        if( command == "Press Esc" ) onPressEsc();
135        if( command == "Press Undo" ) onPressUndo();
136        if( command == "Press Redo" ) onPressRedo();
137        if( command == "Press Cut" ) onPressCtrlX();
138        if( command == "Press Copy" ) onPressCtrlC();
139        if( command == "Press Paste" ) onPressCtrlV();
140        if( command == "Press SelAll" ) onPressCtrlA();
141        if( command == "Drop Element" ) onDropElement();
142        if( command == "Press Help" ) btnHelp.onRelease();
143
144        if( !btnSemitrans._visible ) {
145                if( command == "Init&Open File" ) InitFlashApp(OpenNewFile);
146                if( command == "Open File" ) ExecWithConfirmSave(OpenNewFile);
147                if( command == "Press New" ) btnNew.onRelease();
148                if( command == "Press Open" ) btnOpen.onRelease();
149                if( command == "Press Lib" ) btnLibrary.onRelease();
150                if( command == "Press Save" ) btnSave.onRelease();
151                if( command == "Press Pack" ) btnPack.onRelease();
152                if( command == "Quit App" ) ExitProgram();
153
154                if( command == "Press Undo" ) ProcessUndo();
155                if( command == "Press Redo" ) ProcessRedo();
156                if( command == "Press Cut" ) btnCutOnRelease();
157                if( command == "Press Copy" ) btnCopyOnRelease();
158                if( command == "Press Paste" ) btnPasteOnRelease();
159                if( command == "Press MoveUp" ) btnMoveUp.onRelease();
160                if( command == "Press MoveDn" ) btnMoveDown.onRelease();
161               
162                if( command == "Press Add" ) btnAdd.onRelease();
163                if( command == "Press Update" ) btnDetail.onRelease();
164                if( command == "Press Delete" ) btnDelete.onRelease();
165                if( command == "Press Sync" ) SyncVideoAudio();
166
167                if( command == "Press Layout" ) btnLayout.onRelease();
168                if( command == "Press Preview" ) btnPreview.onRelease();
169        }
170        command = "";
171}
172
173function InitFlashKeys() {
174        var keyListener = new Object();
175        keyListener.onKeyDown = function() {
176                if (messageShowing) return;
177                var keyCode = Key.getCode();
178                switch (keyCode) {
179                        case Key.DELETEKEY: onPressDelete(); break;
180                        case Key.ENTER: onPressEnter(); break;
181                        case Key.ESCAPE: onPressEsc(); break;
182                        case 90 /*Z*/: if (Key.isDown(Key.CONTROL)) onPressUndo(); break;
183                        case 89 /*Y*/: if (Key.isDown(Key.CONTROL)) onPressRedo(); break;
184                        case 88 /*X*/: if (Key.isDown(Key.CONTROL)) onPressCtrlX(); break;
185                        case 67 /*C*/: if (Key.isDown(Key.CONTROL)) onPressCtrlC(); break;
186                        case 86 /*V*/: if (Key.isDown(Key.CONTROL)) onPressCtrlV(); break;
187                        case 65 /*A*/: if (Key.isDown(Key.CONTROL)) onPressCtrlA(); break;
188                        case 112 /*F1*/: btnHelp.onRelease(); break;
189                }
190                if( !btnSemitrans._visible )
191                switch (keyCode) {
192                        case 90 /*Z*/: if (Key.isDown(Key.CONTROL)) ProcessUndo(); break;
193                        case 89 /*Y*/: if (Key.isDown(Key.CONTROL)) ProcessRedo(); break;
194                        case 88 /*X*/: if (Key.isDown(Key.CONTROL)) btnCutOnRelease(); break;
195                        case 67 /*C*/: if (Key.isDown(Key.CONTROL)) btnCopyOnRelease(); break;
196                        case 86 /*V*/: if (Key.isDown(Key.CONTROL)) btnPasteOnRelease(); break;
197
198                        case 76 /*L*/: if (Key.isDown(Key.CONTROL)) btnLibrary.onRelease(); break;
199                        case 83 /*S*/: if (Key.isDown(Key.CONTROL)) btnSave.onRelease(); break;
200                        case 113 /*F2*/: btnNew.onRelease(); break;
201                        case 114 /*F3*/: btnOpen.onRelease(); break;
202                        case 115 /*F4*/: btnPack.onRelease(); break;
203                        case 116 /*F5*/: btnAdd.onRelease(); break;
204                        case 117 /*F6*/: btnDetail.onRelease(); break;
205                        case 118 /*F7*/: SyncVideoAudio(); break;
206                        case 119 /*F8*/: btnLayout.onRelease(); break;
207                        case 120 /*F9*/: btnPreview.onRelease(); break;
208                        case Key.DELETEKEY: btnDelete.onRelease(); break;
209                }
210        }
211        Key.addListener(keyListener);
212}
213
214//******************************************************************************
215// Hàm nạp thông tin về các plugin và các layout, dùng cho hàm chuyển đổi
216// version, cho cửa sổ soạn thảo slide và cho bảng lựa chọn Layout
217// Tác dụng:
218//   - Đọc các thông tin XML trong file Plugin.xml và Layouts.xml
219//******************************************************************************
220
221function LoadPluginInfo() {
222        pluginXML = new XML();
223        pluginXML.ignoreWhite = true;
224        pluginXML.load(appPath + "Plugins.xml");
225        pluginXML.onLoad = function() {
226                pluXML = pluginXML.firstChild;
227                LoadOldPlgLang(pluXML.firstChild.childNodes);
228        }
229
230        layoutXML = new XML();
231        layoutXML.ignoreWhite = true;
232        layoutXML.load(appPath + "Layout" + slash + "Layouts.xml");
233
234        var libXML = new XML();
235        libXML.ignoreWhite = true;
236        libXML.load(appPath + "Libraries.xml");
237        libXML.onLoad = function() {
238                libraryPaths = libXML.firstChild.childNodes[0];
239                symbolPaths = libXML.firstChild.childNodes[1];
240                lecturePaths = libXML.firstChild.childNodes[2];
241                libraryPaths.attributes.libPath = libPath1[0];
242                lecturePaths.attributes.libPath = libPath2[0];
243                libraryPaths.attributes.libCurrentSelected = libPath1[1];
244                lecturePaths.attributes.libCurrentSelected = libPath2[1];
245                libraryPaths.attributes.libCurrentPage = libPath1[2];
246                lecturePaths.attributes.libCurrentPage = libPath2[2];
247        }
248        delete pluginXmlData;
249        delete layoutXmlData;
250}
251
252//******************************************************************************
253// Hàm nạp dữ liệu ngôn ngữ, dùng khi khởi động và khi thay đổi ngôn ngữ
254// Tác dụng: Đọc các file ngôn ngữ trong Langugue và Langugue\Plugins
255//******************************************************************************
256
257function LoadLanguage() {
258        lang.onData = function() {
259                CreateMenuBar();
260                AutoCheckVersion();
261                //if (online && userId==0) LoginViolet();
262                if (online && userId == 0) {
263                        LoadUserInfo();
264                } else {
265                        UpdateFromFlashVars();
266                }
267        }
268        loadVariables(appPath + "Language" + slash + language + ".txt", lang);
269        RemoveAllChild(lang);
270        var plang = lang.createEmptyMovieClip("plgLang", 0);
271        var llang = lang.createEmptyMovieClip("layLang", 1);
272        loadVariables(appPath + "Language" + slash + "Plugins" + slash + language + ".txt", plang);
273        loadVariables(appPath + "Layout" + slash + "Language" + slash + language + ".txt", llang);
274        LoadLibLanguage(commonLibList, commonLibDir);
275}
276
277function LoadOldPlgLang(plulist) {
278        for( var i = 0; i < plulist.length; i++ ) {
279                var name = plulist[i].attributes.name;
280                if (name=="vpTest" || name=="vpDrag" || name=="vpCross") {
281                        var lang = lang.createEmptyMovieClip(name, lang.getNextHighestDepth());
282                        loadVariables(appPath + plulist[i].attributes.language + slash + language + ".txt", lang);
283                }
284        }
285}
286
287function LoadLibLanguage(libStr, libDir) {
288        var libs = libStr.split(",");
289        for (var i = 0; i < libs.length; i++) {
290                if (libs[i].substr(-4).toLowerCase() != ".swf") continue;
291                var name = libs[i].substr(0, -4);
292                var file = libDir + slash + name + "_lang" + slash + language + ".txt";
293                if (lang[name]) lang[name].removeMovieClip();
294                var lib = lang.createEmptyMovieClip(name, lang.getNextHighestDepth());
295                loadVariables(file, lib);
296        }
297}
298
299function GetPluginTitle(node) {
300        var isXml = (typeof(node) != "string");
301        var name = isXml? node.attributes.name: node;
302        var title = lang.plgLang[name];
303        if (!title && isXml) title = node.attributes.title;
304        return title? title: name;
305}
306
307function RunAfterLoadPlgLang(plgNode, UpdateList) {
308        for (var i = 0; i < plgNode.childNodes.length; i++) {
309                if (!_root.lang.plgLang[plgNode.attributes.name]) break;
310        }
311        if (i < plgNode.childNodes.length) {
312                loadVariables(pluginUrl + "language/" + language + ".txt", lang.plgLang);
313                lang.plgLang.onData = UpdateList;
314                needUpdatePluginLang = true;
315        }
316        else UpdateList();
317}
318
319function UpdatePluginLang() {
320        if (!needUpdatePluginLang) return;
321        fscommand("Download Plugin", pluginUrl + "language/Language.zip");
322        needUpdatePluginLang = false;
323}
324
325//******************************************************************************
326// Hàm tự động kiểm tra phiên bản phần mềm và xử lý khi phiên bản đã cũ
327// Tác dụng: Đọc file thông tin violet.inf trên server, so sánh phiên bản và
328//   + nếu update_level = 0 thì không làm gì
329//   + nếu update_level = 1 thì thông báo và chạy tiếp
330//   + nếu update_level = 2 thì thông báo và ngừng chương trình
331//******************************************************************************
332
333function AutoCheckVersion() {
334        var verlv = new LoadVars();
335        verlv.load("http://www.bachkim.vn/resource/violet.inf");
336        verlv.onLoad = function(success) {
337                if (!success) return;
338                var lastest = Number(verlv.violet_version);
339                var prever = Number(verlv.violet_preversion);
340                var level = Number(verlv.update_level);
341                if (level > 0 && prever < version && version < lastest) {
342                        ShowMessage(lang.msgNeedUpdate, lang.msgTitle, function() {
343                                if (level == 2) fscommand("Quit", "");
344                        });
345                }
346        }
347}
348
349//******************************************************************************
350// Hàm nạp dữ liệu từ file ngoài (*.XVL), được gọi trong chức năng MỞ FILE
351// Tác dụng: Tạo biến dataXML và gọi lệnh để đọc dữ liệu từ file vào biến này
352//******************************************************************************
353
354function LoadXMLData(fileName) {
355        dataXML = new XML();
356        dataXML.onLoad = onLoadData;
357        dataXML.ignoreWhite = true;
358        dataXML.load(fileName);
359        movScene.dataXML = dataXML;
360}
361
362//******************************************************************************
363// Hàm thông báo lỗi nếu có lỗi khi mở file, được gọi trong hàm onLoadData()
364//******************************************************************************
365
366function ErrorMessage(message) {
367        ShowMessage(message, lang.msgTitle1);
368        CreateNewData();
369}
370
371//******************************************************************************
372// Hàm cập nhật toàn bộ màn hình Violet mỗi khi dữ liệu dataXML thay đổi một
373// cách bất kỳ. Hàm được gọi khi load một XML mới hoặc khi undo, redo.
374// Tác dụng: Cập nhất nội dung Tree mới và cập nhật phần danh sách file.
375//******************************************************************************
376
377function UpdateScreen() {
378        var index = 0;
379        var a = new XML();
380
381        for( var i=0; i<dataXML.firstChild.childNodes.length; i++ )
382        {
383                var x = a.createElement("node");
384                x.attributes.label = dataXML.firstChild.childNodes[i].attributes.label;
385                x.attributes.section = i+1;
386                x.attributes.item = 0;
387               
388                for( var j=0; j<dataXML.firstChild.childNodes[i].childNodes.length; j++ )
389                {
390                        var y = a.createElement("node");
391                        y.attributes.label = dataXML.firstChild.childNodes[i].childNodes[j].attributes.label;
392                        y.attributes.section = i+1;
393                        y.attributes.item = j+1;
394                        x.appendChild(y);
395                }
396               
397                a.appendChild(x);
398                treItem.addItem(a.childNodes[i]);
399                treItem.setIsOpen(treItem.getNodeDisplayedAt(index), true, false, null);
400                index += (x.childNodes.length+1);
401        }
402        treItem.setFocus();
403        GetRelatedFiles();
404}
405
406//******************************************************************************
407// Hàm sự kiện được gọi sau khi đã đọc xong dữ liệu từ file XVL vào biến
408// dataXML bằng hàm LoadXMLData(fileName) ở trên
409// Tác dụng:
410//   - Thiết lập nội dung của TreeView
411//   - Xử lý hiển thị vùng PREVIEW của bài giảng
412//   - Xử lý phần danh sách các file dữ liệu
413//******************************************************************************
414
415function onLoadData(success)
416{
417        //ShowGrayScreen(false);
418        if( !success ) {
419                ErrorMessage(lang.msgOpenError);
420                return;
421        }
422        if( dataXML.firstChild.nodeName != "LECTURE_INFO" ) {
423                ErrorMessage(lang.msgInvalidFile);
424                return;
425        }
426        if( dataXML.status<0 ) {
427                ErrorMessage(lang.msgCorruptFile);
428                return;
429        }
430
431        if( dataXML.firstChild.attributes.Version ) {
432                var encode = GetAttribute(dataXML.xmlDecl, "encoding");
433                if (encode == null) UnicodeAscii(unescape, dataXML.firstChild);
434        }
435
436        ChangeDataVersion();
437        if (currentFile == "") {
438                var change = function(fn) {return GetFullFileName(fn, openedFileName)};
439                GetDataChangePath(change, dataXML.firstChild);
440        }
441        movScene.GetBackGround();
442        dataXML.firstChild.attributes.Version = version;
443        dataXML.firstChild.attributes.CommonDir = commonDir;
444        if( !appUserName ) delete dataXML.firstChild.attributes.Info;
445        else {
446                dataXML.firstChild.attributes.Info = unescape(appUserName) + " - " + unescape(appAddress);
447                dataXML.firstChild.attributes.Check = dataXML.firstChild.attributes.Info.length + 13;
448        }
449        if (autoPackage) {
450                GetRelatedFiles(true);
451                CreatePackage("Overwrite");
452                fscommand("Quit", "");
453                return;
454        }
455        UpdateScreen();
456        movScene.onLoadXMLData();
457}
458
459//******************************************************************************
460// Hàm xử lý việc lựa chọn các item khác nhau của TreeView
461// Tác dụng: Phần PREVIEW sẽ nhảy đến trang màn hình tương ứng với mục đã
462// chọn trên TreeView
463//******************************************************************************
464
465function onChangeHandle(obj) {
466        var section = treItem.selectedNode.attributes.section;
467        var item = treItem.selectedNode.attributes.item;
468        movScene.gotoScreen(section, item, true);
469        oldTreeSelect = treItem.selectedIndex;
470}
471
472//******************************************************************************
473// Hàm xử lý sự kiện khi người dùng click chuột trên TreeView
474// Tác dụng: Gọi hàm onChangeHandle() để thay đổi nội dung TreeView theo mục
475// lựa chọn, và kiểm tra nếu như nhấn double-click sẽ gọi chức năng sửa đổi mục
476//******************************************************************************
477
478function onTreeViewChange(obj) {
479        var again = (treItem.selectedIndex == oldTreeSelect);
480        if( !again ) onChangeHandle(obj);
481        if( IsDblClick(_root) && again) btnDetail.onRelease();
482}
483
484//******************************************************************************
485// Hàm thiết lập vị trí hiện hành của TreeView, được gọi khi người dùng chọn
486// chủ đề hoặc chọn mục trên phần PREVIEW
487// Tác dụng:
488//   Tìm item trên TreeView có các thông số chủ đề và mục giống như trong phần
489//   PREVIEW bài giảng, sau đó thiết lập item này là vị trí hiện hành
490// Tham số:
491//   section, item: chủ đề và mục đang được lựa chọn trên PREVIEW
492//******************************************************************************
493
494function gotoTreeItem(section, item) {
495        var i = 0;
496        if( section>0 && treItem.length>0 ) {
497                while( i<treItem.length && treItem.getItemAt(i).attributes.section!=section ) {
498                        i++;
499                }
500                var node = treItem.getItemAt(i);
501                if( !getIsOpen(node) ) treItem.setIsOpen(node, true, false, null);
502       
503                while( i<treItem.length && treItem.getItemAt(i).attributes.item!=item ) {
504                        i++;
505                }
506        }
507        if( i<treItem.length ) treItem.selectedIndex = oldTreeSelect = i;
508}
509
510//******************************************************************************
511// Hàm thêm chủ đề và mục mới, được gọi ở bước cuối trong chức năng "Thêm mục"
512// (trường hợp người dùng CÓ nhập chủ đề mới)
513// Tác dụng:
514//   Thêm một chủ đề mới vào vị trí cuối cùng, sau đó thêm mục đầu tiên vào
515//   chủ đề rỗng này
516// Tham số:
517//   itemData: dữ liệu dạng XML node của chủ đề cần thêm vào
518//******************************************************************************
519
520function AddSectionData(itemData, pos) {
521        var a = new XML();
522        var x = a.createElement("node");
523        x.attributes.label = itemData.attributes.label;
524        x.attributes.section = (pos!=undefined)? pos+1: dataXML.firstChild.childNodes.length+1;
525        x.attributes.item = 0;
526
527        for( var j=0; j<itemData.childNodes.length; j++ )
528        {
529                var y = a.createElement("node");
530                y.attributes.label = itemData.childNodes[j].attributes.label;
531                y.attributes.section = x.attributes.section;
532                y.attributes.item = j+1;
533                x.appendChild(y);
534        }
535        a.appendChild(x);
536       
537        var i = (pos==undefined)? treItem.length: 0;
538        while( i<treItem.length && treItem.getItemAt(i).attributes.section != x.attributes.section ) i++;
539        var trePos = i;
540        while( i<treItem.length ) {
541                var node = treItem.getItemAt(i);
542                node.attributes.section++;
543                if( node.attributes.item==0 ) treItem.setIsOpen(node, true, false, null);
544                i++;
545        }
546        treItem.addItemAt(trePos, a.lastChild);
547        treItem.setIsOpen(x, true, false, null);
548
549        UpdateUndoData();
550        if( pos==undefined ) dataXML.firstChild.appendChild(itemData);
551        else dataXML.firstChild.insertBefore(itemData, dataXML.firstChild.childNodes[pos]);
552        movScene.RefreshSectionButton();
553        treItem.selectedIndex = trePos + 1;
554        onChangeHandle(0);
555
556        GetRelatedFiles();
557}
558
559//******************************************************************************
560// Hàm thêm mục mới, được gọi ở bước cuối trong chức năng "Thêm mục" (trường
561// hợp người dùng KHÔNG nhập chủ đề mới)
562// Tác dụng: Thêm một mục mới vào vị trí cuối cùng của chủ đề đã có.
563// Tham số:
564//   index: thứ tự của chủ đề (tính từ 0)
565//   itemData: dữ liệu dạng XML node của mục cần thêm vào
566//******************************************************************************
567
568function AddItemData(index, itemData) {
569        if( index < 0 ) index = 0;
570        if( !dataXML.firstChild.childNodes[index] ) return;
571       
572        for( var i=0; i<treItem.length; i++ ) {
573                if( treItem.getItemAt(i).attributes.section == index+1 ) break;
574        }
575        var sectionNode = treItem.getItemAt(i);
576        var itemNode = commonXML.createElement("node");
577        itemNode.attributes.label = itemData.attributes.label;
578        itemNode.attributes.section = index + 1;
579        itemNode.attributes.item = sectionNode.childNodes.length + 1;
580
581        var newPos = i + 1 + sectionNode.childNodes.length;
582        treItem.setIsOpen(sectionNode, true, false, null);
583        treItem.addItemAt(newPos, itemNode);
584        sectionNode.appendChild(itemNode);
585       
586        UpdateUndoData();
587        dataXML.firstChild.childNodes[index].appendChild(itemData);
588        movScene.RefreshItemButton();
589        treItem.selectedIndex = newPos;
590        onChangeHandle(0);
591
592        GetRelatedFiles();
593}
594
595//******************************************************************************
596function ChangeHyperlink()
597{
598        for( var i=0; i<dataXML.firstChild.childNodes.length; i++ ) {
599                var secNode = dataXML.firstChild.childNodes[i];
600                for( var j=0; j<secNode.childNodes.length; j++ ) {
601                        var iteNode = secNode.childNodes[j];
602                        for( var k=0; k<iteNode.childNodes.length; k++ ) {
603                                var node = iteNode.childNodes[k];
604                                ChangeHyperlinkNode(node);
605                                if( node.nodeName == "PLUGIN" ) {
606                                        var subNodes = node.firstChild.childNodes;
607                                        for( var m=0; m<subNodes.length; m++ ) ChangeHyperlinkNode(subNodes[m]);
608                                }
609                        }
610                }
611        }
612}
613
614//******************************************************************************
615function ChangeHyperlinkNode(node)
616{
617        if( node.attributes.hyperlink.charAt(0) == "2" ) {
618                var a = node.attributes.hyperlink.split("|");
619                for( var c=0; c<curPos.length; c+=2 ) {
620                        if( Number(a[1])==curPos[c] && Number(a[2])==curPos[c+1] ) {
621                                if( repPos[c]==-1 ) delete node.attributes.hyperlink;
622                                else node.attributes.hyperlink = "2|" + repPos[c] + "|" + repPos[c+1];
623                                break;
624                        }
625                }
626        }
627}
628
629//******************************************************************************
630// Hàm xóa mục, chủ đề,... được gọi khi người dùng chọn chức năng xóa mục và
631// đã trả lời xác nhận là có chắc chắn xóa
632// Tác dụng:
633//   Xóa đối tượng đang được lựa chọn trên TreeView (trang bìa, chủ đề hoặc
634//   mục). Nếu xóa một chủ đề thì toàn bộ các mục trong đó cũng bị xóa theo
635//******************************************************************************
636
637function DeleteItem(delOnly)
638{
639        var section = treItem.selectedNode.attributes.section;
640        var item = treItem.selectedNode.attributes.item;
641        var i = treItem.selectedIndex;
642        var oldSel = i;
643
644        if( !delOnly ) {
645                curPos.splice(0);
646                repPos.splice(0);
647                UpdateUndoData();
648        }
649
650        //
651        // Nếu mục đang chọn là duy nhất trong chủ đề thì sẽ xóa cả chủ đề đi
652        //
653        if( item == 1 && treItem.getItemAt(i+1).attributes.section != section ) {
654                item = 0; i--;
655        }
656
657        //
658        // Nếu đang chọn mục thì sẽ xóa mục
659        //
660        if( item > 0 ) {
661                dataXML.firstChild.childNodes[section-1].childNodes[item-1].removeNode();
662
663                if( !delOnly ) {
664                        curPos.push(section);
665                        curPos.push(item);
666                        repPos.push(-1);
667                        repPos.push(-1);
668                }
669                treItem.getItemAt(i).removeTreeNode();
670                treItem.removeItemAt(i);
671                while( i<treItem.length && treItem.getItemAt(i).attributes.section == section ) {
672                        curPos.push(section);
673                        curPos.push(treItem.getItemAt(i).attributes.item);
674                        repPos.push(section);
675                        repPos.push(treItem.getItemAt(i).attributes.item-1);
676                        treItem.getItemAt(i).attributes.item--;
677                        i++;
678                }
679        }
680        //
681        // còn nếu đang chọn chủ đề thì sẽ xóa chủ đề
682        //
683        else {
684                dataXML.firstChild.childNodes[section-1].removeNode();
685
686                while( i<treItem.length && treItem.getItemAt(i).attributes.section == section ) {
687                        if( !delOnly ) {
688                                curPos.push(section);
689                                curPos.push(treItem.getItemAt(i).attributes.item);
690                                repPos.push(-1);
691                                repPos.push(-1);
692                        }
693                        treItem.getItemAt(i).removeTreeNode();
694                        treItem.removeItemAt(i);
695                }
696                while( i<treItem.length ) {
697                        var node = treItem.getItemAt(i);
698                        if( !delOnly ) {
699                                curPos.push(node.attributes.section);
700                                curPos.push(node.attributes.item);
701                                repPos.push(node.attributes.section-1);
702                                repPos.push(node.attributes.item);
703                        }
704                        node.attributes.section--;
705                        if( node.attributes.item==0 ) treItem.setIsOpen(node, true, false, null);
706                        i++;
707                }
708        }
709
710        if( delOnly ) return;
711
712        if( treItem.length > 0 ) {
713                if( oldSel<treItem.length ) treItem.selectedIndex = oldSel;
714                else treItem.selectedIndex = treItem.length - 1;
715                onChangeHandle(0);
716        } else {
717                movScene.gotoScreen(0, 0, true);
718        }
719       
720        movScene.RefreshSectionButton();
721        movScene.RefreshItemButton();
722        ChangeHyperlink();
723        GetRelatedFiles();
724}
725
726//******************************************************************************
727// Hàm xử lý sự kiện click của nút dịch chuyển lên
728// Tác dụng:
729//   Dịch chuyển một chủ đề hoặc mục lên trước một mức. Các mục có thể dịch
730//   chuyển qua lại được giữa các chủ đề. Khi dịch chuyển một chủ đề thì toàn
731//   bộ mục trong đó cũng được dịch chuyển theo
732//******************************************************************************
733
734btnMoveUp.onRelease = function() {
735        if( treItem.length == 0 ) return;
736        var index = treItem.selectedIndex;
737        var node = treItem.getItemAt(index);
738        var item = node.attributes.item;
739        var section = node.attributes.section;
740        if( section == 0 ) return;
741       
742        curPos.splice(0);
743        repPos.splice(0);
744        UpdateUndoData();
745
746        //
747        // Nếu là thao tác dịch chuyển mục
748        //
749        if( item != 0 ) {
750                if( item == 1 && section==1 ) return;
751
752                //
753                // Nếu là mục đầu tiên thì mục sẽ được chuyển vào vị trí cuối cùng
754                // của chủ đề liền trước
755                //
756                if( item == 1 ) {
757                        //
758                        // Xóa mục ở chủ đề cũ
759                        //
760                        var dataNode = dataXML.firstChild.childNodes[section-1].firstChild;
761                        DeleteItem(true);
762                        movScene.RefreshSectionButton();
763
764                        //
765                        // Thêm mục vào chủ đề mới
766                        //
767                        var sectionNode;
768                        for( var i=0; i<treItem.length; i++ ) {
769                                sectionNode = treItem.getItemAt(i);
770                                if( sectionNode.attributes.section == section-1 ) break;
771                        }
772                        treItem.setIsOpen(sectionNode, true, false, null);
773                        var newPos = i + 1 + sectionNode.childNodes.length;
774                       
775                        node.attributes.section = section-1;
776                        node.attributes.item = sectionNode.childNodes.length + 1;
777                        treItem.addItemAt(newPos, node);
778                        sectionNode.appendChild(node);
779                        treItem.selectedIndex = newPos;
780
781                        curPos.push(section);
782                        curPos.push(1);
783                        repPos.push(section-1);
784                        repPos.push(node.attributes.item);
785
786                        dataXML.firstChild.childNodes[section-2].appendChild(dataNode);
787                }
788                //
789                // còn nếu không phải là đầu tiên thì mục sẽ được hoán đổi vị trí
790                // với mục liền trước
791                //
792                else {
793                        //
794                        // Hoán đổi mục trong TreeView
795                        //
796                        var sectionNode = treItem.getItemAt(index).parentNode;
797                        sectionNode.childNodes[item-1].removeNode();
798                        sectionNode.insertBefore(node, sectionNode.childNodes[item-2]);
799
800                        treItem.removeItemAt(index);
801                        treItem.addItemAt(index-1, node);
802                        treItem.getItemAt(index).attributes.item++;
803                        treItem.getItemAt(index-1).attributes.item--;
804                        treItem.selectedIndex = index-1;
805               
806                        //
807                        // Hoán đổi mục trong dataXML
808                        //
809                        var data = dataXML.firstChild.childNodes[section-1];
810                        var temp = data.childNodes[item-1];
811                        data.childNodes[item-1].removeNode();
812                        data.insertBefore(temp, data.childNodes[item-2]);
813
814                        curPos.push(section);
815                        curPos.push(item);
816                        repPos.push(section);
817                        repPos.push(item-1);
818                        curPos.push(section);
819                        curPos.push(item-1);
820                        repPos.push(section);
821                        repPos.push(item);
822
823                        movScene.RefreshItemButton();
824                }
825        }
826       
827        //
828        // còn nếu thao tác là dịch chuyển chủ đề
829        //
830        else {
831                if( section == 1 ) return;
832
833                //
834                // Đóng chủ đề hiện hành và chủ đề liền trước nó (nếu đang được mở)
835                // để dễ dàng hoán đổi đổi vị trí
836                //
837                prevNode = treItem.getItemAt(index-1);
838                if( prevNode.attributes.item != 0 ) prevNode = prevNode.parentNode;
839                treItem.setIsOpen(node, false, false, null);
840                treItem.setIsOpen(prevNode, false, false, null);
841
842                //
843                // Hoán đổi vị trí hai chủ đề (đã được đóng) trong TreeView
844                //
845                var i = treItem.getDisplayIndex(node);
846                treItem.removeItemAt(i);
847                treItem.addItemAt(i-1, node);
848                treItem.setIsOpen(node, true, false, null);
849                treItem.setIsOpen(prevNode, true, false, null);
850                node.attributes.section--;
851                prevNode.attributes.section++;
852                for( i=0; i<node.childNodes.length; i++ ) {
853                        curPos.push(node.childNodes[i].attributes.section);
854                        curPos.push(node.childNodes[i].attributes.item);
855                        repPos.push(node.childNodes[i].attributes.section-1);
856                        repPos.push(node.childNodes[i].attributes.item);
857                        node.childNodes[i].attributes.section--;
858                }
859                for( i=0; i<prevNode.childNodes.length; i++ ) {
860                        curPos.push(prevNode.childNodes[i].attributes.section);
861                        curPos.push(prevNode.childNodes[i].attributes.item);
862                        repPos.push(prevNode.childNodes[i].attributes.section+1);
863                        repPos.push(prevNode.childNodes[i].attributes.item);
864                        prevNode.childNodes[i].attributes.section++;
865                }
866                treItem.selectedIndex = treItem.getDisplayIndex(node);
867
868                //
869                // Hoán đổi vị trí hai chủ đề trong biến dataXML
870                //
871                var data = dataXML.firstChild;
872                var temp = data.childNodes[section-1];
873                data.childNodes[section-1].removeNode();
874                data.insertBefore(temp, data.childNodes[section-2]);
875
876                movScene.RefreshSectionButton();
877        }
878        ChangeHyperlink();
879        onChangeHandle(0);
880}
881
882//******************************************************************************
883// Hàm xử lý sự kiện click của nút dịch chuyển xuống
884// Tác dụng:
885//   Dịch chuyển một chủ đề hoặc mục về phía sau một mức. Các tính năng khác
886//   tương tự như trong hàm sự kiện của nút dịch lên
887//******************************************************************************
888
889btnMoveDown.onRelease = function() {
890        if( treItem.length == 0 ) return;
891        var index = treItem.selectedIndex;
892        var node = treItem.getItemAt(index);
893        var item = node.attributes.item;
894        var section = node.attributes.section;
895        if( section == 0 ) return;
896       
897        curPos.splice(0);
898        repPos.splice(0);
899        UpdateUndoData();
900
901        if( item != 0 ) {
902                if( item == node.parentNode.childNodes.length &&
903                        section == dataXML.firstChild.childNodes.length )
904                        return;
905                       
906                if( item == node.parentNode.childNodes.length ) {
907                        var dataSection = dataXML.firstChild.childNodes[section-1];
908                        var dataNode = dataSection.childNodes[item-1];
909                        if( dataSection.childNodes.length==1 ) {index--; section--}
910                        DeleteItem(true);
911                        movScene.RefreshSectionButton();
912
913                        var sectionNode = treItem.getItemAt(index);
914                        treItem.setIsOpen(sectionNode, true, false, null);
915                       
916                        node.attributes.section = section+1;
917                        node.attributes.item = 1;
918                        sectionNode.insertBefore(node, sectionNode.firstChild);
919                       
920                        i = index + 1;
921                        while( treItem.getItemAt(i).attributes.section == section+1 && i<treItem.length) {
922                                curPos.push(section+1);
923                                curPos.push(treItem.getItemAt(i).attributes.item);
924                                repPos.push(section+1);
925                                repPos.push(treItem.getItemAt(i).attributes.item+1);
926                                treItem.getItemAt(i).attributes.item++;
927                                i++;
928                        }
929                        treItem.addItemAt(index+1, node);
930                        treItem.selectedIndex = index+1;
931
932                        curPos.push(section);
933                        curPos.push(item);
934                        repPos.push(section+1);
935                        repPos.push(1);
936
937                        dataSection = dataXML.firstChild.childNodes[section];
938                        dataSection.insertBefore(dataNode, dataSection.firstChild);
939                } else {
940                        var sectionNode = treItem.getItemAt(index).parentNode;
941                        sectionNode.childNodes[item-1].removeNode();
942                        sectionNode.insertBefore(node, sectionNode.childNodes[item]);
943
944                        treItem.removeItemAt(index);
945                        treItem.addItemAt(index+1, node);
946                        treItem.getItemAt(index).attributes.item--;
947                        treItem.getItemAt(index+1).attributes.item++;
948                        treItem.selectedIndex = index+1;
949
950                        var data = dataXML.firstChild.childNodes[section-1];
951                        var temp = data.childNodes[item-1];
952                        data.childNodes[item-1].removeNode();
953                        data.insertBefore(temp, data.childNodes[item]);
954
955                        curPos.push(section);
956                        curPos.push(item);
957                        repPos.push(section);
958                        repPos.push(item+1);
959                        curPos.push(section);
960                        curPos.push(item+1);
961                        repPos.push(section);
962                        repPos.push(item);
963
964                        movScene.RefreshItemButton();
965                }
966        } else {
967                if( section == node.parentNode.childNodes.length ) return;
968                treItem.setIsOpen(node, false, false, null);
969                nextNode = treItem.getItemAt(index+1);
970                treItem.setIsOpen(nextNode, false, false, null);
971
972                treItem.removeItemAt(index);
973                treItem.addItemAt(index+1, node);
974                treItem.setIsOpen(node, true, false, null);
975                treItem.setIsOpen(nextNode, true, false, null);
976                node.attributes.section++;
977                nextNode.attributes.section--;
978                for( i=0; i<node.childNodes.length; i++ ) {
979                        curPos.push(node.childNodes[i].attributes.section);
980                        curPos.push(node.childNodes[i].attributes.item);
981                        repPos.push(node.childNodes[i].attributes.section+1);
982                        repPos.push(node.childNodes[i].attributes.item);
983                        node.childNodes[i].attributes.section++;
984                }
985                for( i=0; i<nextNode.childNodes.length; i++ ) {
986                        curPos.push(nextNode.childNodes[i].attributes.section);
987                        curPos.push(nextNode.childNodes[i].attributes.item);
988                        repPos.push(nextNode.childNodes[i].attributes.section-1);
989                        repPos.push(nextNode.childNodes[i].attributes.item);
990                        nextNode.childNodes[i].attributes.section--;
991                }
992                treItem.selectedIndex = treItem.getDisplayIndex(node);
993
994                var data = dataXML.firstChild;
995                var temp = data.childNodes[section-1];
996                data.childNodes[section-1].removeNode();
997                data.insertBefore(temp, data.childNodes[section]);
998
999                movScene.RefreshSectionButton();
1000        }
1001        ChangeHyperlink();
1002        onChangeHandle(0);
1003}
1004
1005//******************************************************************************
1006// Hàm kiểm tra xem tên file đã nằm trong danh sách hay chưa
1007// Công việc:
1008//   - Duyệt tất cả danh sách tên file (fileList) ở những vị trí chẵn, nếu
1009//     có phần tử trùng tên với tên file đang xét thì return lại kết quả
1010// Tham số:
1011//   - fileName: tên file có đầy đủ đường dẫn
1012// Trả về:
1013//   - true nếu fileName đã nằm trong danh sách
1014//   - false nếu fileName chưa nằm trong danh sách
1015//******************************************************************************
1016
1017function AlreadyInList(fileName) {
1018        for( var i=0; i<fileList.length; i+=2 ) {
1019                if( fileName == fileList[i] ) return true;
1020        }
1021        return false;
1022}
1023
1024function UniqueFileName(fileName, id) {
1025        var dp = fileName.lastIndexOf(".");
1026        var newName = fileName.substr(0, dp) + (id==0? "": "(" +id +")") + fileName.substr(dp);
1027        for( var i=1; i<fileList.length; i+=2 ) {
1028                if( newName == fileList[i] ) return UniqueFileName(fileName, id + 1);
1029        }
1030        return newName;
1031}
1032
1033//******************************************************************************
1034// Hàm thêm file vào danh sách, được gọi khi xây dựng danh sách file dữ liệu
1035// Tác dụng:
1036//   - Thêm tên file đầy đủ (gồm cả đường dẫn) vào danh sách
1037//   - Thêm tên file không có đường dẫn vào danh sách
1038//   - Tạo lập một đối tượng hiển thị (tương ứng với file) trong ScrollPane,
1039//     đối tượng này bao gồm 1 biểu tượng và tên file không có đường dẫn
1040// Tham số:
1041//   - id: thứ tự của file
1042//   - fileName: tên file có đầy đủ đường dẫn
1043// Trả về:
1044//   - tên file không có đường dẫn
1045//******************************************************************************
1046
1047function AddToList(fileName, fileType)
1048{
1049        if( fileName == "" || fileName == undefined ) return "";
1050        if( fileType != "LIBFILE_INFO" ) {
1051                fileName = GetFullFileName(fileName);
1052        }
1053
1054        var destDir = isCommon ? commonDir : dataDir;
1055        switch( fileType ) {
1056        case "COMMON_FILE":
1057                destDir = commonDir;
1058                commonFileNum ++;
1059                break;
1060        case "EXEC_FILE":
1061                destDir = "fscommand";
1062                execFileNum ++;
1063                break;
1064        default:
1065                destDir = dataDir;
1066                dataFileNum ++;
1067        }
1068        var pos = Math.max(fileName.lastIndexOf("\\"), fileName.lastIndexOf("/"));
1069        var subName = fileName.substr(pos+1);
1070        var destFile = destDir + "/" + GetSafeFileName(subName);
1071
1072        if( AlreadyInList(fileName) ) return destFile;
1073        destFile = UniqueFileName(destFile, 0);
1074        fileList.push(fileName);
1075        fileList.push(destFile);
1076        fileListStr = fileList.join("|");
1077        if( fileType == "COMMON_FILE" ) return destFile;
1078
1079        if( !eval("scpFileList.content.movFileItem"+file_id)) {
1080                scpFileList.content.movFileItem.duplicateMovieClip("movFileItem"+file_id, file_id);
1081        }
1082        var item = eval("scpFileList.content.movFileItem"+file_id);
1083        item._x = file_id*130 + 26;
1084        item.label = subName;
1085        item.lblFileName.autoSize = "left";
1086        item.lblFileName._y = 16 - item.lblFileName._height/2;
1087       
1088        var pos = subName.lastIndexOf(".") + 1;
1089        var extname = subName.substr(pos).toLowerCase();
1090        item.movIcon.gotoAndStop(1);
1091        if( extname == "jpg" || extname == "jpeg") item.movIcon.gotoAndStop(2);
1092        if( extname == "swf" ) item.movIcon.gotoAndStop(3);
1093        if( extname == "flv" ) item.movIcon.gotoAndStop(4);
1094        if( extname == "mp3" ) item.movIcon.gotoAndStop(5);
1095       
1096        if( extname != "swf" ) item.fullName = fileName;
1097        else item.fullName = fileName.substr(0, fileName.length-3) + "fla";
1098
1099        item.onRelease = function() {
1100                this.onDragOut();
1101                EditFile(this.fullName);
1102        }
1103        item.onDragOut = function() {
1104                this._x --;
1105                this._y --;
1106                this.onRollOut();
1107        }
1108        item.onPress = item.onDragOver = function() {
1109                this._x ++;
1110                this._y ++;
1111                this.onRollOver();
1112        }
1113        item.onRollOut = function() {
1114                this._alpha = 65;
1115                this.lblFileName.textColor = 0x5F5F5F;
1116        }
1117        item.onRollOver = function() {
1118                this._alpha = 100;
1119                this.lblFileName.textColor = 0x000000;
1120        }
1121        item.onRollOut();
1122
1123        file_id++;
1124        return destFile;
1125}
1126
1127//******************************************************************************
1128// Hàm xác định danh sách các file dữ liệu, được gọi trong các thao tác thêm
1129// xóa mục dữ liệu có chứa file, thêm xóa trang bìa, mở file, tạo mới,...
1130// Tác dụng:
1131//   - Tạo danh sách file dữ liệu (có cả tên đầy đủ và tên không đường dẫn)
1132//   - Tạo một XML mới mà tất cả tên file trong đó đều không có đường dẫn.
1133//     XML này và danh sách file dữ liệu trên sẽ được dùng để phục vụ cho
1134//     việc "Tạo phần mềm" của chương trình C++
1135//   - Tạo nội dung của đối tượng ScrollPane danh sách file
1136// Kết quả:
1137//   - biến fileList: mảng danh sách tên file dữ liệu
1138//   - biến packXML: XML mà dữ tên file đã được cắt đường dẫn
1139//   - scpFileList.content: nội dung của ScrollPane danh sách file
1140//******************************************************************************
1141
1142function GetRelatedFiles(isPacking) {
1143        if( fileList ) delete fileList;
1144        fileList = new Array();
1145
1146        if( !dataXML.firstChild.firstChild ) dataXML.firstChild.appendChild(movScene.bkgnd_node);
1147        else dataXML.firstChild.insertBefore(movScene.bkgnd_node, dataXML.firstChild.firstChild);
1148
1149        packXML = new XML(dataXML.toString());
1150        commonFileNum = dataFileNum = execFileNum = 0;
1151        file_id = 0;
1152
1153        var slashPos = Math.max(currentFile.lastIndexOf("\\"), currentFile.lastIndexOf("/"));
1154        var subName = currentFile.substr(slashPos+1);
1155        var dotPos = subName.lastIndexOf(".");
1156        subName = subName.substring(0, dotPos);
1157        if( !packXML.firstChild.attributes.AppName || subName != "Scenario" )
1158                packXML.firstChild.attributes.AppName = subName;
1159
1160        var layout = dataXML.firstChild.attributes.Layout;
1161        if( layout != "" ) AddToList(commonPath + layout, "COMMON_FILE");
1162        ChangeLayoutFileParam(packXML.firstChild, AddToList);
1163
1164        for (var i = 0; i < commonLib.libList.length; i++) RemoveCommonLib(packXML, commonLib.libList[i].file);
1165        AddCommonLib(packXML, GetEffectLib(dataXML.firstChild.attributes.PageTransition));
1166
1167        for( var i=0; i<dataXML.firstChild.childNodes.length; i++ ) {
1168                var node = dataXML.firstChild.childNodes[i];
1169                for( var j=0; j<node.childNodes.length; j++ ) {
1170                        var subnode = node.childNodes[j];
1171                        var packnode = packXML.firstChild.childNodes[i].childNodes[j];
1172                        for( var k=0; k<subnode.childNodes.length; k++ ) {
1173                                var element = subnode.childNodes[k];
1174                                var pkNode = packnode.childNodes[k];
1175                                if( element.nodeName == "IMAGE" || element.nodeName == "MEDIA" ) {
1176                                        pkNode.attributes.url = AddToList(element.attributes.url);
1177                                }
1178                                if( element.nodeName == "PLUGIN" ) {
1179                                        var plgNode = pkNode.firstChild;
1180                                        ChangeXMLFileInfo(plgNode, AddToList, pluXML.childNodes[1].childNodes[1].attributes[plgNode.nodeName]);
1181                                        if (isPacking) {
1182                                                pkNode.attributes.url = AddToList(appPath + element.attributes.player, "COMMON_FILE");
1183                                                if (vietType && GetXMLUsingKB(plgNode, pluXML.childNodes[1].childNodes[0].attributes[plgNode.nodeName])) {
1184                                                        AddCommonLib(packXML, "Vnkey.swf");
1185                                                }
1186                                        }
1187                                        var subNodes = element.firstChild.childNodes;
1188                                        for( var p=0; p<subNodes.length; p++ ) {
1189                                                var hl = subNodes[p].attributes.hyperlink;
1190                                                var pkSubNode = pkNode.firstChild.childNodes[p];
1191                                                if( hl.charAt(0) == "1" ) pkSubNode.attributes.hyperlink = "1|" + AddToList(hl.substr(2), "EXEC_FILE");
1192                                        }
1193                                        var langAttr = pkNode.childNodes[1].firstChild.attributes;
1194                                        for (var a in langAttr) if (a.substr(0, 5)=="file_") langAttr[a] = AddToList(langAttr[a]);
1195                                        if (plgNode.attributes.library) {
1196                                                AddCommonLib(packXML, commonLib[plgNode.attributes.library + "_info"].file);
1197                                                var attachment = commonLib[plgNode.attributes.library].firstChild.attributes.attachment;
1198                                                if (attachment != undefined) AddToList(appPath + commonLibDir + slash + attachment, "COMMON_FILE");
1199                                        }
1200                                }
1201                                if( element.attributes.hyperlink.charAt(0) == "1" ) {
1202                                        pkNode.attributes.hyperlink = "1|" + AddToList(element.attributes.hyperlink.substr(2), "EXEC_FILE");
1203                                }
1204                                AddCommonLib(packXML, GetEffectLib(element.attributes.animation));
1205                                AddCommonLib(packXML, GetEffectLib(element.attributes.effects));
1206                        }
1207                }
1208        }
1209
1210        dataXML.firstChild.firstChild.removeNode();
1211        var bgNode = packXML.firstChild.firstChild;
1212        if (bgNode.childNodes.length == 0) bgNode.removeNode();
1213
1214        var width = file_id*130 + 20;
1215        while( eval("scpFileList.content.movFileItem"+file_id)) {
1216                eval("scpFileList.content.movFileItem"+file_id).removeMovieClip();
1217                file_id++;
1218        }
1219        scpFileList.content.movBkGnd._width = (width < 732) ? 732 : width;
1220        scpFileList.redraw(true);
1221}
1222
1223//******************************************************************************
1224// Hàm thay đổi các đường dẫn trong XMLNode của Plugin (khi save as, copy-paste)
1225// Tác dụng: Đọc thông tin trong infostr dạng "name.attr", sau đó thay đổi tất
1226//   cả thuộc tính "attr" của các node có tên là "name". Nếu infostr có dạng
1227//   "name.attr(html)" thì sẽ thay đổi path trong các tag <IMG> của html đó.
1228//   Nếu không có attr thì sẽ thay đổi nội dung của textNode.
1229//******************************************************************************
1230
1231function ChangeXMLFileInfo(node, change, infostr) {
1232        if (infostr == undefined) return;
1233        var infos = infostr.split(";");
1234        for (var i = 0; i < infos.length; i++) {
1235                var html = infos[i].substr(-6) == "(html)";
1236                if (html) infos[i] = infos[i].substr(0, infos[i].length - 6);
1237                var info = infos[i].split(".");
1238                if (info[0] != node.nodeName || (info[1] != undefined && node.attributes[info[1]] == undefined)) continue;
1239                if (info[1] != undefined) node.attributes[info[1]] = ChangeFileInfo(html, change, node.attributes[info[1]]);
1240                else node.firstChild.nodeValue = ChangeFileInfo(html, change, node.firstChild.nodeValue);
1241        }
1242        for (var i = 0; i < node.childNodes.length; i++) {
1243                ChangeXMLFileInfo(node.childNodes[i], change, infostr);
1244        }
1245}
1246
1247function ChangeFileInfo(html, change, data) {
1248        return html? GetHtmlChangePath(change, data): change(data);
1249}
1250
1251//******************************************************************************
1252// Hàm cho biết có sử dụng một mục nào đó có dùng bộ gõ tiếng Việt hay không,
1253//   để khi đóng gói thì copy file Vnkey.swf theo
1254// Tác dụng: Đọc thông tin trong infostr dạng "name.attr.value", nếu node có
1255//   tên là name, thuộc tính attr bằng value thì là có dùng bộ gõ tiếng Việt
1256//******************************************************************************
1257
1258function GetXMLUsingKB(node, infostr) {
1259        if (infostr == undefined) return false;
1260        if (infostr == "") return true;
1261        var infos = infostr.split(";");
1262        for (var i = 0; i < infos.length; i++) {
1263                var info = infos[i].split(".");
1264                if (info[0] == node.nodeName && node.attributes[info[1]] == info[2]) return true;
1265        }
1266        for (var i = 0; i < node.childNodes.length; i++) {
1267                if (GetXMLUsingKB(node.childNodes[i], infostr)) return true;
1268        }
1269        return false;
1270}
1271
1272//******************************************************************************
1273// Hàm thay đổi các đường dẫn nếu có trong các tham số của Layout
1274// Tác dụng: Lấy danh sách tham số Layout, duyệt các tham số, nếu kiểu là
1275// dạng file name thì thay đổi
1276//******************************************************************************
1277
1278function ChangeLayoutFileParam(node, change) {
1279        var layout = node.attributes.Layout;
1280        var paramStr = "";
1281        var layoutInfo = layoutXML.firstChild.childNodes;
1282        for (var i = 0; i < layoutInfo.length; i++)
1283                if (layout == layoutInfo[i].attributes.file)
1284                        paramStr = layoutInfo[i].attributes.param;
1285
1286        var a = paramStr.split("|");
1287        for (var i = 0; i < a.length; i++) {
1288                var b = a[i].split(",");
1289                if (b[1] == "ImageFile" && dataXML.firstChild.attributes[b[0]])
1290                        node.attributes[b[0]] = change(dataXML.firstChild.attributes[b[0]]);
1291        }
1292}
1293
1294
1295//******************************************************************************
1296// Hàm xử lý add thêm common library vào danh sách
1297// Tác dụng: Duyệt trường commonLib của XML, nếu không thấy có libName thì
1298// add thêm vào
1299//******************************************************************************
1300
1301function AddCommonLib(xml, libName) {
1302        if (!libName) return;
1303        var libs = xml.firstChild.attributes.commonLib? xml.firstChild.attributes.commonLib.split(","): new Array();
1304        for (var i = 0; i < libs.length; i++) if (libs[i] == libName) return;
1305        libs.push(libName);
1306        AddToList(appPath + commonLibDir + slash + libName, "COMMON_FILE");
1307        xml.firstChild.attributes.commonLib = libs.join(",");
1308}
1309
1310//******************************************************************************
1311// Hàm xử lý bớt đi common library từ trong danh sách
1312// Tác dụng: Duyệt trường commonLib của XML, nếu thấy có libName thì bỏ đi
1313//******************************************************************************
1314
1315function RemoveCommonLib(xml, libName) {
1316        if (!xml.firstChild.attributes.commonLib) return;
1317        var libs = xml.firstChild.attributes.commonLib.split(",");
1318        for (var i = 0; i < libs.length; i++) if (libs[i] == libName) break;
1319        if (i == libs.length) return;
1320        libs.splice(i, 1);
1321        if (libs.length > 0) xml.firstChild.attributes.commonLib = libs.join(",");
1322        else delete xml.firstChild.attributes.commonLib;
1323}
1324
1325//******************************************************************************
1326// Hàm ghi các thông tin cấu hình vào Cookies
1327// Tác dụng: Dùng đối tượng ShareObject của Flash để ghi vào file sau đây
1328//   C:\Documents and Settings\Administrator\Application Data\Macromedia\
1329//   Flash Player\localhost\...\Violet.sol
1330//******************************************************************************
1331
1332function SaveConfig()
1333{
1334        var configSO = SharedObject.getLocal("Violet");
1335        configSO.data.windowState = windowState;
1336        configSO.data.windowTop = windowTop;
1337        configSO.data.windowLeft = windowLeft;
1338        configSO.data.windowRight = windowRight;
1339        configSO.data.windowBottom = windowBottom;
1340        configSO.data.flashViewMode = flashViewMode;
1341        configSO.data.language = language;
1342        configSO.data.vietType = vietType;
1343        configSO.data.cfgUseSnap = cfgUseSnap;
1344        configSO.data.cfgShowGrid = cfgShowGrid;
1345        configSO.data.cfgGridWidth = cfgGridWidth;
1346        configSO.data.cfgVideoFormat = cfgVideoFormat;
1347        configSO.data.libPath1 = libraryPaths.attributes.libPath + "|" + libraryPaths.attributes.libCurrentSelected + "|" + libraryPaths.attributes.libCurrentPage;
1348        configSO.data.libPath2 = lecturePaths.attributes.libPath + "|" + lecturePaths.attributes.libCurrentSelected + "|" + lecturePaths.attributes.libCurrentPage;
1349        configSO.data.fullscreen = btnSceneBkGnd._visible;
1350        if(usingNum != 200) configSO.data.remainNum = usingNum;
1351        configSO.flush();
1352        delete configSO;
1353}
1354
1355//******************************************************************************
1356// Hàm đọc các thông tin cấu hình trong Cookies ra các biến tương ứng
1357// Tác dụng: Dùng đối tượng ShareObject của Flash để đọc từ file cấu hình mà
1358// hàm SaveConfig ghi ra, sau đó thiết lập chương trình theo các thông tin này
1359//******************************************************************************
1360
1361function LoadConfig()
1362{
1363        windowState = 3;
1364        windowTop = 0;
1365        windowLeft = 0;
1366        windowRight = 0;
1367        windowBottom = 0;
1368        flashViewMode = "original size";
1369
1370        cfgUseSnap = true;
1371        cfgShowGrid = true;
1372        cfgGridWidth = 10;
1373        cfgVideoFormat = "flv";
1374       
1375        var configSO = SharedObject.getLocal("Violet");
1376        for( var a in configSO.data ) {
1377                if( a == "windowState" ) windowState = configSO.data[a];
1378                if( a == "windowTop" ) windowTop = configSO.data[a];
1379                if( a == "windowLeft" ) windowLeft = configSO.data[a];
1380                if( a == "windowRight" ) windowRight = configSO.data[a];
1381                if( a == "windowBottom" ) windowBottom = configSO.data[a];
1382                if( a == "flashViewMode" ) SetFlashViewMode(configSO.data[a]);
1383                if( a == "language" ) language = configSO.data[a];
1384                if( a == "vietType" ) vietType = configSO.data[a];
1385                if( a == "cfgUseSnap" ) cfgUseSnap = configSO.data[a];
1386                if( a == "cfgShowGrid" ) cfgShowGrid = configSO.data[a];
1387                if( a == "cfgGridWidth" ) cfgGridWidth = configSO.data[a];
1388                if( a == "cfgVideoFormat" ) cfgVideoFormat = configSO.data[a];
1389                if( a == "libPath1" ) libPath1 = configSO.data[a].split("|");
1390                if( a == "libPath2" ) libPath2 = configSO.data[a].split("|");
1391                if( a == "fullscreen" ) fullscreen = configSO.data[a];
1392                if( a == "remainNum" ) remainNum = configSO.data[a];
1393        }
1394        delete configSO;
1395
1396        if( remainNum != undefined && usingNum != 200 && Number(remainNum) <= Number(usingNum) )
1397                fscommand("bug", "");
1398
1399        if( flashViewMode == "original size" ) mnuWindow.getItemAt(2).attributes.selected = true;
1400        if( flashViewMode == "full size" ) mnuWindow.getItemAt(3).attributes.selected = true;
1401        if (!webbase) fscommand("Set State", "");
1402}
Note: See TracBrowser for help on using the repository browser.