~vthompson/ubuntu-weather-app/reboot-do-not-build-pointless-pot-file

« back to all changes in this revision

Viewing changes to app/data/Storage.qml

* Added multiselect/swipe delete and reorder support to locations list
* Added a few FIXMEs to fix in future mps.

Approved by Martin Borho, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
        });
135
135
    }
136
136
 
 
137
    function clearMultiLocation(locations) {
 
138
        openDB();
 
139
 
 
140
        db.transaction(function (tx) {
 
141
            // Remove all the deleted indexes
 
142
            for (var i=0; i < locations.length; i++) {
 
143
                tx.executeSql('DELETE FROM Locations WHERE id=?;', [locations[i]])
 
144
            }
 
145
 
 
146
            // Rebuild locations in order
 
147
            var rs = tx.executeSql('SELECT id FROM Locations ORDER BY id ASC')
 
148
 
 
149
            for (i=0; i < rs.rows.length; i++) {
 
150
                tx.executeSql('UPDATE Locations SET id=? WHERE id=?;',
 
151
                              [i, rs.rows.item(i).id])
 
152
            }
 
153
        })
 
154
    }
 
155
 
137
156
    function clearDB() { // for dev purposes
138
157
        openDB();
139
158
        db.transaction(function(tx){
140
159
            tx.executeSql('DELETE FROM Locations WHERE 1');
141
160
        });
142
161
    }
 
162
 
 
163
    function reorder(from, to) {
 
164
        openDB();
 
165
 
 
166
        db.transaction(function(tx) {
 
167
            // Track to move put as -1 for now
 
168
            tx.executeSql('UPDATE Locations SET id=? WHERE id=?;',
 
169
                          [-1, from])
 
170
 
 
171
            // Shuffle locations inbetween from->to
 
172
            if (from > to) {
 
173
                for (var i = from-1; i >= to; i--) {
 
174
                    tx.executeSql('UPDATE Locations SET id=? WHERE id=?;',
 
175
                                  [i+1, i])
 
176
                }
 
177
            } else {
 
178
                for (var j = from+1; j <= to; j++) {
 
179
                    tx.executeSql('UPDATE Locations SET id=? WHERE id=?;',
 
180
                                  [j-1, j])
 
181
                }
 
182
            }
 
183
 
 
184
            // Switch moving location to its new position
 
185
            tx.executeSql('UPDATE Locations SET id=? WHERE id=?;',
 
186
                          [to, -1])
 
187
        })
 
188
    }
143
189
}