2
* Copyright (C) 2015 Szymon Waliczek.
5
* Szymon Waliczek <majsterrr@gmail.com>
7
* This file is part of SocketWorld app for Ubuntu Touch
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; version 3.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28
property var main_list: []
31
Component.onCompleted: load() //load list
35
if (mainShopListDB.contents.mainList) {
36
main_list = JSON.parse(mainShopListDB.contents.mainList)
37
main_shopping_list_MODEL.append(main_list)
38
if (main_list.length == 0){
39
print("List is empty.")
41
print("Loading " + main_list.length + " item/s to main_list.")
44
print("List is empty, nothingk to load.")
51
// Adding new List to mainShopListModel
52
function addMainList(list_name, default_color) {
54
var colorBG = Math.floor((Math.random() * 10) + 1);
55
main_list.push({"name": list_name, "lista": [], "def_color": default_color, "create_date": date.toString(), "last_edit": date.toString()})
56
main_shopping_list_MODEL.clear()
57
main_shopping_list_MODEL.append(main_list)
61
// edit list in main_list
62
function editListNameAndColor(index, new_name, new_color) {
63
var edited_list = main_list[index]
65
// print(main_list.length)
67
main_list[index] = {"name": new_name, "lista": main_list[index]['lista'], "def_color": new_color, "create_date": main_list[index].create_date, "last_edit": date.toString()}
74
// Adding item to the list
75
function addItemToList(item_name, item_name_org) {
76
var edited_list = main_list[currentMainListIndex]['lista']
77
main_list[currentMainListIndex]['lista'].push({"itemName": item_name, "itemNameOrg": item_name_org, "isInBasket": 0})
80
print(main_list[currentMainListIndex]['lista'][0].itemName)
90
// load main_list to main_shopping_list_MODEL
91
function loadMainList() {
92
main_list = JSON.parse(mainShopListDB.contents.mainList)
93
main_shopping_list_MODEL.append(main_list)
97
// remove list from main_list
98
function removeMainList(index) {
99
var list_name = main_shopping_list_MODEL.get(index).name
100
print("removeing list... " + list_name)
102
list.splice(index, 1)
108
// remove multiple lists from main_list
109
function removeMultipleMainLists(to_remove) {
111
if(to_remove.length === main_list.length) {
112
main_shopping_list_MODEL.clear()
114
for(var e = 0; e < main_list.length; e++) {
115
if(to_remove.indexOf(e) === -1) {
116
print(main_list[e].name)
117
new_list.push(main_list[e])
119
main_shopping_list_MODEL.remove(e)
130
// return list length
131
function mainListLengthInArray() {
133
for(var i=0; i < main_list.length; i++) {
140
// list_name validator
141
function listNameValidator(new_list_name){
143
for(var i=0; i<main_list.length; i++){
144
list_names.push(main_list[i].name.toLowerCase())
146
if(list_names.indexOf(new_list_name.toLowerCase()) > -1) {
155
function getCurrentDate() {
156
var date = new Date()
158
return new Date(main_shopping_list_MODEL.get(0).create_date).toLocaleString();
164
/////////////// LOADING INDIVIDUAL LISTs////////////////
166
function loadCurrentList() {
168
// curList = JSON.parse(main_list[currentMainListIndex]['lista'])
169
currentListMODEL.clear()
170
currentListMODEL.append(main_list[currentMainListIndex]['lista'])
178
function saveMainList() {
179
var tempMainList = {}
180
tempMainList = mainShopListDB.contents
181
tempMainList.mainList = JSON.stringify(main_list)
182
// print("++++++++++++++++++++++++")
183
// print(tempMainList.mainList)
184
// print("++++++++++++++++++++++++")
185
mainShopListDB.contents = tempMainList
186
main_shopping_list_MODEL.clear()
188
print("Total Lists: " + main_shopping_list_MODEL.count)
192
function saveMainListSilent() {
193
var tempMainList = {}
194
tempMainList = mainShopListDB.contents
195
tempMainList.mainList = JSON.stringify(main_list)
196
// print("++++++++++++++++++++++++")
197
// print(tempMainList.mainList)
198
// print("++++++++++++++++++++++++")
199
mainShopListDB.contents = tempMainList