Ver Fonte

Option to remove units from the team being created.

Iñigo Valentin há 6 anos atrás
pai
commit
82c1fe54bc
2 ficheiros alterados com 30 adições e 21 exclusões
  1. 23 21
      application/view/teams.php
  2. 7 0
      public/css/teams.css

+ 23 - 21
application/view/teams.php

@@ -310,7 +310,14 @@
                     var slot = document.getElementById(current_slot_id);
                     slot.appendChild(monsterPanel);
                     slot.setAttribute('onclick', 'selectLeader(this);');
-                    // TODO: X to remove
+
+                    // X to remove
+                    var x = document.createElement('input');
+                    x.setAttribute('type', 'button');
+                    x.setAttribute('value', 'x');
+                    x.setAttribute('class', 'delete_unit');
+                    x.setAttribute('onClick', 'deleteUnit(this.parentElement.parentElement);');
+                    monsterPanel.appendChild(x);
 
                     // Set ID
                     var input_id = slot.getElementsByClassName('unit_id')[0];
@@ -330,28 +337,23 @@
 
             /**
              * Deletes a unit from the new team form.
-             * 
-             * @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';
-                    }
+            function deleteUnit(slot){
+            console.log(slot.nodename)
+                var panel = slot.getElementsByClassName('monster_panel')[0];
+                slot.removeChild(panel);
+                var id = slot.getElementsByClassName('unit_id')[0];
+                id.value = '';
+                selected_units --;
+
+                // Remove leader symbol
+                if (slot.classList.contains('leader')){
+                    slot.classList.remove('leader');
+                    leader_id = '';
                 }
+
+                slot.setAttribute('onClick', 'showSearchUnit(this);');
+
             }
 
             /**

+ 7 - 0
public/css/teams.css

@@ -124,6 +124,13 @@ section#new_team div#new_team_units div.monster_panel{
     cursor: pointer;
 }
 
+section#new_team div#new_team_units div.monster_panel input.delete_unit{
+    position: absolute;
+    left: 0.1em;
+    bottom: 0.1em;
+    pointer-events: initial;
+}
+
 section#new_team div.new_unit{
     text-align: right;
     display: none;