1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-01-19 15:52:10 +01:00

Bookmark: Migrate setting into app fix #51

This commit is contained in:
Brice Maron 2012-10-31 21:31:43 +00:00
parent 859a67ae9a
commit d81c83e65c
10 changed files with 160 additions and 41 deletions

27
ajax/import.php Normal file
View File

@ -0,0 +1,27 @@
<?php
OCP\App::checkAppEnabled('bookmarks');
$l = new OC_l10n('bookmarks');
if (isset($_FILES['bm_import'])) {
$error = array();
$file = $_FILES['bm_import']['tmp_name'];
if($_FILES['bm_import']['type'] =='text/html') {
$error = OC_Bookmarks_Bookmarks::importFile($file);
if( empty($errors) ) {
OCP\JSON::success();
//force charset as not set by OC_JSON
header('Content-Type: application/json; charset=utf-8');
exit();
}
} else {
$error[]= $l->t('Unsupported file type for import');
}
}
OC_JSON::error(array('data'=>$error));
//force charset as not set by OC_JSON
header('Content-Type: application/json; charset=utf-8');
exit();

View File

@ -17,7 +17,6 @@ OCP\App::addNavigationEntry( array( 'id' => 'bookmarks_index',
'name' => $l->t('Bookmarks') 'name' => $l->t('Bookmarks')
)); ));
OCP\App::registerPersonal('bookmarks', 'settings');
OCP\Util::addscript('bookmarks', 'bookmarksearch'); OCP\Util::addscript('bookmarks', 'bookmarksearch');
OC_Search::registerProvider('OC_Search_Provider_Bookmarks'); OC_Search::registerProvider('OC_Search_Provider_Bookmarks');

View File

@ -333,4 +333,41 @@ li:hover em { display : none; }
position: absolute; position: absolute;
right: 1em; right: 1em;
top: auto; top: auto;
}
#bookmark_settings {
-moz-box-sizing: border-box;
background: none repeat scroll 0 0 #EEEEEE;
border-right: 1px solid #CCCCCC;
border-top: 1px solid #CCCCCC;
bottom: 0;
height: 2.8em;
margin: 0;
overflow: visible;
padding: 0;
position: fixed;
width: 20em;
z-index: 2;
}
#leftcontent #bookmark_settings li{
padding: 0;
background-color:transparent;
}
#leftcontent #bookmark_settings li:hover{
background-color:transparent;
}
#bookmark_settings .controls {
height: 100%;
width: 100%;
}
#bookmark_settings .controls > li:last-child button {
margin-right: 0.3em;
}
#bookmark_settings button {
height: 2.4em;
margin: 0.15em 0 0 0.15em;
padding: 0.2em 0.1em 0;
width: 2.4em;
} }

View File

