Skip to content

Commit

Permalink
Add drag & drop installation
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Mar 26, 2017
1 parent 3f899cd commit b07c967
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
23 changes: 23 additions & 0 deletions administrator/components/com_installer/controllers/install.php
Expand Up @@ -66,4 +66,27 @@ public function install()

$this->setRedirect($redirect_url);
}

/**
* Install an extension from drag & drop ajax upload.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function ajax_upload()
{
$this->install();

$app = JFactory::getApplication();
$redirect = $this->redirect;

header('Content-Type: application/json');

echo new JResponseJson(array(
'redirect' => $redirect,
), $app->getUserState('com_installer.message'));

exit();
}
}
Expand Up @@ -67,6 +67,100 @@
'
);

$token = JSession::getFormToken();

// Drag-drop installation
JFactory::getDocument()->addScriptDeclaration(
<<<JS
jQuery(document).ready(function($) {
var body = $('body');
var cover = $('#dragarea');
var form = document.getElementById("adminForm");
body.on('dragenter', function(e) {
e.stopPropagation();
cover.fadeIn();
return false;
});
// Notify user when file is over the drop area
body.on('dragover', function(e) {
e.preventDefault();
cover.fadeIn();
return false;
});
body.on('drop', function(event) {
event.preventDefault();
cover.fadeOut();
var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
if (!files.length) {
return;
}
var file = files[0];
var data = new FormData();
data.append('install_package', file);
data.append('installtype', 'upload');
data.append('{$token}', 1);
jQuery("#loading").css("display", "block");
$.ajax({
url: 'index.php?option=com_installer&task=install.ajax_upload',
data: data,
type: 'post',
processData: false,
cache: false,
contentType: false
}).done(function (res) {
console.log(res.redirect);
if (res.success) {
if (res.data.redirect) {
location.href = res.data.redirect;
} else {
location.href = 'index.php?option=com_installer&view=install';
}
}
});
});
});
JS
);

JFactory::getDocument()->addStyleDeclaration(
<<<CSS
#dragarea {
display: block;
background: rgba(255, 255, 255, .8);
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0.8;
-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity = 80);
filter: alpha(opacity = 80);
overflow: hidden;
}
#dragarea .dragarea-title {
width: 100%;
display: block;
font-size: 36px;
text-align: center;
position: absolute;
top: 50%;
}
CSS
);

?>

<script type="text/javascript">
Expand Down Expand Up @@ -149,3 +243,6 @@
</form>
</div>
<div id="loading"></div>
<div id="dragarea" style="display: none;">
<div class="dragarea-title"><?php echo JText::_('COM_INSTALLER_DRAG_FILE_HERE'); ?></div>
</div>
1 change: 1 addition & 0 deletions administrator/language/en-GB/en-GB.com_installer.ini
Expand Up @@ -12,6 +12,7 @@ COM_INSTALLER_CONFIRM_UNINSTALL="Are you sure you want to uninstall? Confirming
COM_INSTALLER_CURRENT_VERSION="Installed"
COM_INSTALLER_DISCOVER_FILTER_SEARCH_DESC="Search in discovered extension name. Prefix with ID: to search for an extension ID."
COM_INSTALLER_DISCOVER_FILTER_SEARCH_LABEL="Search Discovered Extensions"
COM_INSTALLER_DRAG_FILE_HERE="Drag file here to upload."
COM_INSTALLER_ENABLED_UPDATES_1=", 1 disabled site was enabled."
COM_INSTALLER_ENABLED_UPDATES_MORE=", %s disabled sites were enabled."
COM_INSTALLER_ERROR_DISABLE_DEFAULT_TEMPLATE_NOT_PERMITTED="Disable default template is not permitted."
Expand Down

0 comments on commit b07c967

Please sign in to comment.