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

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