From d81c83e65c3533407a4358fcda88fe815855d26a Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Wed, 31 Oct 2012 21:31:43 +0000 Subject: [PATCH] Bookmark: Migrate setting into app fix #51 --- ajax/import.php | 27 +++++++++++++++++++ appinfo/app.php | 1 - css/bookmarks.css | 37 +++++++++++++++++++++++++ js/bookmarks.js | 8 ++++++ js/settings.js | 57 +++++++++++++++++++++++++++++++++++++++ settings.php | 24 ++--------------- templates/addBm.php | 2 +- templates/bookmarklet.php | 2 +- templates/list.php | 12 +++++++++ templates/settings.php | 31 +++++++++++---------- 10 files changed, 160 insertions(+), 41 deletions(-) create mode 100644 ajax/import.php create mode 100644 js/settings.js diff --git a/ajax/import.php b/ajax/import.php new file mode 100644 index 00000000..6264bc78 --- /dev/null +++ b/ajax/import.php @@ -0,0 +1,27 @@ +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(); diff --git a/appinfo/app.php b/appinfo/app.php index 1b4e1ddf..84013d9d 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -17,7 +17,6 @@ OCP\App::addNavigationEntry( array( 'id' => 'bookmarks_index', 'name' => $l->t('Bookmarks') )); -OCP\App::registerPersonal('bookmarks', 'settings'); OCP\Util::addscript('bookmarks', 'bookmarksearch'); OC_Search::registerProvider('OC_Search_Provider_Bookmarks'); diff --git a/css/bookmarks.css b/css/bookmarks.css index 7fe274ae..3062ad9c 100644 --- a/css/bookmarks.css +++ b/css/bookmarks.css @@ -333,4 +333,41 @@ li:hover em { display : none; } position: absolute; right: 1em; 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; } \ No newline at end of file diff --git a/js/bookmarks.js b/js/bookmarks.js index dba3cd25..0b5f4f08 100644 --- a/js/bookmarks.js +++ b/js/bookmarks.js @@ -9,6 +9,14 @@ $(document).ready(function() { $('.centercontent').click(clickSideBar); $('#view_type input').click(clickSwitchView); $('#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 () { fillWindow($('.bookmarks_list')); }); diff --git a/js/settings.js b/js/settings.js new file mode 100644 index 00000000..f005337d --- /dev/null +++ b/js/settings.js @@ -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 = $("").addClass('setting_error_list'); + console.log(data); + $.each(data.data,function(index, item){ + list.append($( "
  • " ).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 = $('').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...')); +} \ No newline at end of file diff --git a/settings.php b/settings.php index 626bbc9e..dae1d581 100644 --- a/settings.php +++ b/settings.php @@ -8,25 +8,5 @@ OCP\App::checkAppEnabled('bookmarks'); -if (isset($_POST['bm_import'])) { - $error = array(); - - $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(); -} +$tmpl = new OCP\Template('bookmarks', 'settings'); +$tmpl->printPage(); diff --git a/templates/addBm.php b/templates/addBm.php index 171b81c8..6457c551 100644 --- a/templates/addBm.php +++ b/templates/addBm.php @@ -1,6 +1,6 @@
    -