Browse Source

Cleaned JS export code

tags/v2.0.4
Christoph Haas 3 years ago
parent
commit
16f33037b7
4 changed files with 291 additions and 140 deletions
  1. +64
    -43
      .idea/workspace.xml
  2. +225
    -0
      js/data/Actions.js
  3. +1
    -49
      js/plugin.contactimporter.js
  4. +1
    -48
      js/ui/ContextMenu.js

+ 64
- 43
.idea/workspace.xml View File

@@ -2,10 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="aae153d8-808f-4371-b0e9-9ee7ff904cab" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/dictionaries/osboxes.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/php/helper.php" afterPath="$PROJECT_DIR$/php/helper.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/php/module.contact.php" afterPath="$PROJECT_DIR$/php/module.contact.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/php/plugin.contactimporter.php" afterPath="$PROJECT_DIR$/php/plugin.contactimporter.php" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/js/data/Actions.js" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/js/plugin.contactimporter.js" afterPath="$PROJECT_DIR$/js/plugin.contactimporter.js" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/js/ui/ContextMenu.js" afterPath="$PROJECT_DIR$/js/ui/ContextMenu.js" />
</list>
<ignored path="contactimporter.iws" />
<ignored path=".idea/workspace.xml" />
@@ -26,36 +25,44 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="module.contact.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/php/module.contact.php">
<file leaf-file-name="ContextMenu.js" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/js/ui/ContextMenu.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="670">
<caret line="784" column="47" selection-start-line="784" selection-start-column="47" selection-end-line="784" selection-end-column="47" />
<folding>
<element signature="e#7#920#0#PHP" expanded="true" />
<element signature="e#1010#1043#0#PHP" expanded="true" />
</folding>
<state relative-caret-position="1644">
<caret line="111" column="5" selection-start-line="111" selection-start-column="5" selection-end-line="111" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="plugin.contactimporter.js" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/js/plugin.contactimporter.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1245">
<caret line="83" column="9" selection-start-line="83" selection-start-column="9" selection-end-line="83" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="plugin.contactimporter.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/php/plugin.contactimporter.php">
<file leaf-file-name="Actions.js" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/js/data/Actions.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="420">
<caret line="28" column="31" selection-start-line="28" selection-start-column="31" selection-end-line="28" selection-end-column="31" />
<state relative-caret-position="1030">
<caret line="223" column="5" selection-start-line="111" selection-start-column="0" selection-end-line="223" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="helper.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/php/helper.php">
<file leaf-file-name="module.contact.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/php/module.contact.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="1" column="0" selection-start-line="1" selection-start-column="0" selection-end-line="1" selection-end-column="0" />
<state relative-caret-position="279">
<caret line="434" column="71" selection-start-line="434" selection-start-column="71" selection-end-line="434" selection-end-column="105" />
<folding>
<element signature="e#7#912#0#PHP" expanded="true" />
<element signature="e#7#920#0#PHP" expanded="true" />
<element signature="e#1010#1043#0#PHP" expanded="true" />
</folding>
</state>
</provider>
@@ -75,8 +82,6 @@
<option value="$PROJECT_DIR$/js/dialogs/ImportPanel.js" />
<option value="$PROJECT_DIR$/js/data/ResponseHandler.js" />
<option value="$PROJECT_DIR$/build.xml" />
<option value="$PROJECT_DIR$/js/ui/ContextMenu.js" />
<option value="$PROJECT_DIR$/js/plugin.contactimporter.js" />
<option value="$PROJECT_DIR$/changelog.txt" />
<option value="$PROJECT_DIR$/manifest.xml" />
<option value="$PROJECT_DIR$/php/download.php" />
@@ -84,6 +89,9 @@
<option value="$PROJECT_DIR$/php/helper.php" />
<option value="$PROJECT_DIR$/php/plugin.contactimporter.php" />
<option value="$PROJECT_DIR$/php/module.contact.php" />
<option value="$PROJECT_DIR$/js/data/Actions.js" />
<option value="$PROJECT_DIR$/js/plugin.contactimporter.js" />
<option value="$PROJECT_DIR$/js/ui/ContextMenu.js" />
</list>
</option>
</component>
@@ -253,6 +261,11 @@
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="js-jscs-nodeInterpreter" value="/usr/bin/node" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/js/data" />
</key>
</component>
<component name="RunManager">
<configuration default="true" type="JavascriptDebugType" factoryName="JavaScript Debug">
<method />
@@ -314,12 +327,12 @@
<workItem from="1480428199144" duration="44000" />
<workItem from="1480428259775" duration="69000" />
<workItem from="1480428330068" duration="6691000" />
<workItem from="1480504955898" duration="1406000" />
<workItem from="1480504955898" duration="2034000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="8210000" />
<option name="totallyTimeSpent" value="8838000" />
</component>
<component name="ToolWindowManager">
<frame x="65" y="24" width="1792" height="999" extended-state="6" />
@@ -491,14 +504,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/ui/ContextMenu.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1515">
<caret line="101" column="8" selection-start-line="101" selection-start-column="8" selection-end-line="104" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/manifest.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60">
@@ -518,14 +523,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/plugin.contactimporter.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1200">
<caret line="80" column="0" selection-start-line="80" selection-start-column="0" selection-end-line="80" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/ABOUT.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="375">
@@ -591,8 +588,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/php/module.contact.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="670">
<caret line="784" column="47" selection-start-line="784" selection-start-column="47" selection-end-line="784" selection-end-column="47" />
<state relative-caret-position="279">
<caret line="434" column="71" selection-start-line="434" selection-start-column="71" selection-end-line="434" selection-end-column="105" />
<folding>
<element signature="e#7#920#0#PHP" expanded="true" />
<element signature="e#1010#1043#0#PHP" expanded="true" />
@@ -600,6 +597,30 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/data/Actions.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1030">
<caret line="223" column="5" selection-start-line="111" selection-start-column="0" selection-end-line="223" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/plugin.contactimporter.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1245">
<caret line="83" column="9" selection-start-line="83" selection-start-column="9" selection-end-line="83" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/ui/ContextMenu.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1644">
<caret line="111" column="5" selection-start-line="111" selection-start-column="5" selection-end-line="111" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>