@ -9,6 +9,14 @@ $(document).ready(function() {
$('.centercontent').click(clickSideBar); $('.centercontent').click(clickSideBar);
$('#view_type input').click(clickSwitchView); $('#view_type input').click(clickSwitchView);
$('#bookmark_add_submit').click(addBookmark); $('#bookmark_add_submit').click(addBookmark);
$('#settingsbtn').on('click keydown', function() {
try {
OC.appSettings({appid:'bookmarks', loadJS:true, cache:false});
} catch(e) {
alert(e);
}
});
$(window).resize(function () { $(window).resize(function () {
fillWindow($('.bookmarks_list')); fillWindow($('.bookmarks_list'));
}); });

57
js/settings.js Normal file
View File

@ -0,0 +1,57 @@
$(document).ready(function() {
$('#bm_import_submit').click(attachSettingEvent);
});
function attachSettingEvent(event) {
event.preventDefault();
fileUpload($(this).closest('form'), $('#upload'));
}
function fileUpload(form, result_div) {
var uploadEventHandler = function () {
var data = {};
try{
data = $.parseJSON(iframe.contents().text());
}catch (e){}
if(data.status == 'error') {
list = $("<ul></ul>").addClass('setting_error_list');
console.log(data);
$.each(data.data,function(index, item){
list.append($( "<li></li>" ).text(item));
});
result_div.html(list);
} else {
result_div.text(t('bookmark', 'Import completed successfully.'));
}
};
// Create the iframe...
var iframe;
if($('#upload_iframe').length === 1)
iframe = $('#upload_iframe')
else {
iframe = $('<iframe></iframe>').attr({
id: 'upload_iframe',
name: 'upload_iframe',
width: '0',
height: '0',
border: '0',
style: 'display:none'
}).bind('load',uploadEventHandler);
form.append(iframe);
}
// Set properties of form...
form.attr({
target: 'upload_iframe',
method: 'post',
enctype: 'multipart/form-data',
encoding: 'multipart/form-data'
});
// Submit the form...
form.submit();
result_div.text(t('bookmark', 'Uploading...'));
}

View File

@ -8,25 +8,5 @@
OCP\App::checkAppEnabled('bookmarks'); OCP\App::checkAppEnabled('bookmarks');
if (isset($_POST['bm_import'])) { $tmpl = new OCP\Template('bookmarks', 'settings');
$error = array(); $tmpl->printPage();
$file = $_FILES['bm_import']['tmp_name'];
if($_FILES['bm_import']['type'] =='text/html') {
$error = OC_Bookmarks_Bookmarks::importFile($file);
} else {
$error[]= array('error' => 'Unsupported file type for import',
'hint' => '');
}
$tmpl = new OCP\Template('bookmarks', 'settings');
// Any problems?
if(count($error)) {
$tmpl->assign('error', $error);
}
return $tmpl->fetchPage();
} else {
$tmpl = new OCP\Template( 'bookmarks', 'settings');
return $tmpl->fetchPage();
}

View File

@ -1,6 +1,6 @@
<form class="addBm" method="post" action="<?php echo OCP\Util::linkTo('bookmarks', 'ajax/editBookmark.php');?>"> <form class="addBm" method="post" action="<?php echo OCP\Util::linkTo('bookmarks', 'ajax/editBookmark.php');?>">
<?php if(!isset($embedded) || !$embedded):?> <?php if(!isset($embedded) || !$embedded):?>
<script> <script type="text/javascript">
var fullTags = <?php echo $_['tags'];?>; var fullTags = <?php echo $_['tags'];?>;
$(document).ready(function() { $(document).ready(function() {
$('body').bookmark_dialog({ $('body').bookmark_dialog({

View File

@ -2,7 +2,7 @@
function createBookmarklet() { function createBookmarklet() {
$l = OC_L10N::get('bookmarks'); $l = OC_L10N::get('bookmarks');
echo '<small>' . $l->t('Drag this to your browser bookmarks and click it, when you want to bookmark a webpage quickly:') . '</small>' echo '<small>' . $l->t('Drag this to your browser bookmarks and click it, when you want to bookmark a webpage quickly:') . '</small><br />'
. '<a class="button bookmarklet" href="javascript:(function(){var a=window,b=document,c=encodeURIComponent,e=document.title,d=a.open(\'' . OCP\Util::linkToAbsolute('bookmarks', 'addBm.php') . '?output=popup&url=\'+c(b.location)+\'&title=\'+e,\'bkmk_popup\',\'left=\'+((a.screenX||a.screenLeft)+10)+\',top=\'+((a.screenY||a.screenTop)+10)+\',height=400px,width=550px,resizable=1,alwaysRaised=1\');a.setTimeout(function(){d.focus()},300);})();">' . '<a class="button bookmarklet" href="javascript:(function(){var a=window,b=document,c=encodeURIComponent,e=document.title,d=a.open(\'' . OCP\Util::linkToAbsolute('bookmarks', 'addBm.php') . '?output=popup&url=\'+c(b.location)+\'&title=\'+e,\'bkmk_popup\',\'left=\'+((a.screenX||a.screenLeft)+10)+\',top=\'+((a.screenY||a.screenTop)+10)+\',height=400px,width=550px,resizable=1,alwaysRaised=1\');a.setTimeout(function(){d.focus()},300);})();">'
. $l->t('Read later') . '</a>'; . $l->t('Read later') . '</a>';
} }

View File

@ -31,6 +31,17 @@
<ul class="tag_list"> <ul class="tag_list">
</ul> </ul>
<div id="bookmark_settings">
<ul class="controls">
<li style="float: right">
<button id="settingsbtn" title="<?php echo $l->t('Settings'); ?>">
<img class="svg" src="<?php echo OCP\Util::imagePath('core','actions/settings.png'); ?>"
alt="<?php echo $l->t('Settings'); ?>" /></button>
</li>
</ul>
</div>
</div> </div>
<div id="rightcontent" class="rightcontent"> <div id="rightcontent" class="rightcontent">
<div class="bookmarks_list"></div> <div class="bookmarks_list"></div>
@ -41,6 +52,7 @@
require_once OC_App::getAppPath('bookmarks') .'/templates/bookmarklet.php' ; require_once OC_App::getAppPath('bookmarks') .'/templates/bookmarklet.php' ;
createBookmarklet(); createBookmarklet();
?> ?>
<div id="appsettings" class="popup bottomleft hidden"></div>
</div> </div>
<script> <script>
var fullTags = <?php echo $_['tags'];?>; var fullTags = <?php echo $_['tags'];?>;

View File

@ -6,29 +6,28 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
?> ?>
<form id="bookmarks">
<fieldset class="personalblock">
<span class="bold"><?php echo $l->t('Bookmarklet <br />');?></span>
<?php
require_once 'bookmarklet.php';
createBookmarklet();
?>
</fieldset>
</form>
<form id="import_bookmark" action="#" method="post" enctype="multipart/form-data"> <fieldset class="personalblock">
<legend><strong><?php echo $l->t('Bookmarklet <br />');?></strong></legend>
<?php
require_once 'bookmarklet.php';
createBookmarklet();
?>
</fieldset>
<form id="import_bookmark" action="<?php echo OCP\Util::linkTo( "bookmarks", "ajax/import.php" );?>" method="post" enctype="multipart/form-data">
<fieldset class="personalblock"> <fieldset class="personalblock">
<?php if(isset($_['error'])): ?> <?php if(isset($_['error'])): ?>
<h3><?php echo $_['error']['error']; ?></h3> <h3><?php echo $_['error']['error']; ?></h3>
<p><?php echo $_['error']['hint']; ?></p> <p><?php echo $_['error']['hint']; ?></p>
<?php endif; ?> <?php endif; ?>
<legend><strong><?php echo $l->t('Import bookmarks');?></strong></legend> <legend><strong><?php echo $l->t('Import bookmarks');?></strong></legend>
<p><input type="file" id="bm_import" name="bm_import" style="width:280px;"> <p><input type="file" id="bm_import" name="bm_import" style="width:280px;">
<label for="bm_import"> <?php echo $l->t('Bookmark html file');?></label> <label for="bm_import"> <?php echo $l->t('html bookmarks file');?></label>
</p> </p>
<input type="submit" name="bm_import" value="<?php echo $l->t('Import'); ?>" /> <input type="button" name="bm_import_btn" id="bm_import_submit" value="<?php echo $l->t('Import'); ?>" />
<div id="upload"></div>
<legend><strong><?php echo $l->t('Export bookmarks');?></strong></legend> <legend><strong><?php echo $l->t('Export bookmarks');?></strong></legend>
<p><a href="<?php echo OCP\Util::linkTo('bookmarks', 'export.php') ;?>" <p><a href="<?php echo OCP\Util::linkTo('bookmarks', 'export.php') ;?>"