home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / DropOffice.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  6.5 KB  |  271 lines

  1. //=========================================================================================================
  2. //
  3. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  4. //
  5. // Feature: Paste Fix
  6. // Author:  JDH
  7. // Module:  DropOffice.js
  8. // Purpose:    Called by the drag and drop mechanism in response to a file drop.
  9. // Updates:
  10. //    8/1/02 - Started file control
  11. //  3/27/03 - updated for FlashPaper.
  12. //
  13. //=========================================================================================================
  14.  
  15. var helpDoc = MM.HELP_objDropOffice;
  16.  
  17. var g_file = null;
  18. var g_returnArray = null;
  19. var g_allowInsertContents = true;
  20. var g_rememberPrefs = true;
  21. var g_fpOptions = null;
  22.  
  23. // ----------------------------------------
  24. function getSelected()
  25. {
  26.     var i;
  27.     for (i = 0; i < document.theForm.opmode.length; ++i)
  28.     {
  29.         if (document.theForm.opmode[i].checked)
  30.         {
  31.             return document.theForm.opmode[i].value;
  32.         }
  33.     }
  34.  
  35.     return null;
  36. }
  37.  
  38. // ----------------------------------------
  39. function setSelected(v)
  40. {
  41.     var i;
  42.     for (i = 0; i < document.theForm.opmode.length; ++i)
  43.     {
  44.         if (document.theForm.opmode[i].value == v)
  45.         {
  46.             document.theForm.opmode[i].checked = true;
  47.             document.theForm.opmode[i].focus();
  48.             return true;
  49.         }
  50.     }
  51.  
  52.     // just choose the first one, whatever it is.
  53.     document.theForm.opmode[0].checked = true;
  54.     document.theForm.opmode[0].focus();
  55.     return false;
  56. }
  57.  
  58. // ----------------------------------------
  59. function getExtension(url)
  60. {
  61.     var lastDot = url.lastIndexOf(".");
  62.     if (lastDot >= 1)
  63.         return url.slice(lastDot).toLowerCase();
  64.     else
  65.         return "";
  66. }
  67.  
  68. // ----------------------------------------
  69. function receiveArguments()
  70. {
  71.     var defVal = dw.getPreferenceString("General Preferences", "Insert Document Default", "flashpaper");
  72.  
  73.     g_file = arguments[0];
  74.     g_returnArray = arguments[1];
  75.     g_allowInsertContents = arguments[2];
  76.     g_rememberPrefs = arguments[3];
  77.  
  78.     // if it's not an Office doc, punt.
  79.     if (!dw.isOfficeDocument(g_file, false))
  80.     {
  81.         alert(dw.loadString("insert doc dialog/not office doc error"));
  82.          return "abort"; 
  83.     }
  84.  
  85.     // if the pref is currently "flashpaper", but that's not on the system, quietly change
  86.     // to something else.
  87.     if (defVal == "flashpaper" &&
  88.         (typeof(FlashPaperConnect) == "undefined" || FlashPaperConnect.isAvailable() != 0))
  89.     {
  90.         defVal = "content";
  91.     }
  92.  
  93.     var isConvertibleOfficeDoc = dw.isOfficeDocument(g_file, true);
  94.     var isTextOnlyMode = dw.getDocumentDOM().getCCSharedSetting_TextOnlyInNonTemplates() && 
  95.         !dw.getDocumentDOM().isTemplateInstance();
  96.  
  97.     if (isTextOnlyMode)
  98.     {
  99.         if (isConvertibleOfficeDoc)
  100.         {
  101.             defVal = "content";
  102.  
  103.             document.theForm.fpoptions.disabled = true;
  104.  
  105.             var i;
  106.             for (i = 0; i < document.theForm.opmode.length; ++i)
  107.             {
  108.                 // changing this to enable all the options for ETO except the insert flash option.
  109.                 if (document.theForm.opmode[i].value == "flashpaper")
  110.                 {
  111.                     document.theForm.opmode[i].disabled = true;
  112.                 }
  113.             }
  114.  
  115.         }
  116.         else
  117.         {
  118.             // doh. can't insert. punt.
  119.             alert(dw.loadString("page props/edit text only"));
  120.              return "abort"; 
  121.         }
  122.     }
  123.  
  124.     // if it's Office but not convertible, hide the "insert contents" option.
  125.     if (!isConvertibleOfficeDoc || !g_allowInsertContents)
  126.     {
  127.         findObject("ContentRow").outerHTML = "";
  128.     }
  129.     
  130.     setSelected(defVal);
  131.     onOptionChanged();
  132.  
  133.     if (g_rememberPrefs)
  134.     {
  135.         // if g_rememberPrefs is false, always show the dialog, regardless of this pref
  136.         var whatToDo = dw.getPreferenceString("General Preferences", "Drop Office Action", "prompt");
  137.         if (whatToDo != "prompt")
  138.         {
  139.             setSelected(whatToDo);
  140.             onOptionChanged();
  141.             document.theForm.remember.checked = true;
  142.             run();
  143.              return "abort"; 
  144.         }
  145.         else
  146.         {
  147.             document.theForm.remember.checked = false;
  148.         }
  149.     }
  150.     else
  151.     {
  152.         findObject("RememberCheckbox").outerHTML = "";
  153.     }
  154. }
  155.  
  156. // ----------------------------------------
  157. function commandButtons()
  158. {
  159.     return new Array( "PutButtonsOnBottom", 
  160.                       "OkButton",            MM.BTN_OK,        "if (checkValid()) { window.close(); run(); }",
  161.                       "CancelButton",        MM.BTN_Cancel,    "window.close();",
  162.                       "PutButtonOnLeft",    MM.BTN_Help,    "displayHelp();");
  163. }
  164.  
  165. // ----------------------------------------
  166. function initializeUI()
  167. {
  168. }
  169.  
  170. // ----------------------------------------
  171. function checkValid()
  172. {
  173.     /*const*/ var warnUserIfNotAvailable = true;
  174.     if (getSelected() == "flashpaper" && !isFlashPaperAvailable(warnUserIfNotAvailable))
  175.     {
  176.         return false;
  177.     }
  178.     return true;
  179. }
  180.  
  181. // ----------------------------------------
  182. function onFlashPaperLinkClicked()
  183. {
  184.     dwscripts.displayDWHelp(MM.HELP_aboutFlashPaper);
  185. }
  186.  
  187. // ----------------------------------------
  188. function onOptionChanged()
  189. {
  190.     if (getSelected() == "flashpaper")
  191.     {
  192.         document.theForm.fpoptions.disabled = false;
  193.     }
  194.     else
  195.     {
  196.         document.theForm.fpoptions.disabled = true;
  197.     }
  198. }
  199.  
  200. // ----------------------------------------
  201. function onFpOptions()
  202. {
  203.     var result = [ null ];
  204.     dw.runCommand("FlashPaperOptions.htm", g_file, result);
  205.     g_fpOptions = result[0];    // could be null! this is ok!
  206. }
  207.  
  208. // ----------------------------------------
  209. function run()
  210. {
  211.     var selected = getSelected();
  212.  
  213.     if (g_rememberPrefs)
  214.     {
  215.         dw.setPreferenceString("General Preferences", "Insert Document Default", selected);
  216.     }
  217.  
  218.     if (g_returnArray)
  219.         g_returnArray[0] = false;
  220.  
  221.     if (selected == "content")
  222.     {
  223.         var insertedAnything = insertOfficeDoc(g_file);
  224.         if (g_returnArray)
  225.             g_returnArray[0] = insertedAnything;
  226.     }
  227.     else if (selected == "flashpaper")
  228.     {
  229.  
  230.         var ok = true;
  231.         if (getExtension(g_file) == ".xls")
  232.         {
  233.             ok = dw.displayOptionalDialog("Excel FlashPaper Conversion Warning Dialog", 
  234.                                             dw.loadString("insert doc dialog/excel print warning"), 
  235.                                             true);
  236.         }
  237.  
  238.         if (ok)
  239.         {
  240.             // insertFlashPaper wants a localURL, not a pathname.
  241.             var fileURL = dw.doURLEncoding(MMNotes.filePathToLocalURL(g_file));
  242.             var result = insertFlashPaper(fileURL, g_fpOptions);
  243.             if (g_returnArray)
  244.                 g_returnArray[0] = result;
  245.         }
  246.         else
  247.         {
  248.             if (g_returnArray)
  249.                 g_returnArray[0] = true;    // pretend we converted.
  250.         }
  251.     }
  252.     else if (selected == "link")
  253.     {
  254.         var insertedURL = dw.insertLinkToDocument(g_file);
  255.         if (g_returnArray)
  256.             g_returnArray[0] = (insertedURL != null);
  257.     }
  258.  
  259.     if (g_rememberPrefs)
  260.     {
  261.         if (document.theForm.remember.checked)
  262.         {
  263.             dw.setPreferenceString("General Preferences", "Drop Office Action", selected);
  264.         }
  265.         else
  266.         {
  267.             dw.setPreferenceString("General Preferences", "Drop Office Action", "prompt");
  268.         }
  269.     }
  270. }
  271.