+ 225
- 0
js/data/Actions.js View File

@@ -0,0 +1,225 @@
/**
* Actions.js, Kopano Webapp contact to vcf im/exporter
*
* Author: Christoph Haas <christoph.h@sprinternet.at>
* Copyright (C) 2012-2016 Christoph Haas
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

Ext.namespace('Zarafa.plugins.contactimporter.data');

/**
* @class Zarafa.plugins.contactimporter.data.Actions
* Common actions which can be used within {@link Ext.Button buttons}
* or other {@link Ext.Component components} with action handlers.
* @singleton
*/
Zarafa.plugins.contactimporter.data.Actions = {
/**
* Generates a request to download the selected records as vCard.
*
* @param storeId
* @param recordIds
*/
exportToVCF: function (storeId, recordIds, recordFolder) {
if ((typeof recordIds != "undefined" && recordIds.length < 1) || (typeof recordFolder != "undefined" && recordFolder.get('content_count') < 1)) {
Zarafa.common.dialogs.MessageBox.show({
title: dgettext('plugin_contactimporter', 'Error'),
msg: dgettext('plugin_contactimporter', 'No contacts found. Export skipped!'),
icon: Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
} else {

var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
successCallback: Zarafa.plugins.contactimporter.data.Actions.downloadVCF
});

var recordcount = 0;
var exportPayload = {
storeid: storeId,
records: undefined,
folder: undefined
};

if (typeof recordIds != "undefined") {
exportPayload.records = recordIds;
recordcount = recordIds.length;
}

if (typeof recordFolder != "undefined") {
exportPayload.folder = recordFolder.get("entryid");
recordcount = recordFolder.get('content_count');
}

// Notify user
// # TRANSLATORS: {0} will be replaced by the number of contacts that will be exported
container.getNotifier().notify('info', dgettext('plugin_contactimporter', 'Contact Export'), String.format(dgettext('plugin_contactimporter', 'Exporting {0} contacts. Please wait...'), recordcount));


// request attachment preperation
container.getRequest().singleRequest(
'contactmodule',
'export',
exportPayload,
responseHandler
);
}
},

/**
* Callback for the export request.
* @param {Object} response
*/
downloadVCF: function (response) {
if (response.status == false) {
Zarafa.common.dialogs.MessageBox.show({
title: dgettext('plugin_contactimporter', 'Warning'),
msg: response.message,
icon: Zarafa.common.dialogs.MessageBox.WARNING,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
} else {
var downloadFrame = Ext.getBody().createChild({
tag: 'iframe',
cls: 'x-hidden'
});

var url = document.URL;
var link = url.substring(0, url.lastIndexOf('/') + 1);

link += "index.php?sessionid=" + container.getUser().getSessionId() + "&load=custom&name=download_vcf";
link = Ext.urlAppend(link, "token=" + encodeURIComponent(response.download_token));
link = Ext.urlAppend(link, "filename=" + encodeURIComponent(response.filename));

downloadFrame.dom.contentWindow.location = link;
}
},

/**
* Get all calendar folders.
* @param {boolean} asDropdownStore If true, a simple array store will be returned.
* @returns {*}
*/
getAllCalendarFolders: function (asDropdownStore) {
asDropdownStore = Ext.isEmpty(asDropdownStore) ? false : asDropdownStore;

var allFolders = [];

var inbox = container.getHierarchyStore().getDefaultStore();
var pub = container.getHierarchyStore().getPublicStore();

if (!Ext.isEmpty(inbox.subStores) && inbox.subStores.folders.totalLength > 0) {
for (var i = 0; i < inbox.subStores.folders.totalLength; i++) {
var folder = inbox.subStores.folders.getAt(i);
if (!Ext.isEmpty(folder) && folder.get("container_class") == "IPF.Appointment") {
if (asDropdownStore) {
allFolders.push([
folder.get("entryid"),
folder.get("display_name")
]);
} else {
allFolders.push({
display_name: folder.get("display_name"),
entryid: folder.get("entryid"),
store_entryid: folder.get("store_entryid"),
is_public: false
});
}
}
}
}

if (!Ext.isEmpty(pub.subStores) && pub.subStores.folders.totalLength > 0) {
for (var j = 0; j < pub.subStores.folders.totalLength; j++) {
var folder = pub.subStores.folders.getAt(j);
if (!Ext.isEmpty(folder) && folder.get("container_class") == "IPF.Appointment") {
if (asDropdownStore) {
allFolders.push([
folder.get("entryid"),
folder.get("display_name") + " (Public)"
]);
} else {
allFolders.push({
display_name: folder.get("display_name"),
entryid: folder.get("entryid"),
store_entryid: folder.get("store_entryid"),
is_public: true
});
}
}
}
}

if (asDropdownStore) {
return allFolders.sort(Zarafa.plugins.contactimporter.data.Actions.dynamicSort(1));
} else {
return allFolders;
}
},

/**
* Return a calendar folder element by name.
* @param {string} name
* @returns {*}
*/
getCalendarFolderByName: function (name) {
var folders = Zarafa.plugins.contactimporter.data.Actions.getAllCalendarFolders(false);

for (var i = 0; i < folders.length; i++) {
if (folders[i].display_name == name) {
return folders[i];
}
}

return container.getHierarchyStore().getDefaultFolder('calendar');
},

/**
* Return a calendar folder element by entryid.
* @param {string} entryid
* @returns {*}
*/
getCalendarFolderByEntryid: function (entryid) {
var folders = Zarafa.plugins.contactimporter.data.Actions.getAllCalendarFolders(false);

for (var i = 0; i < folders.length; i++) {
if (folders[i].entryid == entryid) {
return folders[i];
}
}

return container.getHierarchyStore().getDefaultFolder('calendar');
},

/**
* Dynamic sort function, sorts by property name.
* @param {string|int} property
* @returns {Function}
*/
dynamicSort: function (property) {
var sortOrder = 1;
if (property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a, b) {
var result = (a[property].toLowerCase() < b[property].toLowerCase()) ? -1 : (a[property].toLowerCase() > b[property].toLowerCase()) ? 1 : 0;
return result * sortOrder;
}
}
};

+ 1
- 49
js/plugin.contactimporter.js View File

@@ -83,55 +83,7 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
recordIds.push(btn.records[i].get("entryid"));
}
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
successCallback: this.downloadVCF,
scope: this
});
// Notify user
// # TRANSLATORS: {0} will be replaced by the number of contacts that will be exported
container.getNotifier().notify('info', dgettext('plugin_contactimporter', 'Contact Export'), String.format(dgettext('plugin_contactimporter', 'Exporting {0} contacts. Please wait...'), recordIds.length));
// request attachment preperation
container.getRequest().singleRequest(
'contactmodule',
'export',
{
storeid: btn.records[0].get("store_entryid"),
records: recordIds
},
responseHandler
);
},
/**
* Callback for the export request.
* @param {Object} response
*/
downloadVCF: function (response) {
if (response.status == false) {
Zarafa.common.dialogs.MessageBox.show({
title: dgettext('plugin_contactimporter', 'Warning'),
msg: response.message,
icon: Zarafa.common.dialogs.MessageBox.WARNING,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
} else {
var downloadFrame = Ext.getBody().createChild({
tag: 'iframe',
cls: 'x-hidden'
});
var url = document.URL;
var link = url.substring(0, url.lastIndexOf('/') + 1);
link += "index.php?sessionid=" + container.getUser().getSessionId() + "&load=custom&name=download_vcf";
link = Ext.urlAppend(link, "token=" + encodeURIComponent(response.download_token));
link = Ext.urlAppend(link, "filename=" + encodeURIComponent(response.filename));
downloadFrame.dom.contentWindow.location = link;
}
Zarafa.plugins.contactimporter.data.Actions.exportToVCF(btn.records[0].get("store_entryid"), recordIds, undefined);
},
/**


+ 1
- 48
js/ui/ContextMenu.js View File

@@ -94,25 +94,7 @@ Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.C
* @private
*/
onContextItemExport: function () {
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
successCallback: this.downloadVCF,
scope: this
});

// Notify user
// # TRANSLATORS: {0} will be replaced by the number of contacts that will be exported
container.getNotifier().notify('info', dgettext('plugin_contactimporter', 'Contact Export'), String.format(dgettext('plugin_contactimporter', 'Exporting {0} contacts. Please wait...'), this.records.get('content_count')));

// request attachment preperation
container.getRequest().singleRequest(
'contactmodule',
'export',
{
storeid: this.records.get("store_entryid"),
folder: this.records.get("entryid")
},
responseHandler
);
Zarafa.plugins.contactimporter.data.Actions.exportToVCF(this.records.get("store_entryid"), undefined, this.records);
},

/**
@@ -127,35 +109,6 @@ Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.C
};

Zarafa.core.data.UIFactory.openLayerComponent(componentType, undefined, config);
},

/**
* Callback for the export request.
* @param {Object} response
*/
downloadVCF: function (response) {
if (response.status == false) {
Zarafa.common.dialogs.MessageBox.show({
title: dgettext('plugin_contactimporter', 'Warning'),
msg: response.message,
icon: Zarafa.common.dialogs.MessageBox.WARNING,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
} else {
var downloadFrame = Ext.getBody().createChild({
tag: 'iframe',
cls: 'x-hidden'
});

var url = document.URL;
var link = url.substring(0, url.lastIndexOf('/') + 1);

link += "index.php?sessionid=" + container.getUser().getSessionId() + "&load=custom&name=download_vcf";
link = Ext.urlAppend(link, "token=" + encodeURIComponent(response.download_token));
link = Ext.urlAppend(link, "filename=" + encodeURIComponent(response.filename));

downloadFrame.dom.contentWindow.location = link;
}
}
});



Loading…
Cancel
Save