Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.webDb = (function (w) {
- var api = {}, db;
- // set up event handlers and file system
- api.init = function () {
- // Create database
- var dbSize = 20 * 1024 * 1024; // 20MB
- api.db = openDatabase("Database_Banque", "1.0", "Gestion des documents clients", dbSize);
- // Create tables
- api.createTables();
- };
- //event handler for filesystem action
- api.createTables = function () {
- api.db.transaction(function (tx) {
- //(Destroy/Re)Create table customers
- tx.executeSql("DROP TABLE IF EXISTS CUST_Customers", []);
- tx.executeSql("CREATE TABLE IF NOT EXISTS CUST_Customers(tpar_id INTEGER PRIMARY KEY ASC, display_Name TEXT, external_id TEXT)", []);
- //(Destroy/Re)Create table document types
- tx.executeSql("DROP TABLE IF EXISTS DOTY_DocumentType", []);
- tx.executeSql("CREATE TABLE IF NOT EXISTS DOTY_DocumentType(doty_code INTEGER PRIMARY KEY ASC, doty_label TEXT)", []);
- //(Destroy/Re)Create table documents
- tx.executeSql("DROP TABLE IF EXISTS DOCU_Documents", []);
- tx.executeSql("CREATE TABLE IF NOT EXISTS DOCU_Documents(docu_id INTEGER PRIMARY KEY ASC, doty_label TEXT, external_id TEXT, selected BOOLEAN, deleted BOOL, viewed BOOL, filesystem_url TEXT, filename TEXT)", []);
- });
- };
- // pull file down into local
- api.fillData = function (document) {
- try {
- api.db.transaction(function (tx) {
- //Verify if CUST is into db
- tx.executeSql('SELECT * FROM CUST_Customers WHERE external_id = ?', [document.client_external_id], function (t, data) {
- if (data.rows.length == 0) {
- tx.executeSql('INSERT INTO CUST_Customers (display_name, external_id) VALUES (?, ?)', [document.clientFullName, document.client_external_id]);
- console.log("client created");
- }
- });
- //Verify if DOTY is into db
- tx.executeSql('SELECT * FROM DOTY_DocumentType WHERE doty_label = ?', [document.theme], function (t, data) {
- if (data.rows.length == 0) {
- tx.executeSql('INSERT INTO DOTY_DocumentType (doty_label) VALUES (?)', [document.theme]);
- console.log("documentType created");
- }
- });
- //Add DOCU into db
- tx.executeSql('INSERT INTO DOCU_Documents (doty_label, external_id, selected, deleted, viewed, filesystem_url, filename) VALUES (?, ?, ?, ?, ?, ?, ?)', [document.theme, document.client_external_id, false, false, false, document.filesystem, document.fileName]);
- });
- } catch (ev) {
- alert("error");
- }
- //Insert doty into db
- //tx.executeSql();
- //Insert docu into db
- //tx.executeSql();
- };
- // default error handler - that doesn't do anything useful
- api.err = function (ev) {
- console.log(ev);
- };
- api.getDocuments = function () {
- return api.documentsList;
- };
- api.setDocumentsList = function (docList) {
- api.documentsList = docList;
- };
- return api;
- })(window);
Add Comment
Please, Sign In to add comment