Просмотр исходного кода

Save teams from the runs page. UI improvements in the New Team form.

Iñigo Valentin 6 лет назад
Родитель
Сommit
cc7327a300

+ 5 - 0
application/Controller.php

@@ -57,6 +57,11 @@
                         action($db);
                         return;
                         break;
+                    case "SAVE_RUN_TEAM":
+                        require_once($path["action"] . "save_run_team.php");
+                        action($db);
+                        return;
+                        break;
                     default:
                         require_once($path["page"] . "Error_Page.php");
                         $page = new Error_Page($db, 404);

+ 41 - 0
application/action/save_run_team.php

@@ -0,0 +1,41 @@
+<?php
+    function action($db = null){
+        $player = filter_input(INPUT_POST, 'uid');
+        $run = filter_input(INPUT_POST, 'run');
+        $name = filter_input(INPUT_POST, 'name');
+        $description = filter_input(INPUT_POST, 'description');
+        if ($name == null || strlen($name) == 0){
+            return -1;
+        }
+        $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
+        $q = $db->query($s);
+        $r = $q->fetchArray(SQLITE3_ASSOC);
+        $team_id = $r["id"];
+        $s = "SELECT run.area AS area, run.stage AS stage, run.difficulty AS difficulty, k_area.type AS area_type FROM run, k_area WHERE run.uid = '$player' AND run.id = '$run' AND k_area.id = run.area AND run.helper = 0;";
+        $q = $db->query($s);
+        $r = $q->fetchArray(SQLITE3_ASSOC);
+        if (!$r){
+            return -2;
+        }
+        $statement = $db->prepare('INSERT INTO team (uid, id, name, description, area_type, area, stage, difficulty) VALUES (:uid, :id, :name, :description, :area_type, :area, :stage, :difficulty);');
+        $statement->bindValue(':uid', $player);
+        $statement->bindValue(':id', $team_id);
+        $statement->bindValue(':name', $name);
+        $statement->bindValue(':description', $description);
+        $statement->bindValue(':area_type', $r["area_type"]);
+        $statement->bindValue(':area', $r["area"]);
+        $statement->bindValue(':stage', $r["stage"]);
+        $statement->bindValue(':difficulty', $r["difficulty"]);
+        $res = $statement->execute();
+        if (!$res){
+            return -3;
+        }
+        $s = "SELECT unit FROM run_party WHERE run = $run AND unit IS NOT NULL;";
+        $q = $db->query($s);
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            $s = "INSERT INTO team_unit VALUES ('$team_id', '" . $r["unit"] . "');";
+            $db->query($s);
+        }
+        return 0;
+    }
+?>

+ 78 - 0
application/view/runs.php

@@ -1,6 +1,7 @@
 <?php
     global $AREA_TYPE;
     global $SCENARIO;
+    global $UID;
 ?>
 <!DOCTYPE html>
 <html lang='en'>
@@ -33,6 +34,36 @@
         <meta name='twitter:image' content='<?=$page->icon?>'/>
         <meta name='twitter:url' content='<?=$page->canonical?>'/>
         <meta name='robots' content='index follow'/>
+        <script>
+            function saveForm(id, show){
+                if (show === true){
+                    document.getElementById('save_team').style.display = 'block';
+                    document.getElementById('save_id').value = id;
+                }
+                else{
+                    document.getElementById('save_team').style.display = 'none';
+                }
+            }
+
+            function saveTeam(){
+                var id = document.getElementById('save_id').value;
+                var name = document.getElementById('save_team_name').value;
+                var description = document.getElementById('save_team_description').value;
+                if (name == ''){
+                    alert('Name required')
+                    return;
+                }
+                var xhttp = new XMLHttpRequest();
+                xhttp.onreadystatechange = function() {
+                    if (this.readyState == 4 && this.status == 200) {
+                        saveForm(null, false);
+                    }
+                };
+                xhttp.open("POST", "/action/save_run_team/", true);
+                xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+                xhttp.send('uid=<?=$UID?>&run=' + id + '&name=' + encodeURI(name) + '&description=' + encodeURI(description));
+            }
+        </script>
     </head>
     <body>
 <?php
@@ -50,6 +81,9 @@
 
             </section> <!-- #filters -->
             <section class='content'>
+                <h2>
+                    Runs
+                </h2>
                 <article>
                     <table id='runs'>
                         <tr>
