Created
March 11, 2016 17:37
-
-
Save mcrider/f5d684b8387373a73043 to your computer and use it in GitHub Desktop.
Cockpit CMS patch to duplicate collection entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/server/modules/core/Collections/Controller/Api.php b/server/modules/core/Collections/Controller/Api.php | |
index 7c8c381..5fda5b3 100755 | |
--- a/server/modules/core/Collections/Controller/Api.php | |
+++ b/server/modules/core/Collections/Controller/Api.php | |
@@ -104,6 +104,40 @@ public function duplicate(){ | |
return false; | |
} | |
+ public function duplicateEntry (){ | |
+ $collection = $this->param("collection", null); | |
+ $entryId = $this->param("entryId", null); | |
+ $entry = false; | |
+ | |
+ if ($collection && $entryId) { | |
+ $col = "collection".$collection['_id']; | |
+ error_log($collection['_id'] . ' ' . $entryId); | |
+ if ($entry = $this->app->db->findOne("collections/{$col}", ["_id" => $entryId])) { | |
+ | |
+ unset($entry['_id']); | |
+ | |
+ $entry["modified"] = time(); | |
+ $entry["_uid"] = @$this->user["_id"]; | |
+ $entry["created"] = $collection["modified"]; | |
+ | |
+ if (isset($entry["title"])) { | |
+ $entry["title"] .= ' (copy)'; | |
+ } else if (isset($entry["name"])) { | |
+ $entry["name"] .= ' (copy)'; | |
+ } | |
+ | |
+ if (isset($entry["name_slug"])) { | |
+ $entry["name_slug"] .= '-copy'; | |
+ } | |
+ | |
+ $this->app->db->save("collections/{$col}", $entry); | |
+ } | |
+ | |
+ } | |
+ | |
+ return $entry ? json_encode($entry) : '{"success":false}'; | |
+ } | |
+ | |
public function entries() { | |
$collection = $this->param("collection", null); | |
diff --git a/server/modules/core/Collections/assets/js/entries.js b/server/modules/core/Collections/assets/js/entries.js | |
index 02cbd4d..a29dd3c 100755 | |
--- a/server/modules/core/Collections/assets/js/entries.js | |
+++ b/server/modules/core/Collections/assets/js/entries.js | |
@@ -30,6 +30,26 @@ | |
}); | |
}; | |
+ $scope.duplicateEntry = function(index, entryId){ | |
+ App.Ui.confirm(App.i18n.get("Are you sure?"), function(){ | |
+ | |
+ $http.post(App.route("/api/collections/duplicateEntry"), { | |
+ | |
+ "collection": angular.copy($scope.collection), | |
+ "entryId": entryId | |
+ | |
+ }, {responseType:"json"}).success(function(data){ | |
+ | |
+ $timeout(function(){ | |
+ $scope.entries.splice(index + 1, 0, data); | |
+ App.notify(App.i18n.get("Collection entry duplicated"), "success"); | |
+ $scope.collection.count += 1; | |
+ }, 0); | |
+ | |
+ }).error(App.module.callbacks.error.http); | |
+ }); | |
+ }; | |
+ | |
$scope.loadmore = function() { | |
var limit = COLLECTION.sortfield == 'custom-order' ? 10000 : 25, filter = false; | |
diff --git a/server/modules/core/Collections/views/entries.php b/server/modules/core/Collections/views/entries.php | |
index 7ad52d1..361b2b6 100755 | |
--- a/server/modules/core/Collections/views/entries.php | |
+++ b/server/modules/core/Collections/views/entries.php | |
@@ -135,7 +135,8 @@ | |
<i class="uk-icon-bars"></i> | |
<div class="uk-dropdown uk-dropdown-flip uk-text-left"> | |
<ul class="uk-nav uk-nav-dropdown uk-nav-parent-icon"> | |
- <li><a href="@route('/collections/entry/'.$collection["_id"])/@@ entry._id @@"><i class="uk-icon-pencil"></i> @lang('Edit entry')</a></li> | |
+ <li><a href="@route('/collections/entry/'.$collection["_id"])/@@ entry._id @@"><i class="uk-icon-pencil"></i> @lang('Edit entry')</a></li> | |
+ <li><a href="#" data-ng-click="duplicateEntry($index, entry._id)"><i class="uk-icon-plus-circle"></i> @lang('Duplicate entry')</a></li> | |
<li><a href="#" data-ng-click="remove($index, entry._id)"><i class="uk-icon-trash-o"></i> @lang('Delete entry')</a></li> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment