Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Upload to SharinPix using URL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README modified - added backticks and markdown syntax instead of html tags

useful link - https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet


# [Flow](https://github.com/sharinpix/demo-apex/tree/flow)
Deploy this branch to your Salesforce organization and open the `SharinPixImageFromUrlsDemo` Visualforce page.
At the top of the page, insert the Album ID in which you wish to upload.

[<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=flow)
Fill in the fields.
* filename - the filename that will be used to store this file.
* URL - the URL of the image file.

# Work Order token
You may add more URLs by clicking on the `Add URL` button.
Once done, click on `Upload`.

[<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=work_order_token)
**Note:** Each URL is sent individually to the Apex controller for upload. (Multiple requests)

[<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=upload_by_url)
10 changes: 10 additions & 0 deletions src/classes/SharinPixImageFromUrlsDemo.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public with sharing class SharinPixImageFromUrlsDemo {

@RemoteAction
public static Boolean uploadByUrls(String albumId, String url, String filename) {
sharinpix.Utils utils = new sharinpix.Utils();
utils.uploadFromUrl(url, albumId, filename);
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return true always ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add status messages or return void

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces

}
10 changes: 10 additions & 0 deletions src/classes/SharinPixImageFromUrlsDemo.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>40.0</apiVersion>
<packageVersions>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove packageVersions tag from meta.xmls

<majorNumber>1</majorNumber>
<minorNumber>33</minorNumber>
<namespace>sharinpix</namespace>
</packageVersions>
<status>Active</status>
</ApexClass>
10 changes: 9 additions & 1 deletion src/package.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<version>36.0</version>
<types>
<members>SharinPixImageFromUrlsDemo</members>
<name>ApexPage</name>
</types>
<types>
<members>SharinPixImageFromUrlsDemo</members>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suffix: Controller / Ctrl

<name>ApexClass</name>
</types>
<version>40.0</version>
</Package>
123 changes: 123 additions & 0 deletions src/pages/SharinPixImageFromUrlsDemo.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<apex:page controller="SharinPixImageFromUrlsDemo">
<script>
function generateUrlInput(index) {
return '<div class="padding-top slds-form-element"><label class="slds-form-element__label">'+
'URL number ' + (index+1) + '</label><div class="slds-grid slds-wrap slds-grid_pull-padded">'+
'<div class="slds-p-horizontal_small slds-size_1-of-1 slds-medium-size_1-of-1 slds-large-siz'+
'e_4-of-12"><div class="slds-form-element__control"><input type="text" id="input-filename-' + index +
'" class="slds-input" placeholder="Filename" /></div></div><div class="slds-p-horizontal_small'+
' slds-size_1-of-1 slds-medium-size_1-of-1 slds-large-size_8-of-12"><div class="slds-form-element_'+
'_control"><input type="text" id="input-url-' + (index) + '" class="slds-input" placeholder='+
'"URL" /></div></div></div></div>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use concatenation and indentation in string

}
</script>
<style>
#main {
padding: 10px 20px;
}
#main-form {
max-width: 800px;
}
.margined-top {
margin-top: .5em !important;
}
.padding-top {
padding-top: .5em !important;
}
.divider-top {
border-top: 1px solid rgba(0, 0, 0, .3);
}
#success-div {
display: none;
position: fixed;
top: 0;
right: 0;
}
</style>
<div class="slds-scope" id="main">
<div class="slds-grid">
<div class="slds-col">
<div id="success-div" style="height: 4rem;">
<div class="slds-notify_container slds-is-relative">
<div class="slds-notify slds-notify_toast slds-theme_success" role="alert">
<div class="slds-notify__content">
<h2 class="slds-text-heading_small ">Your images was send for upload.</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were sent

</div>
</div>
</div>
</div>
</div>
</div>
<div class="slds-grid">
<div class="slds-col">
<div id="main-form" class="slds-form slds-form_stacked">
<div class="slds-form-element">
<label class="slds-form-element__label" for="input-unique-id">Album ID</label>
<div class="slds-form-element__control">
<input type="text" id="input-album-id" class="slds-input" />
</div>
</div>
<div class="margined-top" id="urls">
<script>document.write(generateUrlInput(0))</script>
</div>
<div class="margined-top slds-form-element">
<button type="button" onclick="uploadAll()" class="margined-top slds-button slds-button_brand">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try using slds padding/margin classes https://www.lightningdesignsystem.com/utilities/padding/

Upload
</button>
<button type="button" onclick="addUrl()" class="margined-top slds-button slds-button_neutral">
Add URL
</button>
</div>
</div>
</div>
</div>
</div>
<script>
var isEmpty = function(string) {
return string === '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if null or undefined or ''

};
var addUrl = function() {
var $urls = document.getElementById('urls');
if ($urls.childElementCount <= 10) {
var values = [];
for (var index = 1; index < $urls.childElementCount; index++) {
var filename = document.getElementById('input-filename-' + (index-1)).value;
var url = document.getElementById('input-url-' + (index-1)).value;
values.push({filename: filename, url: url});
}
var urlInputHtml = generateUrlInput($urls.childElementCount - 1);
$urls.innerHTML += urlInputHtml;
for (var index = 1; index < $urls.childElementCount - 1; index++) {
document.getElementById('input-filename-' + (index-1)).value = values[index-1].filename;
document.getElementById('input-url-' + (index-1)).value = values[index-1].url;
}
}
};
var uploadAll = function() {
var $urls = document.getElementById('urls');
for (var index = 1; index < $urls.childElementCount; index++) {
var albumId = document.getElementById('input-album-id').value;
var filename = document.getElementById('input-filename-' + (index-1)).value;
var url = document.getElementById('input-url-' + (index-1)).value;
if (!albumId || !url || !filename || isEmpty(albumId) || isEmpty(url) || isEmpty(filename)) {
alert('Fill all fields appropriately.');
return;
}
Visualforce.remoting.Manager.invokeAction(
'{! $RemoteAction.SharinPixImageFromUrlsDemo.uploadByUrls }',
albumId, url, filename,
function(res) {
if (res) {
$alert = document.getElementById('success-div');
$alert.style.display = 'block';
setTimeout(function() {
$alert.style.display = 'none';
}, 4000)
}
}
)
}
}
</script>
<apex:slds />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to move to top

</apex:page>
22 changes: 22 additions & 0 deletions src/pages/SharinPixImageFromUrlsDemo.page-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>40.0</apiVersion>
<availableInTouch>false</availableInTouch>
<confirmationTokenRequired>false</confirmationTokenRequired>
<label>SharinPixImageFromUrlsDemo</label>
<packageVersions>
<majorNumber>1</majorNumber>
<minorNumber>7</minorNumber>
<namespace>sf_com_apps</namespace>
</packageVersions>
<packageVersions>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove meta package (sharinpix + tfa)

<majorNumber>1</majorNumber>
<minorNumber>33</minorNumber>
<namespace>sharinpix</namespace>
</packageVersions>
<packageVersions>
<majorNumber>2</majorNumber>
<minorNumber>1</minorNumber>
<namespace>tfa</namespace>
</packageVersions>
</ApexPage>