Sfoglia il codice sorgente

update bookmark plugin to include setup function

CauseFX 5 anni fa
parent
commit
d70bf0199d
2 ha cambiato i file con 135 aggiunte e 22 eliminazioni
  1. 103 11
      api/plugins/bookmark.php
  2. 32 11
      api/plugins/js/bookmark-settings.js

+ 103 - 11
api/plugins/bookmark.php

@@ -96,23 +96,44 @@ class Bookmark extends Organizr
 		return array(
 			'custom' => '
 				<div class="row">
-                    <div class="col-lg-12">
-                        <div class="panel panel-info">
-                            <div class="panel-heading">
+					<div class="col-lg-6 col-sm-12 col-md-6">
+						<div class="white-box">
+							<h3 class="box-title" lang="en">Automatic Setup Tasks</h3>
+							<ul class="feeds">
+								<li class="bookmark-check-tab">
+									<div class="bg-info">
+										<i class="sticon ti-layout-tab-v text-white"></i>
+									</div>
+									<small lang="en">Checking for Bookmark tab...</small>
+									<span class="text-muted result">...checking...</span>
+								</li>
+								<li class="bookmark-check-category">
+									<div class="bg-success">
+										<i class="ti-layout-list-thumb text-white"></i>
+									</div>
+									<small lang="en">Checking for bookmark default category...</small>
+									<span class="text-muted result">...checking...</span>
+								</li>
+							</ul>
+						</div>
+					</div>
+					<div class="col-lg-6 col-sm-12 col-md-6">
+						<div class="panel panel-info">
+							<div class="panel-heading">
 								<span lang="en">Notice</span>
-                            </div>
-                            <div class="panel-wrapper collapse in" aria-expanded="true">
-                                <div class="panel-body">
+							</div>
+							<div class="panel-wrapper collapse in" aria-expanded="true">
+								<div class="panel-body">
 									<ul class="list-icons">
 										<li><i class="fa fa-chevron-right text-info"></i> Add tab that points to <i>api/v2/plugins/bookmark/page</i> and set it\'s type to <i>Organizr</i>.</li>
 										<li><i class="fa fa-chevron-right text-info"></i> Create Bookmark categories in the new area in <i>Tab Editor</i>.</li>
 										<li><i class="fa fa-chevron-right text-info"></i> Create Bookmark tabs in the new area in <i>Tab Editor</i>.</li>
 										<li><i class="fa fa-chevron-right text-info"></i> Open your custom Bookmark page via menu.</li>
-                                    </ul>
-                                </div>
-                            </div>
-                        </div>
-                    </div>
+									</ul>
+								</div>
+							</div>
+						</div>
+					</div>
 				</div>
 			'
 		);
@@ -984,4 +1005,75 @@ class Bookmark extends Organizr
 		}
 		return '#' . implode($hexCode);
 	}
+	
+	public function _checkForBookmarkTab()
+	{
+		$response = [
+			array(
+				'function' => 'fetchAll',
+				'query' => array(
+					'SELECT * FROM tabs',
+					'WHERE url = ?',
+					'api/v2/plugins/bookmark/page'
+				)
+			),
+		];
+		$tab = $this->processQueries($response);
+		if ($tab) {
+			$this->setAPIResponse('success', 'Tab already exists', 200);
+			return $tab;
+		} else {
+			$createTab = $this->_createBookmarkTab();
+			if ($createTab) {
+				$tab = $this->processQueries($response);
+				$this->setAPIResponse('success', 'Tab created', 200);
+				return $tab;
+			} else {
+				$this->setAPIResponse('error', 'Tab creation error', 500);
+			}
+		}
+	}
+	
+	public function _createBookmarkTab()
+	{
+		$tabInfo = [
+			'order' => $this->getNextTabOrder() + 1,
+			'category_id' => $this->getDefaultCategoryId(),
+			'name' => 'Bookmarks',
+			'url' => 'api/v2/plugins/bookmark/page',
+			'default' => false,
+			'enabled' => true,
+			'group_id' => $this->getDefaultGroupId(),
+			'image' => 'fontawesome::book',
+			'type' => 0
+		];
+		$response = [
+			array(
+				'function' => 'query',
+				'query' => array(
+					'INSERT INTO [tabs]',
+					$tabInfo
+				)
+			),
+		];
+		return $this->processQueries($response);
+	}
+	
+	public function _checkForBookmarkCategories()
+	{
+		$categories = $this->_getAllCategories();
+		if ($categories) {
+			$this->setAPIResponse('success', 'Categories already exists', 200);
+			return $categories;
+		} else {
+			$createCategory = $this->_addCategory(['category' => 'Unsorted', 'default' => 1]);
+			if ($createCategory) {
+				$categories = $this->_getAllCategories();
+				$this->setAPIResponse('success', 'Category created', 200);
+				return $categories;
+			} else {
+				$this->setAPIResponse('error', 'Category creation error', 500);
+			}
+		}
+	}
 }

+ 32 - 11
api/plugins/js/bookmark-settings.js

@@ -1,20 +1,41 @@
 /* BOOKMARK JS FILE */
 // FUNCTIONS
-$(document).on('click', '#BOOKMARK-settings-button', function() {
-	ajaxloader(".content-wrap","in");
-	organizrAPI2('GET','api/v2/plugins/bookmark/settings').success(function(data) {
-		var response = data.response;
-		$('#BOOKMARK-settings-items').html(buildFormGroup(response.data));
-	}).fail(function(xhr) {
-		console.error("Organizr Function: API Connection Failed");
-	});
-	ajaxloader();
-});
-
 bookmarkLaunch();
 $('body').arrive('#settings-main-tab-editor .nav-tabs', {onceOnly: true}, function() {
 	bookmarkLaunch();
 });
+function bookmarkCheckForTab() {
+	// Let check for tab with bookmark url
+	organizrAPI2('GET', 'api/v2/plugins/bookmark/setup/tab').success(function (data) {
+		try {
+			let response = data.response;
+			$('.bookmark-check-tab .result').text(response.message);
+		} catch (e) {
+			organizrCatchError(e, data);
+		}
+	}).fail(function (xhr) {
+		OrganizrApiError(xhr);
+		$('.bookmark-check-tab .result').text('Error...');
+	});
+}
+$('body').arrive('.bookmark-check-tab', {onceOnly: false}, function() {
+	bookmarkCheckForTab()
+	bookmarkCheckForCategory();
+});
+function bookmarkCheckForCategory(){
+	// Let check for tab with bookmark url
+	organizrAPI2('GET','api/v2/plugins/bookmark/setup/category').success(function(data) {
+		try {
+			let response = data.response;
+			$('.bookmark-check-category .result').text(response.message);
+		}catch(e) {
+			organizrCatchError(e,data);
+		}
+	}).fail(function(xhr) {
+		OrganizrApiError(xhr);
+		$('.bookmark-check-category .result').text('Error...');
+	});
+}
 function bookmarkLaunch(){
 	if(activeInfo.plugins["BOOKMARK-enabled"] == true){
 		bookmarkTabsLaunch();