diff --git a/Database/Migrations/2015_12_19_143643_add_sortable.php b/Database/Migrations/2015_12_19_143643_add_sortable.php
new file mode 100644
index 00000000..44a1d72e
--- /dev/null
+++ b/Database/Migrations/2015_12_19_143643_add_sortable.php
@@ -0,0 +1,31 @@
+integer('order')->nullable()->after('zone');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('media__imageables', function (Blueprint $table) {
+ $table->dropColumn('order');
+ });
+ }
+}
diff --git a/Http/Controllers/Api/MediaController.php b/Http/Controllers/Api/MediaController.php
index da27dd3e..5b3eead0 100644
--- a/Http/Controllers/Api/MediaController.php
+++ b/Http/Controllers/Api/MediaController.php
@@ -105,4 +105,22 @@ public function unlinkMedia(Request $request)
return Response::json(['error' => false, 'message' => 'The link has been removed.']);
}
+
+ /**
+ * Sort the record in the media__imageables table for the given array
+ * @param Request $request
+ */
+ public function sortMedia(Request $request)
+ {
+ $imageableIdArray = $request->get('sortable');
+
+ $order = 1;
+
+ foreach ($imageableIdArray as $id) {
+ $updated = DB::table('media__imageables')->whereId($id)->update(['order' => $order]);
+ $order++;
+ }
+
+ return Response::json(['error' => false, 'message' => 'The items have been reorder.']);
+ }
}
diff --git a/Http/apiRoutes.php b/Http/apiRoutes.php
index 270fc16a..6f0717a4 100644
--- a/Http/apiRoutes.php
+++ b/Http/apiRoutes.php
@@ -4,3 +4,4 @@
post('media/link', ['uses' => 'MediaController@linkMedia', 'as' => 'api.media.link']);
post('media/unlink', ['uses' => 'MediaController@unlinkMedia', 'as' => 'api.media.unlink']);
get('media/all', ['uses' => 'MediaController@all', 'as' => 'api.media.all', ]);
+post('media/sort', ['uses' => 'MediaController@sortMedia', 'as' => 'api.media.sort']);
diff --git a/Resources/views/admin/fields/file-link-multiple.blade.php b/Resources/views/admin/fields/file-link-multiple.blade.php
index 40c446fc..7122c035 100644
--- a/Resources/views/admin/fields/file-link-multiple.blade.php
+++ b/Resources/views/admin/fields/file-link-multiple.blade.php
@@ -1,3 +1,4 @@
+
@@ -14,6 +15,7 @@
border: 1px solid #eee;
padding: 3px;
border-radius: 3px;
+ cursor: grab;
}
.jsThumbnailImageWrapper i.removeIcon {
position: absolute;
@@ -25,6 +27,12 @@
border-radius: 20px;
height: 25px;
}
+
+ figure.ui-state-highlight {
+ border: none;
+ width:100px;
+ height: 0;
+ }
diff --git a/Resources/views/admin/fields/file-link.blade.php b/Resources/views/admin/fields/file-link.blade.php
index 2b85d037..b0b5e8eb 100644
--- a/Resources/views/admin/fields/file-link.blade.php
+++ b/Resources/views/admin/fields/file-link.blade.php
@@ -41,10 +41,10 @@
'zone': window.mediaZone
},
success: function (data) {
- var html = '
' +
+ var html = '
' +
'' +
'' +
- '';
+ '';
window.zoneWrapper.append(html).fadeIn('slow', function() {
toggleButton($(this));
});
diff --git a/Support/Traits/MediaRelation.php b/Support/Traits/MediaRelation.php
index 18d4684a..243e22ea 100644
--- a/Support/Traits/MediaRelation.php
+++ b/Support/Traits/MediaRelation.php
@@ -8,6 +8,6 @@ trait MediaRelation
*/
public function files()
{
- return $this->morphToMany('Modules\Media\Entities\File', 'imageable', 'media__imageables')->withPivot('zone', 'id')->withTimestamps();
+ return $this->morphToMany('Modules\Media\Entities\File', 'imageable', 'media__imageables')->withPivot('zone', 'id')->withTimestamps()->orderBy('order');
}
}