
//XXX: Purge JQuery
function changeAlertMsgForRWD(){
    $("#alert-message").css("left", function(){
        return $(window).width() / 2 - $(this).outerWidth() / 2;
    })
}

function alertWarning(type){
    alert_msg = $("#alert-message")
    alert_msg.text(type);
    changeAlertMsgForRWD();
    alert_msg.animate({top:"10px"}, 500);
}

function alertWarningClear(){
    alert_msg = $("#alert-message")
    changeAlertMsgForRWD();
    alert_msg.animate({top:"-100px"}, 500);
}

function warningColor(no){
    $($("input[type=\"pd\"]")[no]).css("border-color", "#ff0000");
    $($("input[type=\"pd\"]")[no]).css("box-shadow", "0 0 5px rgba(255, 000, 0, 0.4)");
}

function normalColor(no){
    $($("input[type=\"pd\"]"))[no].css("border-color", "");
    $($("input[type=\"pd\"]"))[no].css("box-shadow", "");
}
function resetColor(){
    $("input[type=\"pd\"]").css("border-color", "");
    $("input[type=\"pd\"]").css("box-shadow", "");
}

app.controller('order_form', function($scope, $http) {
    $scope.getNumber = function(num) {
        return new Array(num);
    };

    $scope.item = [];
    $scope.item_count = 1;
    $scope.stage = 1;
    $scope.loading = false;

    $scope.increase_item_count = function(){
        $scope.item_count += 3;
    };

    $scope.go_to_stage = function(num){
        $scope.stage = num;
    };

    $scope.arrange_order = function(){
        order_list = "";

        for(item of $scope.item){
            order_list += item.pn + ":" + item.quantity + ",";
        }
        if(order_list != ""){
            order_list = order_list.slice(0, -1)
        }

        $scope.item_count = $scope.item.length;

        return order_list;
    }

    $scope.cancel_form = function(){
        if(confirm("您尚未提交訂單，確定要離開?")){
            window.location.href = "/";
        }
    };

    $scope.confirm_price = function(){
        $scope.loading = true;

        var order_list = $scope.arrange_order();
        if(order_list != ""){
            $http.get("/digikey/price/?order_list=" + order_list)
                .then(function(response){
                    if(response.status == 200){
                        console.log(200);
                        var total = 0;

                        response.data.forEach(function(element, index){
                            $scope.item[index].price = parseInt(element["unit_price"], 10) * element["quantity"]
                            total += $scope.item[index].price;
                        });

                        $scope.sum_price = total;

                        alertWarningClear();
                        resetColor();
                        $scope.stage = 2;

                    }else if(response.status == 400){
                        console.log(400);
                        alertWarning("有不存在的料號、不可以1單位訂購的零件、沒有庫存的零件");
                        response.data.forEach(function(element, index){
                            if(element["unit_price"] <= 0){
                                warningColor(index);
                            }
                        });
                    }else if(response.status == 500){
                        alertWarning("我們出錯了，請再試一次");
                    }

                    $scope.loading = false;
                 });
        }else{
            $scope.item_count = 1;
            alertWarning("尚未輸入任何訂單!")
        }
    };

    $scope.submit_form = function(){
        $scope.loading = true;
        $http.get("/digikey/order?order_list=" + $scope.arrange_order())
            .then(function(response){
                if(response.status == 200){
                    window.location.href = "/progress/";
                }
            });
    };
});

$(window).resize(function(){
    changeAlertMsgForRWD();
})

@@ -2071,56 +2071,8 @@
 e)%7B%0A
-                    if(response.status == 200)%7B%0A
     
@@ -2615,37 +2615,126 @@
                 
-%7Delse
+    $scope.loading = false;%0A                    %7D, function(response)%7B%0A                       
  if(response.sta
@@ -2762,32 +2762,36 @@
                 
+    
 console.log(400)
@@ -2808,32 +2808,36 @@
                 
+ 
+   
 alertWarning(%22%E6%9C%89%E4%B8%8D
@@ -2861,24 +2861,28 @@
 %E3%80%81%E6%B2%92%E6%9C%89%E5%BA%AB%E5%AD%98%E7%9A%84%E9%9B%B6%E4%BB%B6%22);%0A
+    
             
@@ -2969,16 +2969,20 @@
         
+ 
+   
 if(eleme
@@ -3001,24 +3001,28 @@
 ce%22%5D %3C= 0)%7B%0A
+    
             
@@ -3082,34 +3082,42 @@
                 
-%7D%0A
+    %7D%0A    
                 
@@ -3144,24 +3144,28 @@
             
+  
+  
 %7Delse if(res
@@ -3202,32 +3202,36 @@
                 
+    
 alertWarning(%22%E6%88%91%E5%80%91
@@ -3255,35 +3255,43 @@
                 
+   
+ 
 %7D%0A%0A
+    
                 
@@ -3310,32 +3310,35 @@
 oading = false;%0A
+   
                 

Fix wrong usage of on ordering