[TIC-Web] fix the recipe order 63/124463/2
authorChangHyun Lee <leechwin.lee@samsung.com>
Tue, 11 Apr 2017 10:02:42 +0000 (19:02 +0900)
committerChangHyun Lee <leechwin.lee@samsung.com>
Tue, 11 Apr 2017 10:18:10 +0000 (19:18 +0900)
- fix the recipe order

Change-Id: I14a4b017d0130a991792090bfd4a9678c270c6a3
Signed-off-by: ChangHyun Lee <leechwin.lee@samsung.com>
public/src/index.html
public/src/js/page/settings.js

index 77c5be3..de31545 100644 (file)
                                         <label class="radio-inline control-label"><input id="tic-import-recipe-repo-url-group" type="radio" name="recipe" > Repository URL</label>
                                     </div>
                                 </div>
-                                <div class="form-group has-feedback has-clear col-md-7">
+                                <div id="tic-import-recipe-repo-url-group" class="form-group has-feedback has-clear col-md-7">
                                     <input class="form-control tic-import-recipe-repo-url-group" id="tic-import-recipe-repo-url-input" type="url" placeholder="Enter repository URL" data-unique="unique">
-                                    <div class="help-block with-errors"></div>
+                                    <div id="tic-import-recipe-repo-url-group-help" class="help-block with-errors"></div>
                                 </div>
                             </div>
                         </div>
index e6f0ce5..f969be4 100644 (file)
@@ -28,6 +28,10 @@ define([
         return recipeStore;
     }
 
+    function setRecipeStore(store) {
+        recipeStore = store;
+    }
+
     function _addRecipe(recipe) {
         var $recipe;
         if (recipe.type === 'recipe') {
@@ -45,7 +49,6 @@ define([
         $('#tic-recipe-list').append($recipe);
     }
 
-    // TODO: set/get sortable recipe
     function _updateRecipe() {
         var $recipe = $('#tic-recipe-list');
         $recipe.empty();
@@ -56,16 +59,14 @@ define([
     }
 
     function updatePackage() {
-        // FIXME:
         var postBody = {
-            //repos : _.map(_.orderBy(recipeStore, ['priority']), 'url'),
             recipes : recipeStore
         };
 
         return Util.POST(CONFIG.EVENT.PACKAGE.ANALYSIS, postBody)
         .then(function (result) {
             if (result.result === 'true') {
-                recipeStore = result.data.recipes;
+                setRecipeStore(result.data.recipes);
                 _updateRecipe();
                 return result.data;
             } else {
@@ -88,7 +89,7 @@ define([
         function _importHandler() {
             Import.showImportDialog(recipeStore)
             .then(function(recipes) {
-                recipeStore = recipes;
+                setRecipeStore(recipes);
                 _updateRecipe();
             });
         }
@@ -123,7 +124,7 @@ define([
             pullPlaceholder: false,
 
             // set $item relative to cursor position
-            onDragStart: function ($item, container, _super) {
+            onDragStart: function($item, container, _super) {
                 var offset = $item.offset()
                 var pointer = container.rootGroup.pointer;
                 adjustment = {
@@ -132,11 +133,30 @@ define([
                 };
                 _super($item, container);
             },
-            onDrag: function ($item, position) {
+            onDrag: function($item, position) {
                 $item.css({
                     left: position.left - adjustment.left,
                     top: position.top - adjustment.top
                 });
+            },
+            onDrop: function($item, container, _super) {
+                // reorder for recipe
+                var recipeItems = $('#tic-recipe-list li');
+                var store = [];
+                _.forEach(recipeItems, function(recipeItem) {
+                    store.push(_.find(getRecipeStore(), { url: recipeItem.id }));
+                });
+                setRecipeStore(store);
+
+                // animation on drop
+                var $clonedItem = $('<li/>').css({height: 0});
+                $item.before($clonedItem);
+                $clonedItem.animate({'height': $item.height()});
+
+                $item.animate($clonedItem.position(), function() {
+                    $clonedItem.detach();
+                    _super($item, container);
+                });
             }
         });