|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
-
- function OnWorkbookBeforePrint(doc) {
- return;
- }
-
-
-
- function OnWindowActivate() {
- console.log("OnWindowActivate" + "=======================");
-
- var l_doc = wps.EtApplication().ActiveWorkbook;
- SetCurrDocEnvProp(l_doc);
- showOATab();
- setTimeout(activeTab, 2000);
- return;
- }
-
-
- function CheckIfOADocSaveAs(doc) {
- if (!doc) {
- return;
- }
-
- var l_Path = GetDocParamsValue(doc, "SourcePath");
-
- return l_Path == doc.FullName;
- }
-
-
-
- function OnWorkbookBeforeSave(doc) {
- console.log("OnWorkbookBeforeSave");
-
-
- var l_IsOADocButtonSave = false;
- l_IsOADocButtonSave = wps.PluginStorage.getItem("OADocUserSave");
-
-
- if (pCheckCurrOADocCanSaveAs(doc) == false) {
-
-
- if (pIsOnlineOADoc(doc) == true) {
-
- if (l_IsOADocButtonSave == false) {
- alert("来自OA的不落地文档,禁止另存为本地文档!");
-
- wps.ApiEvent.Cancel = true;
- }
- } else {
-
- if (l_IsOADocButtonSave == false) {
- doc.Save();
-
- wps.ApiEvent.Cancel = true;
- } else {}
- }
-
- }
-
-
- showOATab();
- return;
- }
-
-
-
-
- function OnWorkbookBeforeClose(doc) {
- console.log('OnWorkbookBeforeClose');
-
- var l_fullName = doc.FullName;
- var l_bIsOADoc = false;
- l_bIsOADoc = CheckIfDocIsOADoc(doc);
- if (l_bIsOADoc == false) {
- return;
- }
-
- if (pISOADocReadOnly(doc) == false) {
- if (doc.Saved == false) {
- if (wps.confirm("系统文件有改动,是否提交后关闭?" + "\n" + "确认后请按上传按钮执行上传操作。取消则继续关闭文档。")) {
- wps.ApiEvent.Cancel = true;
- return;
- }
- }
- }
- doc.Close(false);
- closeEtIfNoDocument();
- wps.FileSystem.Remove(l_fullName);
- }
-
-
-
- function OnWorkbookAfterClose(doc) {
- console.log("OnWorkbookAfterClose");
-
- var l_NofityURL = GetDocParamsValue(doc, "notifyUrl");
- if (l_NofityURL) {
- l_NofityURL = l_NofityURL.replace("{?}", "3");
- console.log("" + l_NofityURL);
- NotifyToServer(l_NofityURL);
- }
-
- pRemoveDocParam(doc);
- pSetetAppUserName();
- }
-
-
- function OnWorkbookOpen(doc) {
-
-
-
-
-
-
- OnWindowActivate();
- ChangeOATabOnDocOpen();
- }
-
-
- function OnWorkbookNew(doc) {
-
-
-
-
-
- ChangeOATabOnDocOpen();
- wps.ribbonUI.Invalidate();
- }
-
-
-
- function pISOADocReadOnly(doc) {
- if (!doc) {
- return false;
- }
- var l_openType = GetDocParamsValue(doc, "openType");
- if (l_openType == "") {
- return false;
- }
- try {
- if (!!l_openType.protectType) {
- return true;
- }
- } catch (err) {
- return false;
- }
- }
-
-
-
- function SetCurrDocEnvProp(doc) {
- if (!doc) return;
- var l_bIsOADoc = false;
- l_bIsOADoc = pCheckIfOADoc(doc);
-
-
- if (l_bIsOADoc == true) {
- var l_userName = GetDocParamsValue(doc, "userName");
- if (l_userName != "") {
- wps.EtApplication().UserName = l_userName;
- return;
- }
- }
-
- wps.EtApplication().UserName = wps.PluginStorage.getItem("WPSInitUserName");
- }
-
-
- function pCheckCurrOADocCanSaveAs(doc) {
-
- if (CheckIfDocIsOADoc(doc) == false) return true;
-
-
- var l_CanSaveAs = GetDocParamsValue(doc, "CanSaveAs");
-
-
- if (typeof (l_CanSaveAs) == "boolean") {
- return l_CanSaveAs;
- }
- return false;
- }
-
-
- function pSetetAppUserName() {
-
- if (wps.EtApplication().Workbooks.Count == 1) {
- var l_strUserName = wps.PluginStorage.getItem("WPSInitUserName");
- wps.EtApplication().UserName = l_strUserName;
- }
- }
-
-
- function pRemoveDocParam(doc) {
- if (!doc) return;
- wps.PluginStorage.removeItem(doc.FullName);
- return;
- }
-
-
- function pSetNoneOADocFlag(doc) {
- if (!doc) return;
- var l_param = wps.PluginStorage.getItem(doc.FullName);
- var l_objParams = new Object();
- if (l_param) {
- l_objParams = JSON.parse(l_param);
- }
- l_objParams.isOA = EnumOAFlag.DocFromNoOA;
- wps.PluginStorage.setItem(doc.FullName, JSON.stringify(l_objParams));
- }
-
-
-
- function ChangeOATabOnDocOpen() {
- var l_ShowOATab = true;
- l_ShowOATab = wps.PluginStorage.getItem("ShowOATabDocActive");
-
- if (l_ShowOATab == true) {
- if (wps.ribbonUI)
- wps.ribbonUI.ActivateTab("WPSWorkExtTab");
- else
- wps.ActivateTab("WPSWorkExtTab");
- }
- }
|