@@ -71,6 +105,7 @@
                         </tr>
 <?php
                         foreach ($page->runs as $run){
+                            $enable_save = true;
 ?>
                             <tr>
                                 <td class='area'>
@@ -108,6 +143,7 @@
                                 <td class='team'>
 <?php
                                     if ($run->helper == 1){
+                                        $enable_save = false;
 ?>
                                         <div class='monster_panel helper'>
                                             <img class='monster' title='Friend/Menstor' src='<?=$path["img"]["currency"]?>socialpoint.png'/>
@@ -116,6 +152,7 @@
                                     }
                                     foreach ($run->party as $party){
                                         if ($party instanceof K_Unit){
+                                            $enable_save = false;
                                             $disabled = "disabled";
                                         }
                                         else{
@@ -233,6 +270,15 @@
                                         </div>
 <?php
                                     }
+?>
+                                </td>
+                                <td class='action'>
+<?php
+                                    if ($enable_save){
+?>
+                                        <img alt='Save Team' class='save_team' onclick='saveForm(<?=$run->id?>, true);' src='<?=$path["img"]["icon"]?>save.png'/>
+<?php
+                                    }
 ?>
                                 </td>
                             </tr>
@@ -242,6 +288,38 @@
                     </table>
                 </article>
             </section>
+            <section id='save_team' class='content'>
+                <h2>
+                    Save run
+                </h2>
+                <article>
+                    <input id='save_id' type='hidden' value=''/>
+                    <table>
+                        <tr>
+                            <td class='save_title'>
+                                Name
+                            </td>
+                            <td class='save_values'>
+                                <input type='text' id='save_team_name' name='name'/>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td class='save_title'>
+                                Description
+                            </td>
+                            <td class='save_values'>
+                                <textarea id='save_team_description' name='description'></textarea>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td colspan='2'>
+                                <input type='button' value='Save' onClick='saveTeam();'/>
+                                <input type='button' value='Close' onClick='saveForm(null, false);'/>
+                            </td>
+                        </tr>
+                    </table>
+                </article>
+            </section>
 <?php
         include __DIR__ . "/inc/footer.php";
 ?>

+ 23 - 3
application/view/teams.php

@@ -142,13 +142,11 @@
                 var xhttp = new XMLHttpRequest();
                 xhttp.onreadystatechange = function() {
                     if (this.readyState == 4 && this.status == 200) {
-                        alert("200");
-                        //location.reload(); 
+                        location.reload(); 
                     }
                 };
                 xhttp.open("POST", "/action/new_team/", true);
                 xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-                console.log('uid=<?=$UID?>&ids=' + ids + '&area_type=' + area_type + '&area=' + area + '&difficulty=' + difficulty + '&stage=' + stage + '&name=' + encodeURI(name) + '&description=' + encodeURI(description));
                 xhttp.send('uid=<?=$UID?>&ids=' + ids + '&area_type=' + area_type + '&area=' + area + '&difficulty=' + difficulty + '&stage=' + stage + '&name=' + encodeURI(name) + '&description=' + encodeURI(description));
 
             }
@@ -209,6 +207,8 @@
                 if (name != null){
                     var monsterPanel = document.createElement('div');
                     monsterPanel.setAttribute('class', 'monster_panel');
+                    monsterPanel.setAttribute('id', 'monster_panel_' + id);
+                    monsterPanel.setAttribute('onclick', 'deleteUnit(' + id + ')');
                     var monsterStars = document.createElement('span');
                     monsterStars.setAttribute('class', 'stars');
                     for (var i = 0; i < stars; i ++){
@@ -253,6 +253,24 @@
              * @param id Unit id.
              */
             function deleteUnit(id){
+                var position = -1;
+                for (var i = 0; i < units.length; i ++) {
+                    if (units[i].id == id){
+                        position = i;
+                        break;
+                    }
+                }
+                if (position >= 0 && position < units.length){
+                    units.splice(position, 1);
+                    document.getElementById('new_team_units').removeChild(document.getElementById('monster_panel_' + id));
+                    selected_units --;
+                    if (selected_units >= max_units){
+                        document.getElementById('new_unit').style.display = 'none';
+                    }
+                    else{
+                        document.getElementById('new_unit').style.display = 'block';
+                    }
+                }
             }
 
             /**
@@ -681,8 +699,10 @@
                     <tr>
                         <td colspan='2'>
                             <input type='button' value='Save' onClick='saveTeam();'/>
+                            <input type='button' value='Close' onClick='showNewTeam(false);'/>
                         </td>
                     </tr>
+                </table>
             </article>
         </section>
     </body>

+ 33 - 0
public/css/runs.css

@@ -113,3 +113,36 @@ table#runs td.reward div.item_rune table.rune{
 table#runs td.reward div.item_rune:hover table.rune{
     display: block;
 }
+
+table#runs td.action img.save_team{
+    width: 1em;
+    height: 1em;
+    cursor: pointer;
+}
+
+
+section#save_team{
+    z-index: 1;
+    display: none;
+    position: fixed;
+    width: 80%;
+    height: 70%;
+    margin: 0 10%;
+    top: 10%;
+    filter: drop-shadow(0 0 10em #000000) drop-shadow(0 0 6em #000000);
+}
+
+section#save_team table{
+    width: 100%;
+}
+
+section#save_team table td.save_title{
+    width: 10em;
+    text-align: right;
+    padding-right: 2em;
+}
+
+section#save_team table td.save_values{
+    text-align: left;
+    padding-right: 2em;
+}

+ 11 - 1
public/css/teams.css

@@ -79,6 +79,7 @@ section#new_team div#new_team_units{
 
 section#new_team div#new_team_units div.monster_panel{
     font-size: 50%;
+    cursor: not-allowed;
 }
 
 section#new_team div.new_unit{
@@ -96,9 +97,18 @@ section#new_team div.new_unit div.new_unit_autocomplete{
 
 section#new_team div.new_unit div.new_unit_autocomplete div{
     border: 0.05em solid #000000;
-    margin: 0.1em;
     text-align: left;
+    text-transform: capitalize;
+    font-variant: small-caps;
     cursor: pointer;
+    color: var(--input-color);
+    font-weight: var(--input-font-weight);
+    padding: var(--input-padding);
+    background: var(--input-background);
+    border: var(--input-border);
+    border-radius: var(--input-border-radius);
+    text-shadow: var(--input-text-shadow);
+    box-shadow: var(--input-box-shadow);
 }
 
 section#new_team div.new_unit div.new_unit_autocomplete div span{