Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = {
- // Application Constructor
- initialize: function() {
- this.bindEvents();
- persistenceTest();
- databaseCreateSchema(true, false, false);
- setupHomePageProjects();
- createEventHandlers();
- },
- // Bind Event Listeners
- //
- // Bind any events that are required on startup. Common events are:
- // 'load', 'deviceready', 'offline', and 'online'.
- bindEvents: function() {
- document.addEventListener('deviceready', this.onDeviceReady, false);
- },
- // deviceready Event Handler
- //
- // The scope of 'this' is the event. In order to call the 'receivedEvent'
- // function, we must explicitly call 'app.receivedEvent(...);'
- onDeviceReady: function() {
- app.receivedEvent('deviceready');
- },
- // Update DOM on a Received Event
- receivedEvent: function(id) {
- var parentElement = document.getElementById(id);
- var listeningElement = parentElement.querySelector('.listening');
- var receivedElement = parentElement.querySelector('.received');
- listeningElement.setAttribute('style', 'display:none;');
- receivedElement.setAttribute('style', 'display:block;');
- console.log('Received Event: ' + id);
- }
- };
- app.initialize();
- var Task = persistence.define('Task', {
- name: "TEXT",
- done: "BOOL"
- });
- function persistenceTest() {
- console.log("persistenceTest1");
- persistence.store.websql.config(persistence, 'ptest', 'A database description', 5 * 1024 * 1024);
- console.log("persistenceTest2");
- //persistenceSchemaSync();
- console.log("persistenceTest3");
- //persistenceReset();
- console.log("persistenceTest4");
- }
- function persistenceSchemaSync() {
- }
- function persistenceReset() {
- persistenceFlush();
- };
- function persistenceFlush() {
- }
- function testJSONLoad() {
- console.log("testJSONLoad1");
- // $.getJSON("http://localhost:8080/cc/tablet/UserTestPassword.jsp", {UserName: "ky1a21w2a1wv1lemore", Password: "b2t$g6y*"}, function(data) {
- // $.getJSON("/cc/tablet/UserTestPassword.jsp", {UserName: "ky1a21w2a1wv1lemore", Password: "b2t$g6y*"}, function(data) {
- $.getJSON("http://10.60.74.102:8080/cc/tablet/UserTestPassword.jsp", {UserName: "ky1a21w2a1wv1lemore", Password: "b2t$g6y*"}, function(data) {
- // $.getJSON("alex.builderlynx.com:8080/cc/tablet/UserTestPassword.jsp", {UserName: "ky1a21w2a1wv1lemore", Password: "b2t$g6y*"}, function(data) {
- console.log(data);
- console.log(data.AuthenticationPassword);
- console.log(data.AuthenticationUsername);
- console.log(data.AuthenticationRequestResult);
- alert(data.AuthenticationRequestResult);
- });
- console.log("testJSONLoad2");
- }
- // Wait for PhoneGap to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
- // PhoneGap is ready
- //
- function onDeviceReady() {
- console.log("onDeviceReady***1");
- }
- function cleanString(str) {
- str = str.replace(/[^a-zA-Z 0-9]+/g,'');
- str = str.replace(/[ ]+/g, '');
- return str;
- }
- function processUnitDirectory(blUnit, actionOnDirectory) {
- blProject = blUnit.blProject;
- blUnit.fetch("BLProject", function (blProject) {
- blDirectory = "BuilderLynx";
- console.log("here1:" + blUnit.Name);
- console.log("here1:" + blProject);
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
- function(fileSystem) {
- console.log("here2");
- fileSystem.root.getDirectory(blDirectory, {create: true}, function (dirBuilderLynx) {
- console.log("here3");
- dirBuilderLynx.getDirectory(cleanString(blProject.Name), {create: true}, function (dirProject) {
- console.log("here4");
- dirProject.getDirectory(cleanString(blUnit.Name), {create: true}, function (dirUnit) {
- console.log("here5");
- actionOnDirectory(dirUnit);
- }, fileOperationFail);
- }, fileOperationFail);
- }, fileOperationFail);
- }, fileOperationFail);
- });
- }
- function fileOperationFail(error) {
- console.log("fileOperationFail***2");
- errorDesc = "";
- if (error.code == FileError.NOT_FOUND_ERR) {
- errorDesc = error.code + "NOT_FOUND_ERR";
- } else if (error.code == FileError.SECURITY_ERR) {
- errorDesc = error.code + "SECURITY_ERR";
- } else if (error.code == FileError.ABORT_ERR) {
- errorDesc = error.code + "ABORT_ERR";
- } else if (error.code == FileError.NOT_READABLE_ERR) {
- errorDesc = error.code + "NOT_READABLE_ERR";
- } else if (error.code == FileError.ENCODING_ERR) {
- errorDesc = error.code + "ENCODING_ERR";
- } else if (error.code == FileError.NO_MODIFICATION_ALLOWED_ERR) {
- errorDesc = error.code + "NO_MODIFICATION_ALLOWED_ERR";
- } else if (error.code == FileError.INVALID_STATE_ERR) {
- errorDesc = error.code + "INVALID_STATE_ERR";
- } else if (error.code == FileError.SYNTAX_ERR) {
- errorDesc = error.code + "SYNTAX_ERR";
- } else if (error.code == FileError.INVALID_MODIFICATION_ERR) {
- errorDesc = error.code + "INVALID_MODIFICATION_ERR";
- } else if (error.code == FileError.QUOTA_EXCEEDED_ERR) {
- errorDesc = error.code + "QUOTA_EXCEEDED_ERR";
- } else if (error.code == FileError.TYPE_MISMATCH_ERR) {
- errorDesc = error.code + "TYPE_MISMATCH_ERR";
- } else if (error.code == FileError.PATH_EXISTS_ERR) {
- errorDesc = error.code + "PATH_EXISTS_ERR";
- }
- console.log(errorDesc);
- displayErrorMessage(errorDesc);
- }
- function displayErrorMessage() {
- $('#PageReportError').html(message);
- $('#PageReportError').popup();
- }
- SQLDatabaseName = "BuilderLynxPDI";
- SQLDatabaseVersion = "1.0";
- SQLDatabaseSize = 5 * 1024 * 1024;
- SQLDatabase = null;
- SQLQueries = 0;
- SQLErrors = 0;
- var BLProject = BLProject != null ? BLProject : null;
- var BLUnit = BLUnit != null ? BLUnit : null;
- var BLUser = BLUser != null ? BLUser : null;
- var BLRoom = BLRoom != null ? BLRoom : null;
- var BLDeficiencyType = BLDeficiencyType != null ? BLDeficiencyType : null;
- var BLDeficiency = BLDeficiency != null ? BLDeficiency : null;
- var BLSupplierDepartment = BLSupplierDepartment != null ? BLSupplierDepartment : null;
- //CAMERA *******************************************************************************************
- //var BLPicGallery = BLPicGallery != null ? BLPicGallery : null;
- //var BLPicTaken = BLPicTaken != null ? BLPicTaken : null;
- // Populate the database
- function databaseCreateSchema(resetSchema, populateDatabase, dropAllData) {
- console.log("Create BLProject");
- BLProject = persistence.define('BLProject', {
- RemoteID: "INT",
- Name: "TEXT",
- CompanyName: "TEXT",
- TarionRegistrationNumber: "TEXT",
- Municipality: "TEXT",
- Domain: "TEXT",
- });
- console.log("Create BLUnit");
- BLUnit = persistence.define('BLUnit', {
- RemoteID: "INT",
- Name: "TEXT",
- BuyerClosingDate: "TEXT",
- MunicipalAddress: "TEXT",
- City: "TEXT",
- TarionEnrollmentNumber: "TEXT",
- });
- BLProject.hasMany("BLUnits", BLUnit, "BLProject");
- console.log("Create BLUser");
- BLUser = persistence.define('BLUser', {
- RemoteID: "INT",
- Username: "TEXT",
- Password: "TEXT",
- Name1: "TEXT",
- Name2: "TEXT",
- Name3: "TEXT",
- Name4: "TEXT",
- Phone1: "TEXT",
- Phone2: "TEXT",
- Email: "TEXT",
- Street: "TEXT",
- City: "TEXT",
- Province: "TEXT",
- PostalCode: "TEXT",
- });
- BLUser.hasOne("BLProject", BLProject);
- BLUser.hasOne("BLUnit", BLUnit);
- BLUnit.hasOne("BLUser", BLUser);
- BLProject.hasOne("BLUser", BLUser);
- console.log("Create BLRoom");
- BLRoom = persistence.define('BLRoom', {
- RemoteID: "INT",
- Name: "TEXT",
- });
- BLProject.hasMany("BLRooms", BLRoom, "BLProject");
- //CAMERA
- /*console.log("Create BLPicGallery");
- BLPicGallery = persistence.define('BLPicGallery', {
- RemoteID: "INT",
- Image: "TEXT",
- });
- BLProject.hasMany("BLPicsGallery", BLPicGallery, "BLProject");
- console.log("Create BLPicTaken");
- BLPicTaken = persistence.define('BLPicTaken', {
- RemoteID: "INT",
- Image: "TEXT",
- });
- BLProject.hasMany("BLPicsTaken", BLPicTaken, "BLProject");*/
- //END CAMERA
- console.log("Create BLSupplierDepartment");
- BLSupplierDepartment = persistence.define('BLSupplierDepartment', {
- RemoteID: "INT",
- CompanyName: "TEXT",
- ContactName: "TEXT",
- Phone1: "TEXT",
- Phone2: "TEXT",
- Email: "TEXT",
- });
- BLProject.hasMany("BLSupplierDepartments", BLSupplierDepartment, "BLProject");
- console.log("Create BLDeficiencyType");
- BLDeficiencyType = persistence.define('BLDeficiencyType', {
- RemoteID: "INT",
- Name: "TEXT",
- });
- BLProject.hasMany("BLDeficiencyTypes", BLDeficiencyType, "BLProject");
- BLDeficiencyType.hasOne("BLSupplierDepartment", BLSupplierDepartment);
- console.log("Create BLDeficiencyTypeDescription");
- BLDeficiencyTypeDescription = persistence.define('BLDeficiencyTypeDescription', {
- RemoteID: "INT",
- Description: "TEXT",
- });
- BLDeficiencyTypeDescription.hasOne("BLDeficiencyType", BLDeficiencyType);
- BLDeficiencyType.hasMany("BLDeficiencyTypeDescriptions", BLDeficiencyTypeDescription, "BLDeficiencyType");
- console.log("Create BLFormTemplate");
- BLFormTemplate = persistence.define('BLFormTemplate', {
- RemoteID: "INT",
- Title: "TEXT",
- Description: "TEXT",
- Text: "TEXT",
- });
- BLProject.hasMany("BLFormTemplates", BLFormTemplate, "BLProject");
- console.log("Create BLDeficiency");
- BLDeficiency = persistence.define('BLDeficiency', {
- RemoteID: "INT",
- Description: "TEXT",
- Source: "TEXT",
- Status: "TEXT",
- ChargeBack: "TEXT",
- Saved: "BOOL",
- ImageGallery: "TEXT",
- ImageTaken: "TEXT",
- ImageDynamic: "TEXT",
- });
- BLDeficiency.hasOne("BLRoom", BLRoom);
- BLDeficiency.hasOne("BLDeficiencyType", BLDeficiencyType);
- BLDeficiency.hasOne("BLUnit", BLUnit);
- BLDeficiency.hasOne("BLProject", BLProject);
- BLDeficiency.hasOne("BLSupplierDepartment", BLSupplierDepartment);
- BLDeficiency.hasOne("BLSupplierDepartmentChargeBack", BLSupplierDepartment);
- //BLDeficiency.hasOne("BLPicGallery", BLPicGallery);
- //BLDeficiency.hasOne("BLPicTaken", BLPicTaken);
- BLUnit.hasMany("BLDeficiencies", BLDeficiency, "BLUnit");
- console.log("populateDB start");
- if (resetSchema) {
- persistenceReset();
- }
- if (dropAllData) {
- BLDeficiency.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLDeficiency");
- });
- BLDeficiencyType.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLDeficiencyType");
- });
- /*BLDeficiencyTypeDescription.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLDeficiencyTypeDescription");
- });*/
- BLFormTemplate.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLFormTemplate");
- });
- BLRoom.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLRoom");
- });
- BLSupplierDepartment.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLSupplierDepartment");
- });
- BLUnit.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLUnit");
- });
- BLUser.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLUser");
- });
- BLProject.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLProject");
- });
- //PROVA CAMERA *****************************************************************************
- /*BLPics.all().list(function (objects) {
- objects.forEach(function (object) {
- persistence.remove(object);
- });
- console.log("Deleted all BLPics");
- });*/
- }
- persistence.schemaSync(function() {
- console.log("schema sync done");
- if (populateDatabase) {
- databasePopulateDB();
- }
- });
- }
- //Trial DB function
- /*function databasePopulateDB() {
- var BLProject1 = new BLProject({RemoteID: 703273, Name: "Northshore1", CompanyName: "Fram Building Group", Plan: "2030-33"});
- var BLProject2 = new BLProject({RemoteID: 123456, Name: "West Village 2B", CompanyName: "Kylemore Communities", Plan: "2030-33"});
- var BLUnit201 = createBLUnit(BLProject1, 1, "Suite 201", "2012/03/05");
- var BLUnit202 = createBLUnit(BLProject1, 2, "Suite 202", "2012/03/07");
- var BLUnit203 = createBLUnit(BLProject1, 3, "Suite 203", "2012/03/08");
- var BLUnit302 = createBLUnit(BLProject1, 4, "Suite 301", "2012/03/09");
- var BLUnit303 = createBLUnit(BLProject1, 5, "Suite 302", "2012/03/02");
- var BLLot1 = createBLUnit(BLProject2, 5, "Lot 1", "2012/03/05");
- var BLLot2 = createBLUnit(BLProject2, 6, "Lot 2", "2012/03/04");
- var BLLot3 = createBLUnit(BLProject2, 7, "Lot 3", "2012/03/03");
- var BLLot4 = createBLUnit(BLProject2, 8, "Lot 4", "2012/03/02");
- var BLLot5 = createBLUnit(BLProject2, 9, "Lot 5", "2012/03/01");
- createBLUser(BLProject1, BLUnit201, 1, "John1", "Smith1", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "201 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject1, BLUnit202, 2, "John2", "Smith2", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "202 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject1, BLUnit203, 3, "John3", "Smith3", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "203 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject1, BLUnit302, 4, "John4", "Smith4", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "302 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject1, BLUnit303, 5, "John5", "Smith5", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "303 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject2, BLLot1, 6, "Dave1", "Smith1", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "1 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject2, BLLot2, 7, "Dave2", "Smith2", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "2 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject2, BLLot3, 8, "Dave3", "Smith3", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "3 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject2, BLLot4, 9, "Dave4", "Smith4", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "4 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- createBLUser(BLProject2, BLLot5, 10, "Dave5", "Smith5", "416-425-2925", "416-425-4233", "alex@builderlynx.com", "5 Donlea Drive", "Toronto", "ON", "M4G 2M4");
- var p1S1 = createBLSupplierDepartment(BLProject1, 1, "Elec Contractors1", "Jeff Martino");
- var p1S2 = createBLSupplierDepartment(BLProject1, 2, "Flooring Contractors2", "Jeff Martino");
- var p1S3 = createBLSupplierDepartment(BLProject1, 3, "Plumbing Contractors3", "Jeff Martino");
- var p1S4 = createBLSupplierDepartment(BLProject1, 4, "Paint Contractors4", "Jeff Martino");
- var p1S5 = createBLSupplierDepartment(BLProject1, 5, "HVAC Contractors5", "Jeff Martino");
- var p1S6 = createBLSupplierDepartment(BLProject1, 6, "Drywall Contractors6", "Jeff Martino");
- createBLSupplierDepartment(BLProject2, 7, "Elec Contractors1", "Jeff Martino");
- createBLSupplierDepartment(BLProject2, 8, "Tile and Hardwood Contractors2", "Jeff Martino");
- createBLSupplierDepartment(BLProject2, 9, "Plumbing Contractors3", "Jeff Martino");
- createBLSupplierDepartment(BLProject2, 10, "Paint Contractors4", "Jeff Martino");
- createBLSupplierDepartment(BLProject2, 11, "HVAC Contractors5", "Jeff Martino");
- createBLSupplierDepartment(BLProject2, 12, "Drywall Contractors6", "Jeff Martino");
- var p1Foyer = createBLRoom(BLProject1, 1, "Foyer");
- var p1Dinig = createBLRoom(BLProject1, 2, "Dining");
- var p1Living = createBLRoom(BLProject1, 3, "Living");
- var p1Stairs = createBLRoom(BLProject1, 4, "Stairs");
- var p1MasterBedroom = createBLRoom(BLProject1, 5, "Master Bedroom");
- var p1Bedroom2 = createBLRoom(BLProject1, 6, "Bedroom 2");
- var p1Bedroom3 = createBLRoom(BLProject1, 7, "Bedroom 3");
- var p1MainBathroom = createBLRoom(BLProject1, 8, "Main Bathroom");
- var p1EnsuiteBathroom = createBLRoom(BLProject1, 9, "Ensuite Bathroom");
- var p1Other = createBLDeficiencyType(BLProject1, 1, "Other", null);
- var p1Electrical = createBLDeficiencyType(BLProject1, 2, "Electrical", p1S1);
- var p1Flooring = createBLDeficiencyType(BLProject1, 3, "Flooring", p1S2);
- var p1Tile = createBLDeficiencyType(BLProject1, 4, "Tile", p1S2);
- var p1Hardwood = createBLDeficiencyType(BLProject1, 5, "Hardwood", p1S2);
- var p1Carpet = createBLDeficiencyType(BLProject1, 6, "Carpet", p1S2);
- var p1Plumbing = createBLDeficiencyType(BLProject1, 7, "Plumbing", p1S3);
- var p1Paint = createBLDeficiencyType(BLProject1, 8, "Paint", p1S4);
- var p1HVAC = createBLDeficiencyType(BLProject1, 9, "HVAC", p1S5);
- var p1Drywall = createBLDeficiencyType(BLProject1, 10, "Drywall", p1S6);
- createBLDeficiencyType(BLProject2, 11, "Other", -1);
- createBLDeficiencyType(BLProject2, 12, "Electrical", -1);
- createBLDeficiencyType(BLProject2, 13, "Flooring", -1);
- createBLDeficiencyType(BLProject2, 14, "Tile", -1);
- createBLDeficiencyType(BLProject2, 15, "Hardwood", -1);
- createBLDeficiencyType(BLProject2, 16, "Carpet", -1);
- createBLDeficiencyType(BLProject2, 17, "Plumbing", -1);
- createBLDeficiencyType(BLProject2, 18, "Paint", -1);
- createBLDeficiencyType(BLProject2, 19, "HVAC", -1);
- createBLDeficiencyType(BLProject2, 20, "Drywall", -1);
- createBLDeficiency(BLUnit201, p1Foyer, p1HVAC, "Fix something1", "PDI", "New", p1S1);
- createBLDeficiency(BLUnit202, p1Bedroom2, p1Electrical, "Broken Outlet", "Purchaser", "New", p1S2);
- createBLDeficiency(BLUnit201, p1Bedroom2, p1Tile, "Fix somethingafdfad", "Conciliation", "Finished", p1S2);
- createBLDeficiency(BLUnit201, p1Living, p1Hardwood, "Fix somethingbxvbxvbx", "Seasonal", "Deferred", p1S2);
- createBLDeficiency(BLUnit201, p1Living, p1HVAC, "Fix somethingyutuytutyu", "Construction", "New", p1S3);
- createBLDeficiency(BLUnit201, p1Stairs, p1Electrical, "Fix somethingklhklhjkl", "Inspection", "Sending", p1S1);
- createBLDeficiency(BLUnit201, p1MainBathroom, p1Plumbing, "Fix somethingmbnvmnmv", "PDI", "New", p1S5);
- createBLFormTemplate(BLProject1, "1", "PDI Report", "Description of some kind", "PDI REPORT\n\nProject: #Project.Name.99#\nUser: #User.Name1.99# #User.Name2.99# #User.Name3.99# #User.Name4.99#\nUnit: #Unit.Name.99##Unit.Name.99##Unit.Name.99##System.Date# Some more text\nClosingDate: #Unit.Buyer Closing Date.99#\nEnd \nUnit: #Unit.Name.99# of PDI Report\nUnit: #Unit.Name.99#\nProject: #User.Name1.99# #User.Name2.99# #User.Name3.99# #User.Name4.99#\n\n");
- persistence.flush(function(err) {
- console.log("Done Flushing!");
- persistence.dump(null, [BLProject], function(dump) {
- console.log("DUMP START1");
- console.log(dump);
- console.log("DUMP DONE1");
- });
- // createEventHandlers();
- //setupHomePageProjects();
- // testFillReport();
- });
- }*/
- //End of trial DB function
- function createBLUnit(blProject, remoteID, name, buyerClosingDate, municipalAddress, city, tarionEnrollmentNumber) {
- var newUnit = new BLUnit({RemoteID: remoteID, Name: name, BuyerClosingDate: buyerClosingDate, MunicipalAddress: municipalAddress, City: city, TarionEnrollmentNumber: tarionEnrollmentNumber});
- blProject.BLUnits.add(newUnit);
- persistence.add(newUnit);
- return newUnit;
- }
- function createBLUser(blProject, blUnit, remoteID, name1, name2, phone1, phone2, email, street, city, province, postalCode) {
- if (remoteID == 685438) {
- console.log(remoteID);
- }
- var newUser = new BLUser({RemoteID: remoteID, Name1: name1, Name2: name2, Phone1: phone1, Phone2: phone2, Email: email, Street: street, City: city, Province: province, PostalCode: postalCode});
- if (blUnit != null) {
- blUnit.BLUser = newUser;
- newUser.BLUnit = blUnit;
- }
- newUser.BLProject = blProject;
- persistence.add(newUser);
- return newUser;
- }
- function createBLRoom(blProject, remoteID, name) {
- var newRoom = new BLRoom({RemoteID: remoteID, Name: name});
- blProject.BLRooms.add(newRoom);
- persistence.add(newRoom);
- return newRoom;
- }
- function createBLDeficiencyType(blProject, remoteID, name, supplierDepartment) {
- var newDefType = new BLDeficiencyType({RemoteID: remoteID, Name: name, BLDefaultSupplierDepartment: supplierDepartment});
- blProject.BLDeficiencyTypes.add(newDefType);
- newDefType.BLSupplierDepartment = supplierDepartment;
- persistence.add(newDefType);
- /*for (i = 1; i < 10; i ++) {
- // createBLDeficiencyTypeDescription(blProject, newDefType, remoteID * 10, "Description " + i + name);
- }
- return newDefType;*/
- }
- /*function createBLDeficiencyTypeDescription(blProject, blDeficiencyType, remoteID, description) {
- var newDefTypeDesc = new BLDeficiencyTypeDescription({RemoteID: remoteID, Description: description});
- blDeficiencyType.BLDeficiencyTypeDescriptions.add(newDefTypeDesc);
- persistence.add(newDefTypeDesc);
- return newDefTypeDesc;
- }*/
- function createBLSupplierDepartment(blProject, remoteID, companyName, contactName) {
- var newSD = new BLSupplierDepartment({RemoteID: remoteID, CompanyName: companyName, ContactName: contactName});
- blProject.BLSupplierDepartments.add(newSD);
- persistence.add(newSD);
- return newSD;
- }
- function createBLFormTemplate(blProject, remoteID, title, description, text) {
- var newFT = new BLFormTemplate({RemoteID: remoteID, Title: title, Description: description, Text: text});
- blProject.BLFormTemplates.add(newFT);
- persistence.add(newFT);
- return newFT;
- }
- //blPic ALLA FINE DA CANCELLARE SE NON FUNZIONA, AGGIUNGERE blPic ALLA FINE DELLA PRIMA RIGA QUANDO DI PROVA
- function createBLDeficiency(blUnit, blRoom, blDeficiencyType, description, source, status, blSupplierDepartment) {
- var newDeficiency = new BLDeficiency({Description: description, Source: source, Status: status, Saved: true});
- newDeficiency.BLUnit = blUnit;
- newDeficiency.BLProject = blUnit.BLProject;
- newDeficiency.BLRoom = blRoom;
- newDeficiency.BLDeficiencyType = blDeficiencyType;
- newDeficiency.BLSupplierDepartment = blSupplierDepartment;
- //NEXT LINE DA ELIMINARE SE NON VA
- //newDeficiency.BLPic = blPic
- persistence.add(newDeficiency);
- return newDeficiency;
- }
- function logDatabaseStatus() {
- console.log("***DATABASE STATUS***");
- console.log("DatabaseName: " + SQLDatabaseName);
- console.log("SQLErrors : " + SQLErrors);
- console.log("***DATABASE STATUS***");
- }
- function setupHomePageProjects() {
- $('#PageHomeListProject').empty();
- BLProject.all().list(function (projects) {
- projects.forEach(function (project) {
- $('#PageHomeListProject').append($('<li/>', {
- 'data-theme': "a"}).append($('<a/>', {
- 'href': 'index.html#PageProject',
- 'data-transition': 'slide',
- 'class': 'projectButton',
- 'projectID': project.id,
- 'text': project.Name
- })));
- });
- $("#PageHomeListProject").listview('refresh');
- console.log(BLProject);
- });
- }
- function setupProjectPage(projectID) {
- BLProject.load(projectID, function(project) {
- // If different project, then blank out list first
- if ($("#PageProjectProjectName").text() != project.Name) {
- $("#PageProjectProjectName").html(project.Name);
- document.BLProject = project;
- console.log("BLProject.BLUser: " + BLProject.BLUser);
- var projects = BLProject.all().filter("id", '=', project.id).prefetch("BLUser");
- projects.list(null, function(results, err) {
- if (results) {
- var blp = results[0];
- var blu = blp.BLUser;
- if (blu != null) {
- $("#PageProjectUserInfo").html(blu.Name1 + " " + blu.Name2);
- }
- }
- });
- // BLUser.load(BLProject.BLUser, function(blUser) {
- // if (blUser != null) {
- // $("#PageProjectUserInfo").html(blUser.Name1 + " " + blUser.Name2);
- // }
- // });
- $('#PageProjectListUnit').empty();
- var units = BLUnit.all().filter("BLProject", '=', projectID);
- units.list(null, function(results, err) {
- if (results) {
- for (i = 0; i < results.length; i ++) {
- unit = results[i];
- $('#PageProjectListUnit').append($('<li/>', {
- 'data-theme': "a"}).append($('<a/>', {
- 'href': 'index.html#PageUnit',
- 'class': 'unitButton',
- 'data-transition': 'slide',
- 'unitID' : unit.id,
- 'text': unit.Name
- })));
- console.log(unit.Name);
- }
- $("#PageProjectListUnit").listview('refresh');
- } else {
- console.log("no units");
- }
- });
- }
- });
- }
- function setupUnitPage(unitID) {
- console.log("Parameter unitID=" + unitID);
- BLUnit.load(unitID, function(unit) {
- document.BLUnit = unit;
- if ($("#PageUnitUnitName").text() != unit.Name) {
- $("#PageUnitUnitName").html(unit.Name);
- // $("#PageUnitUnitName2").html(unit.Name);
- $("#PageUnitUnitBuyerClosingDate").html(unit.BuyerClosingDate != null ? unit.BuyerClosingDate : "N/A");
- $("#PageUnitUnitPurchaseDate").html(unit.PurchaseDate != null ? unit.PurchaseDate : "N/A");
- $("#PageUnitUnitOccupancyDate").html(unit.OccupancyDate != null ? unit.OccupancyDate : "N/A");
- $("#PageUnitUnitMunicipalAddress").html(unit.MunicipalAddress != null ? unit.MunicipalAddress : "N/A");
- $("#PageUnitUnitCity").html(unit.City != null ? unit.City : "N/A");
- $("#PageUnitUnitModel").html(unit.Model != null ? unit.Model : "N/A");
- $("#PageUnitUnitCode").html(unit.Code != null ? unit.Code : "N/A");
- $("#PageUnitUnitTarion").html(unit.Tarion != null ? unit.Tarion : "N/A");
- BLUser.findBy("BLUnit", unit.id, function(purchaser) {
- if (purchaser) {
- $("#PageUnitPurchaserName").text(purchaser.Name1 + " " + purchaser.Name2 + ", " + purchaser.Name3 + " " + purchaser.Name4);
- $("#PageUnitPurchaserPhone1").html(purchaser.Phone1 != null ? purchaser.Phone1 : "N/A");
- $("#PageUnitPurchaserPhone2").html(purchaser.Phone2 != null ? purchaser.Phone2 : "N/A");
- $("#PageUnitPurchaserEmail").html(purchaser.Email != null ? purchaser.Email : "N/A");
- $("#PageUnitPurchaserStreet").html(purchaser.Street != null ? purchaser.Street : "N/A");
- $("#PageUnitPurchaserCity").html(purchaser.City != null ? purchaser.City : "N/A");
- $("#PageUnitPurchaserProvince").html(purchaser.Province != null ? purchaser.Province : "N/A");
- $("#PageUnitPurchaserPostalCode").html(purchaser.PostalCode != null ? purchaser.PostalCode : "N/A");
- }
- });
- $('#PageUnitGridDeficiencies').empty();
- var defs = BLDeficiency.all().filter("BLUnit", '=', unit.id).prefetch("BLRoom").prefetch("BLDeficiencyType");
- defs.list(null, function(results, err) {
- if (results) {
- defsTable = $('#PageUnitGridDeficiencies');
- defsTable.append($('<thead/>')).append(
- $('<tr/>', {'class': 'blBold'}).append(
- $('<td/>', {'class': 'blBold'}).text('View')
- , $('<td/>', {'class': 'blBold'}).text('Room')
- , $('<td/>', {'class': 'blBold'}).text('Type')
- , $('<td/>', {'class': 'blBold'}).text('Description')
- , $('<td/>', {'class': 'blBold'}).text('Source')
- , $('<td/>', {'class': 'blBold'}).text('Status')
- , $('<td/>', {'class': 'blBold'}).text('Supplier')
- ));
- for (i = 0; i < results.length; i ++) {
- def = results[i];
- pageUnitGridDeficienciesDeficiencyAppend(def, i);
- }
- } else {
- console.log("no defs");
- }
- $('#PageUnitButtonAddDeficiency').attr('href', "index.html#PageModifyDeficiency").attr('class', 'addDeficiencyButton').attr('unitID', unit.id);
- // $('#PageUnitGridDeficiencies').append($('<div/>', {'class': "grid_12"}).append($('<a/>', {
- // 'href': 'index.html#PageModifyDeficiency?unitID=' + unit.id,
- // 'id': 'PageUnitButtonAddDeficiency',
- // 'data-transition': 'slide',
- // 'text': 'Add Deficiency'
- // })));
- $("#PageUnitButtonAddDeficiency").trigger("create");
- });
- }
- });
- }
- function createEventHandlers() {
- console.log("createEventHandlers");
- // Setup for jqm.page.params.js plugin
- $(document).bind("pagebeforechange", function( event, data ) {
- $.mobile.pageData = (data && data.options && data.options.pageData) ? data.options.pageData : null;
- });
- $( document ).bind( "mobileinit", function() {
- // Make your jQuery Mobile framework configuration changes here!
- $.support.cors = true;
- $.mobile.allowCrossDomainPages = true;
- });
- $(document).on("vclick", ".projectButton", function() {
- setupProjectPage($(this).attr("projectID"));
- });
- $(document).on("vclick", ".unitButton", function() {
- setupUnitPage($(this).attr("unitID"));
- });
- $(document).on("vclick", ".addDeficiencyButton", function() {
- // setupDeficiencyPage($(this).attr("unitID"));
- pageModifyDeficiencyActivate($(this).attr("unitID"), null);
- });
- $("#PageProjectSync").on("pageshow", function(e, data){
- console.log("1111PageSync.Project=" + document.BLProject);
- console.log(document.BLProject.Domain);
- if (document.BLProject != null) {
- console.log("PageSync.Project=" + document.BLProject);
- console.log("PageSync.ProjectName=" + document.BLProject.Name);
- $("#PageProjectSyncProjectName").html(document.BLProject.Name);
- $("#PageProjectSyncDomain").val(document.BLProject.Domain);
- var defsToSync = BLDeficiency.all().filter("RemoteID", '=', "0").filter("BLProject", '=', document.BLProject.id).prefetch("BLRoom").prefetch("BLDeficiencyType");
- defsToSync.list(null, function(results, err) {
- if (results) {
- var objects = "Deficiencies: " + results.length;
- $("#PageProjectSyncObjectCountText").val(objects);
- }
- });
- var projects = BLProject.all().filter("id", '=', document.BLProject.id).prefetch("BLUser");
- projects.list(null, function(results, err) {
- if (results) {
- var blp = results[0];
- var blu = blp.BLUser;
- if (blu != null) {
- $("#PageProjectSyncUsername").val(blu.Username);
- $("#PageProjectSyncPassword").val(blu.Password);
- }
- }
- });
- }
- });
- $("#PageUnit").on("pageshow", function(e, data){
- });
- $("#PageModifyDeficiency").on("pageshow", function(e, data){
- console.log("View link has been here");
- if ($.mobile.pageData && $.mobile.pageData.unitID){
- console.log("Parameter unitID=" + $.mobile.pageData.unitID);
- console.log("Parameter unitID=" + $.mobile.pageData.deficiencyID);
- pageModifyDeficiencyActivate($.mobile.pageData.unitID, $.mobile.pageData.deficiencyID);
- }
- //console.log(JSON.stringify(deficiency));
- });
- $(document).delegate(".ui-page","pagebeforehide", function(evt, ui){
- // alert('pagebeforehide fired');
- });
- $("index.html#PageModifyDeficiency").on("pagecontainerbeforechange", function(e, data){
- var deficiency = document.BLDeficiency;
- console.log("Save triggered");
- if (deficiency != null) {
- if ( ! deficiency.Saved) {
- persistence.remove(deficiency);
- persistence.flush();
- }
- }
- });
- }
- var blankCellValue = "<div> </div>";
- function pageUnitGridDeficienciesDeficiencyAppend (deficiency, row) {
- defsTable = $('#PageUnitGridDeficiencies tbody');
- defsTable.append($('<tr>', {'class': 'blTR'}).append(
- $('<td/>', {'class': 'blTD'}).append($('<a/>', {'class': 'button',
- 'href': 'index.html#PageModifyDeficiency?deficiencyID=' + deficiency.id + '&unitID=' + deficiency.BLUnit.id,
- 'data-transition': 'slide', 'data-role': 'link', 'name': 'PageModifyDeficiencyLink',
- 'text': 'View'
- }))
- , $('<td/>', {'class': 'blTD', 'id': "Deficiency_" + deficiency.id + "_Room"}).html(deficiency.BLRoom != null ? deficiency.BLRoom.Name : blankCellValue)
- , $('<td/>', {'class': 'blTD', 'id': "Deficiency_" + deficiency.id + "_DeficiencyType"}).html(deficiency.BLDeficiencyType != null ? deficiency.BLDeficiencyType.Name : blankCellValue)
- , $('<td/>', {'class': 'blTD', 'id': "Deficiency_" + deficiency.id + "_Description"}).html(deficiency.Description)
- , $('<td/>', {'class': 'blTD', 'id': "Deficiency_" + deficiency.id + "_Source"}).html(deficiency.Source)
- , $('<td/>', {'class': 'blTD', 'id': "Deficiency_" + deficiency.id + "_Status"}).html(deficiency.Status)
- , $('<td/>', {'class': 'blTD', 'id': "Deficiency_" + deficiency.id + "_SupplierDepartment"}).html(deficiency.BLSupplierDepartment != null ? deficiency.BLSupplierDepartment.CompanyName : blankCellValue)
- //, $('<td/>', {'class': 'blTD', 'id': "Deficiency_" + deficiency.id + "_ImageGallery"}).html(deficiency.ImageGallery)
- //, $('<td/>', {'class': 'blTD', 'id': "Deficiency_" + deficiency.id + "_ImageTaken"}).html(deficiency.ImageTaken)
- )).trigger('create');
- }
- function pageUnitGridDeficienciesDeficiencyUpdate (deficiency) {
- $('#Deficiency_' + deficiency.id + "_Room").html(deficiency.BLRoom != null ? deficiency.BLRoom.Name : blankCellValue);
- $('#Deficiency_' + deficiency.id + "_DeficiencyType").html(deficiency.BLDeficiencyType != null ? deficiency.BLDeficiencyType.Name : blankCellValue);
- $('#Deficiency_' + deficiency.id + "_Description").html(deficiency.Description);
- $('#Deficiency_' + deficiency.id + "_Source").html(deficiency.Source);
- $('#Deficiency_' + deficiency.id + "_Status").html(deficiency.Status);
- $('#Deficiency_' + deficiency.id + "_SupplierDepartment").html(deficiency.BLSupplierDepartment != null ? deficiency.BLSupplierDepartment.CompanyName : blankCellValue);
- //$('#Deficiency_' + deficiency.id + "_ImageGallery").html(deficiency.ImageGallery);
- //$('#Deficiency_' + deficiency.id + "_ImageTaken").html(deficiency.ImageTaken);
- }
- //called on Add Deficiency or View (Modify) Deficiency
- var DeficiencySource = null;
- var DeficiencyStatus = null;
- function pageModifyDeficiencyActivate(unitID, deficiencyID) {
- BLUnit.load(unitID, function(unit) {
- var deficiency = null;
- if (deficiencyID == null) {
- deficiency = new BLDeficiency({BLUnit: unitID, BLProject: unit.BLProject, Saved: false});
- if (document.DeficiencySource != null) {
- deficiency.Source = document.DeficiencySource;
- }
- if (document.DeficiencyStatus != null) {
- deficiency.Status = document.DeficiencyStatus;
- }
- pageModifyDeficiencySetup(unit, deficiency);
- } else {
- BLDeficiency.load(deficiencyID, function(deficiency) {
- pageModifyDeficiencySetup(unit, deficiency);
- });
- }
- });
- }
- //Called when working on deficiencies
- function pageModifyDeficiencySetup(unit, deficiency) {
- // If different unit, then blank out list first (no need atm)
- // pageDeficiencyBlankForm();
- defId = deficiency.id;
- if (deficiency._new) {
- alert("Add a new deficiency!");
- $("#PageModifyDeficiencyUnitName").html(unit.Name + " Add Deficiency");
- } else {
- alert("View an existing deficiency!");
- $("#PageModifyDeficiencyUnitName").html(unit.Name + " Modify Deficiency");
- }
- $("#PageModifyDeficiencyUnitName").attr('persistenceID', unit.id);
- document.BLDeficiency = deficiency;
- $('#DeficiencyRoom').empty();
- addSelectOption("#DeficiencyRoom", "", "", deficiency.BLRoom == null ? "" : deficiency.BLRoom.id);
- var rooms = BLRoom.all().filter("BLProject", '=', unit.BLProject).order("Name", true);
- rooms.list(null, function(results, err) {
- if (results) {
- for (var i = 0; i < results.length; i ++) {
- room = results[i];
- addSelectOption("#DeficiencyRoom", room.id, room.Name, deficiency.BLRoom == null ? "" : deficiency.BLRoom.id);
- }
- $("#DeficiencyRoom").selectmenu("refresh", true);
- } else {
- console.log("no rooms");
- }
- });
- $('#DeficiencyType').empty();
- addSelectOption("#DeficiencyType", "", "", deficiency.BLDeficiencyType == null ? "" : deficiency.BLDeficiencyType.id);
- var defTypes = BLDeficiencyType.all().filter("BLProject", '=', unit.BLProject).order("Name", true);
- defTypes.list(null, function(results, err) {
- if (results) {
- for (var i = 0; i < results.length; i ++) {
- defType = results[i];
- addSelectOption("#DeficiencyType", defType.id, defType.Name, deficiency.BLDeficiencyType == null ? "" : deficiency.BLDeficiencyType.id);
- }
- $("#DeficiencyType").selectmenu("refresh", true);
- } else {
- console.log("no def types");
- }
- });
- $('#DeficiencyDescription').val(deficiency.Description);
- //$('#DeficiencyDescription').trigger("create");
- $('#DeficiencySource').val(deficiency.Source).attr('selected', true).siblings('option').removeAttr('selected');
- $('#DeficiencySource').selectmenu("refresh", true);
- $('#DeficiencyStatus').val(deficiency.Status).attr('selected', true).siblings('option').removeAttr('selected');
- $('#DeficiencyStatus').selectmenu("refresh", true);
- if ("True" == deficiency.ChargeBack) {
- $('#DeficiencyChargeBackYes').attr('checked', true).checkboxradio("refresh");
- $('#DeficiencyChargeBackNo').removeAttr('checked').checkboxradio("refresh"); ;
- } else {
- $('#DeficiencyChargeBackYes').removeAttr('checked').checkboxradio("refresh"); ;
- $('#DeficiencyChargeBackNo').attr('checked', true).checkboxradio("refresh"); ;
- }
- $('#DeficiencySupplier').empty();
- $('#DeficiencySupplierChargeBack').empty();
- addSelectOption("#DeficiencySupplier", "", "", deficiency.BLSupplierDepartment == null ? "" : deficiency.BLSupplierDepartment.id);
- addSelectOption("#DeficiencySupplierChargeBack", "", "", deficiency.BLSupplierDepartmentChargeBack == null ? "" : deficiency.BLSupplierDepartmentChargeBack.id);
- var supplierDepartments = BLSupplierDepartment.all().filter("BLProject", '=', unit.BLProject).order("CompanyName", true);
- supplierDepartments.list(null, function(results, err) {
- if (results) {
- for (i = 0; i < results.length; i ++) {
- supplierDepartment = results[i];
- addSelectOption("#DeficiencySupplier", supplierDepartment.id, supplierDepartment.CompanyName + " " + supplierDepartment.ContactName, deficiency.BLSupplierDepartment == null ? "" : deficiency.BLSupplierDepartment.id);
- addSelectOption("#DeficiencySupplierChargeBack", supplierDepartment.id, supplierDepartment.CompanyName + " " + supplierDepartment.ContactName, deficiency.BLSupplierDepartmentChargeBack == null ? "" : deficiency.BLSupplierDepartmentChargeBack.id);
- }
- $("#DeficiencySupplier").selectmenu("refresh", true);
- $("#DeficiencySupplierChargeBack").selectmenu("refresh", true);
- } else {
- console.log("no def types");
- }
- });
- $('#DeficiencySupplierChargeBack').empty();
- addSelectOption("#DeficiencySupplierChargeBack", "", "", deficiency.BLSupplierDepartmentChargeBack == null ? "" : deficiency.BLSupplierDepartmentChargeBack.id);
- var supplierDepartmentsChargeBack = BLSupplierDepartment.all().filter("BLProject", '=', unit.BLProject).order("CompanyName", true);
- supplierDepartments.list(null, function(results, err) {
- if (results) {
- for (i = 0; i < results.length; i ++) {
- supplierDepartment = results[i];
- addSelectOption("#DeficiencySupplierChargeBack", supplierDepartment.id, supplierDepartment.CompanyName + " " + supplierDepartment.ContactName, deficiency.BLSupplierDepartmentChargeBack == null ? "" : deficiency.BLSupplierDepartmentChargeBack.id);
- }
- $("#DeficiencySupplierChargeBack").selectmenu("refresh", true);
- } else {
- console.log("no def types");
- }
- });
- $('#DeficiencyImageTaken').prop('src','');
- $("#DeficiencyImageTaken").attr("src", deficiency.ImageTaken);
- $('#DeficiencyImageGallery').prop('src','');
- $("#DeficiencyImageGallery").attr("src", deficiency.ImageGallery);
- //MARIO
- //ciclo che mette le foto dinamicamente, problema, non distingue le deficiencies
- /*for (var j = 0; j < len; j += 1) {
- var imgDynamic = document.createElement('img');
- imgDynamic.src = '';
- imgDynamic.src = deficiency.ImageDynamic;
- //img.width = '100px'
- //img.height = '100px'
- // Append the image to the anchor and the anchor to the td
- document.getElementById($('#DynamicImage')).appendChild(imgDynamic);
- }*/
- console.log('id delle pictures sono: ' + deficiency.ImageDynamic);
- $('#DynamicPictureTaken').html('');
- //for (var j = 0; j < deficiency.ImageDynamic.length; j += 1) {
- for (var j in deficiency.ImageDynamic) {
- $('#DynamicPictureTaken').append('<img src="'+deficiency.ImageDynamic[j]+'" id="def' + defId + 'pic' + j+'" width=20% height =20%>');
- console.log("src= " +deficiency.ImageDynamic);
- }
- }
- function addSelectOption(elementID, value, text, valueToSelect) {
- $(elementID).append($('<option/>', {
- 'value': value,
- 'text': text}));
- if (valueToSelect == null) {
- valueToSelect = "";
- }
- // if (elementID == "#DeficiencyType") {
- // console.log(elementID + " '" + value + "' '" + text + "' =test: '" + valueToSelect + "' comp: " + (value == valueToSelect) );
- // }
- // if (value == valueToSelect) {
- // console.log("matched: " + elementID);
- // }
- if (value == "") {
- $(elementID).val(value).attr('data-placeholder', "true");
- }
- if (value == valueToSelect) {
- // console.log("*****" + elementID + ": " + value + " = " + valueToSelect);
- $(elementID).val(value).attr('selected', true).siblings('option').removeAttr('selected');
- }
- }
- //NEVER USED FUNCTION
- /*$('#DeficiencyType').click(function(e) {
- //$('#DeficiencyTypeDescription').empty();
- BLDeficiencyType.load($('#DeficiencyType').val(), function(deficiencyType) {
- if (deficiencyType.BLSupplierDepartment != null) {
- $('#DeficiencySupplier').val(deficiencyType.BLSupplierDepartment.id).attr('selected', true).siblings('option').removeAttr('selected');
- } else {
- $('#DeficiencySupplier').val("").attr('selected', true).siblings('option').removeAttr('selected');
- }
- $("#DeficiencySupplier").selectmenu("refresh", true);
- //var defTypeDescs = BLDeficiencyTypeDescription.all().filter("BLDeficiencyType", '=', deficiencyType.id);
- defTypeDescs.list(null, function(results, err) {
- if (results) {
- for (i = 0; i < results.length; i ++) {
- defTypeDesc = results[i];
- console.log(defTypeDesc.id);
- console.log(defTypeDesc.Description);*/
- /*$('#DeficiencyTypeDescription').append($('<option/>', {
- 'value': defTypeDesc.id,
- 'text': defTypeDesc.Description
- }));*/
- /*}
- //$("#DeficiencyTypeDescription").selectmenu("refresh", true);
- } else {
- console.log("no def type descs");
- }
- });
- });
- });*/
- /*$('#DeficiencyTypeDescription').click(function(e) {
- BLDeficiencyTypeDescription.load($('#DeficiencyTypeDescription').val(), function(deficiencyTypeDescription) {
- $('#DeficiencyDescription').append(" " + deficiencyTypeDescription.Description);
- });
- });*/
- //END NEVER USED FUNCTION
- $('#DeficiencyChargeBackYes').click(function(e) {
- $('#DeficiencySupplierChargeBack').val("");
- $('#DeficiencySupplierChargeBack').removeAttr("disabled");
- });
- $('#DeficiencyChargeBackNo').click(function(e) {
- $('#DeficiencySupplierChargeBack').val("");
- $('#DeficiencySupplierChargeBack').attr("disabled");
- });
- $('#PageModifyDeficiencyButtonSave').click(function(e) {
- var defUnit = $("#PageModifyDeficiencyUnitName").attr('persistenceID');
- BLUnit.load(defUnit, function(unit) {
- var defPicDynamic = [];
- var defProject = unit.BLProject;
- var defRoom = $('#DeficiencyRoom').val();
- var defType = $('#DeficiencyType').val();
- var defDesc = $('#DeficiencyDescription').val();
- var defSource = $('#DeficiencySource').val();
- var defStatus = $('#DeficiencyStatus').val();
- var defSupplier = $('#DeficiencySupplier').val();
- var defChargeBack = $('input[name*=DeficiencyChargeBack]:checked').val();
- var defSupplierChargeBack = $('#DeficiencySupplierChargeBack').val();
- var defPicGallery = $("#DeficiencyImageGallery").attr("src");
- var defPicTaken = $("#DeficiencyImageTaken").attr("src");
- //var defPicDynamic = $("#index" + index).attr("src");
- for (var j = 0; j < len; j += 1) {
- /*defPicDynamic [j] = document.getElementById('index' + j).src;
- console.log(defPicDynamic[j]);*/
- defPicDynamic[j] = document.getElementById('def' + defId + 'pic' + j).src;
- }
- console.log("defProject: " + defProject);
- console.log("defUnit: " + defUnit);
- console.log("defRoom: " + defRoom);
- console.log("defType: " + defType);
- console.log("defDesc: " + defDesc);
- console.log("defSource: " + defSource);
- console.log("defStatus: " + defStatus);
- console.log("defSupplier: " + defSupplier);
- console.log("defChargeBack: " + defChargeBack);
- console.log("defSupplierChargeBack: " + defSupplierChargeBack);
- console.log("defPicGallery: " + defPicGallery);
- console.log("defPicTaken: " + defPicTaken);
- console.log("defPicDynamic: " + defPicDynamic);
- document.DeficiencySource = defSource;
- document.DeficiencyStatus = defStatus;
- //document.DeficiencyImageGallery = defPicGallery;
- //document.DeficiencyImageTaken = defPicTaken;
- var deficiency = document.BLDeficiency;
- deficiency.ImageDynamic = [];
- if (deficiency != null) {
- deficiency.BLProject = defProject;
- deficiency.BLUnit = defUnit;
- deficiency.BLRoom = defRoom;
- deficiency.BLDeficiencyType = defType;
- deficiency.Description = defDesc;
- deficiency.Source = defSource;
- deficiency.Status = defStatus;
- deficiency.BLSupplierDepartment = defSupplier;
- deficiency.BLSupplierDepartmentChargeBack = defSupplierChargeBack;
- if (defChargeBack != null) {
- deficiency.ChargeBack = defChargeBack;
- }
- deficiency.ImageGallery = defPicGallery;
- deficiency.ImageTaken = defPicTaken;
- deficiency.ImageDynamic = defPicDynamic;
- //console.log("sto salvando" +deficiency.ImageDynamic);
- var saved = deficiency.Saved;
- deficiency.Saved = true;
- persistence.add(deficiency);
- console.log("sto salvando" +deficiency);
- console.log(JSON.stringify(deficiency));
- persistence.flush();
- if ( ! saved) {
- pageUnitGridDeficienciesDeficiencyAppend(deficiency);
- } else {
- pageUnitGridDeficienciesDeficiencyUpdate(deficiency);
- }
- }
- });
- });
- $('#PageModifyDeficiencyButtonCancel').click(function(e) {
- var deficiency = document.BLDeficiency;
- if (deficiency != null) {
- if ( ! deficiency.Saved) {
- persistence.remove(deficiency);
- persistence.flush();
- }
- }
- // $.mobile.changePage("index.html#PageUnit", { transition: "slideup"} );
- });
- $("#SetupButton").click(function(e) {
- e.preventDefault();
- //alert("SetupButton is clicked");
- $.mobile.changePage("index.html#PageSetup", { transition: "slideup"} );
- return false;
- });
- $("#PageSetupDownloadProject").click(function (e) {
- e.preventDefault();
- domain = $("#PageSetupDomain").val();
- username = $("#PageSetupUsername").val();
- password = $("#PageSetupPassword").val();
- details = $("#PageSetupDetails");
- details.append("Starting Download\n");
- details.append("Domain: " + domain + "\n");
- details.append("Username: " + username + "\n");
- details.append("Password: " + password + "\n");
- details.append("Calling Authentication\n");
- console.log(domain + ", " + username + ", " + password);
- $.getJSON("http://" + domain + "/cc/tablet/UserTestPassword.jsp", {UserName: username, Password: password}, function(data) {
- // alert(data.AuthenticationRequestResult);
- console.log(data);
- console.log(data.AuthenticationPassword);
- console.log(data.AuthenticationUsername);
- console.log(data.AuthenticationRequestResult);
- details.append("AuthenticationRequestResult: '" + data.AuthenticationRequestResult + "'\n");
- if ("Successful Login" == data.AuthenticationRequestResult) {
- details.append("Get Project Info\n");
- $.getJSON("http://" + domain + "/cc/tablet/GetProject.jsp", {UserName: username, Password: password}, function(data) {
- try {
- details.append("Got Project Info\n");
- // alert("Name: " + data.Properties[3].Value);
- var projectP = propertiesToObject(data.Properties);
- details.append("ProjectName: " + projectP.Name + "'\n");
- details.append("ProjectID: " + projectP.ID + "'\n");
- var blProject = new BLProject({RemoteID: projectP.ID, Name: projectP.Name, Plan: projectP.Plan, CompanyName: projectP.CompanyName, TarionRegistrationNumber: projectP.TarionRegistrationNumber, Municipality: projectP.Municipality});
- blProject.Domain = domain;
- persistence.add(blProject);
- persistence.flush(null, function(err) {
- details.append("Storing Project\n");
- console.log("Done Flushing!");
- details.append("Updating Project List\n");
- setupHomePageProjects();
- details.append("Downloading Supplier Departments\n");
- downloadProjectSupplierDepartments(blProject);
- });
- } catch (ex) {
- alert(ex);
- }
- });
- }
- });
- });
- function propertiesToObject(properties) {
- var obj = new Object();
- for (i = 0; i < properties.length; i ++) {
- obj[properties[i].Name] = properties[i].Value;
- }
- // console.log(obj);
- return obj;
- }
- var BatchSize = 3;
- function downloadProjectSupplierDepartments(blProject) {
- alert("Downloading Supplier Departments (1/7)");
- details = $("#PageSetupDetails");
- details.append("SupplierDepartment Sending JSON Request\n");
- $.getJSON("http://" + domain + "/cc/tablet/GetSupplierDepartments.jsp", {}, function(data) {
- console.log(JSON.stringify(data));
- console.log(data);
- try {
- details.append("SupplierDepartment Processing Response\n");
- var supplierDepartments = data.SupplierDepartments;
- details.append("Records: " + supplierDepartments.length + "\n");
- processSupplierDepartments(blProject, supplierDepartments, 0);
- } catch (ex) {
- alert(ex);
- }
- });
- }
- function processSupplierDepartments(blProject, supplierDepartments, startFrom) {
- var addedObjects = false;
- for (var i = startFrom; i < supplierDepartments.length && i < startFrom + BatchSize; i ++) {
- po = supplierDepartments[i];
- sdp = propertiesToObject(po.Properties);
- //console.log(sdp);
- blSupplierDepartment = createBLSupplierDepartment(blProject, sdp.ID, sdp.CompanyName, sdp.ContactName);
- blSupplierDepartment.Phone1 = sdp.OfficePhone;
- blSupplierDepartment.Phone1 = sdp.MobilePhone;
- blSupplierDepartment.Email = sdp.Email;
- if (i % 10 == 0) {
- details.append("SupplierDepartment Record " + i + " of " + supplierDepartments.length + "\n");
- }
- addedObjects = true;
- }
- details.append("SupplierDepartment Done Creating Objects\n");
- if (addedObjects) {
- persistence.flush(null, function(err) {
- if (err != null) {
- // alert(err);
- }
- details.append("SupplierDepartment Done Flush\n");
- console.log("Done SupplierDepartments Flushing!");
- processSupplierDepartments(blProject, supplierDepartments, startFrom + BatchSize);
- });
- } else {
- //downloadProjectDeficiencyTypes(blProject);
- downloadProjectUnits(blProject);
- }
- }
- function downloadProjectDeficiencyTypes(blProject) {
- alert("Downloading Deficiency Types (3/7)");
- details = $("#PageSetupDetails");
- details.append("DeficiencyTypes Sending JSON Request\n");
- $.getJSON("http://" + domain + "/cc/tablet/GetDeficiencyTypes.jsp", {}, function(data) {
- try {
- details.append("DeficiencyTypes Processing Response\n");
- var defTypes = data.DeficiencyTypes;
- details.append("Records: " + defTypes.length + "\n");
- $("#PageSetupSliderRecords").attr("value", 0);
- $("#PageSetupSliderRecords").attr("max", defTypes.length);
- for (var i = 0; i < defTypes.length; i ++) {
- po = defTypes[i];
- dtp = propertiesToObject(po.Properties);
- sdid = dtp.SupplierDepartment;
- if (sdid != "-1") {
- ( function (dtp) {
- var sds = BLSupplierDepartment.all().filter("RemoteID", '=', dtp.SupplierDepartment);
- sds.list(null, function(results, err) {
- console.log("results: " + results.length);
- if (results && results.length > 0) {
- // alert("found Supplier Department");
- sd = results[0];
- var blDefType = createBLDeficiencyType(blProject, dtp.ID, dtp.Name, sd);
- }
- });
- })(dtp);
- } else {
- var blDefType = createBLDeficiencyType(blProject, dtp.ID, dtp.Name, null);
- }
- if (i % 10 == 0) {
- details.append("DeficiencyType Record " + i + " of " + defTypes.length + "\n");
- }
- }
- /*
- var names = new Array();
- var dtids = new Array();
- for (var i = 0; i < defTypes.length; i ++) {
- $("#PageSetupSliderRecords").attr("value", i);
- $("#PageSetupSliderRecords").attr("val", i);
- $("#PageSetupSliderRecords").slider("refresh", true);
- $("#PageSetupSliderRecords").slider();
- po = defTypes[i];
- dtp = propertiesToObject(po.Properties);
- sdid = dtp.SupplierDepartment;
- if (sdid != "-1") {
- var sds = BLSupplierDepartment.all().filter("RemoteID", '=', sdid);
- names[i] = dtp.Name;
- dtids[i] = dtp.ID;
- // Not sure why this query always returns nothing
- sds.list(null, function(results, err) {
- console.log("results: " + results.length);
- if (results && results.length > 0) {
- // alert("found Supplier Department");
- sd = results[0];
- var blDefType = createBLDeficiencyType(blProject, dtids[i], names[i], sd);
- }
- });
- } else {
- var blDefType = createBLDeficiencyType(blProject, dtp.ID, dtp.Name, null);
- }
- if (i % 10 == 0) {
- details.append("DeficiencyType Record " + i + " of " + defTypes.length + "\n");
- }
- }
- */
- details.append("Deficiency Types Done Creating Objects\n");
- persistence.flush(null, function(err) {
- details.append("DeficiencyTypes Done Flush\n");
- console.log("Done DeficiencyTypes Flushing!");
- downloadProjectRooms(blProject);
- });
- } catch (ex) {
- alert(ex);
- }
- });
- }
- function downloadProjectUnits(blProject) {
- alert("Downloading Units (2/7)");
- details = $("#PageSetupDetails");
- details.append("Units Sending JSON Request\n");
- $.getJSON("http://" + domain + "/cc/tablet/GetUnits.jsp", {}, function(data) {
- try {
- details.append("Units Processing Response\n");
- var units = data.Units;
- details.append("Records: " + units.length + "\n");
- $("#PageSetupSliderRecords").attr("value", 0);
- $("#PageSetupSliderRecords").attr("max", units.length);
- for (var i = 0; i < units.length; i ++) {
- $("#PageSetupSliderRecords").attr("value", i);
- $("#PageSetupSliderRecords").attr("val", i);
- $("#PageSetupSliderRecords").slider("refresh", true);
- $("#PageSetupSliderRecords").slider();
- po = units[i];
- up = propertiesToObject(po.Properties);
- //console.log(sdp);
- var blUnit = createBLUnit(blProject, up.ID, up.Name, up.BuyerClosingDate, up.MunicipalAddress, up.City, up.TarionEnrollmentNumber);
- if (i % 10 == 0) {
- details.append("Unit Record " + i + " of " + units.length + "\n");
- }
- }
- details.append("Units Done Creating Objects\n");
- persistence.flush(null, function(err) {
- details.append("Units Done Flush\n");
- console.log("Done Units Flushing!");
- downloadProjectDeficiencyTypes(blProject);
- });
- } catch (ex) {
- alert(ex);
- }
- });
- }
- function downloadProjectRooms(blProject) {
- alert("Downloading Rooms (4/7)");
- details = $("#PageSetupDetails");
- details.append("Room Sending JSON Request\n");
- $.getJSON("http://" + domain + "/cc/tablet/GetRooms.jsp", {}, function(data) {
- try {
- details.append("Room Processing Response\n");
- var rooms = data.Rooms;
- details.append("Records: " + rooms.length + "\n");
- processRooms(blProject, rooms, 0);
- } catch (ex) {
- alert(ex);
- }
- });
- }
- function processRooms(blProject, rooms, startFrom) {
- var addedObjects = false;
- for (var i = startFrom; i < rooms.length && i < startFrom + BatchSize; i ++) {
- po = rooms[i];
- sdp = propertiesToObject(po.Properties);
- //console.log(sdp);
- blRoom = createBLRoom(blProject, sdp.ID, sdp.Name);
- if (i % 10 == 0) {
- details.append("Rooms Record " + i + " of " + rooms.length + "\n");
- }
- addedObjects = true;
- }
- details.append("Rooms Done Creating Objects\n");
- if (addedObjects) {
- persistence.flush(null, function(err) {
- if (err != null) {
- // alert(err);
- }
- details.append("Rooms Done Flush\n");
- console.log("Done Rooms Flushing!");
- processRooms(blProject, rooms, startFrom + BatchSize);
- });
- } else {
- downloadProjectUsers(blProject);
- }
- }
- function downloadProjectUsers(blProject) {
- alert("Downloading Users (5/7)");
- details = $("#PageSetupDetails");
- details.append("Users Sending JSON Request\n");
- $.getJSON("http://" + domain + "/cc/tablet/GetUsers.jsp", {}, function(data) {
- try {
- details.append("Users Processing Response\n");
- var users = data.Users;
- details.append("Records: " + users.length + "\n");
- processUsers(blProject, users, 0, 1);
- } catch (ex) {
- alert(ex);
- }
- });
- }
- function processUsers(blProject, users, startFrom, batchSize) {
- var addedObjects = false;
- var username = $("#PageSetupUsername").val();
- var password = $("#PageSetupPassword").val();
- for (var i = startFrom; i < users.length && i < startFrom + batchSize; i ++) {
- po = users[i];
- sdp = propertiesToObject(po.Properties);
- var trid = sdp.TreeRootID;
- if (sdp.ID == 685438) {
- console.log(trid);
- }
- var st = sdp.ID + " " + sdp.UserName;
- console.log(st);
- var sds = BLUnit.all().filter("RemoteID", '=', trid);
- // Not sure why this query always returns nothing
- sds.list(null, function(results, err) {
- if (sdp.ID == 685438) {
- console.log(trid);
- }
- // console.log("results: " + results.length);
- var unit = null;
- if (results && results.length > 0) {
- // alert("found Supplier Department");
- unit = results[0];
- }
- var blUser = createBLUser(blProject, unit, sdp.ID, sdp.Name1, sdp.Name2, sdp.HomePhone, sdp.CellPhone, sdp.Email, sdp.StreetAddress, sdp.City, sdp.Province, sdp.PostalCode);
- blUser.Name3 = sdp.Name3;
- blUser.Name4 = sdp.Name4;
- blUser.Username = sdp.UserName;
- blUser.Password = sdp.Password;
- if (username == blUser.Username) {
- blProject.BLUser = blUser;
- }
- var st2 = blUser.RemoteID + " " + blUser.Username;
- console.log(st2);
- });
- if (i % 10 == 0) {
- details.append("Users Record " + i + " of " + users.length + "\n");
- }
- addedObjects = true;
- }
- details.append("Users Done Creating Objects\n");
- if (addedObjects) {
- persistence.flush(null, function(err) {
- if (err != null) {
- // alert(err);
- }
- details.append("Users Done Flush\n");
- console.log("Done Users Flushing!");
- processUsers(blProject, users, startFrom + batchSize, batchSize);
- });
- } else {
- //alert("All Done Downloading");
- downloadProjectFormTemplates(blProject);
- }
- }
- function downloadProjectFormTemplates(blProject) {
- alert("Downloading FormTemplates (6/7)");
- details = $("#PageSetupDetails");
- details.append("FormTemplates Sending JSON Request\n");
- $.getJSON("http://" + domain + "/cc/tablet/GetFormTemplates.jsp", {}, function(data) {
- try {
- details.append("FormTemplates Processing Response\n");
- var records = data.FormTemplates;
- details.append("Records: " + records.length + "\n");
- processFormTemplates(blProject, records, 0, 1);
- } catch (ex) {
- alert(ex);
- }
- });
- }
- function processFormTemplates(blProject, records, startFrom, batchSize) {
- var addedObjects = false;
- for (var i = startFrom; i < records.length && i < startFrom + batchSize; i ++) {
- po = records[i];
- sdp = propertiesToObject(po.Properties);
- var blFormTemplate = createBLFormTemplate(blProject, sdp.ID, sdp.Title, sdp.Description, sdp.Text);
- if (i % 10 == 0) {
- details.append("FormTemplates Record " + i + " of " + records.length + "\n");
- }
- addedObjects = true;
- }
- details.append("FormTemplates Done Creating Objects\n");
- if (addedObjects) {
- persistence.flush(null, function(err) {
- if (err != null) {
- // alert(err);
- }
- details.append("FormTemplates Done Flush\n");
- console.log("Done FormTemplates Flushing!");
- processFormTemplates(blProject, records, startFrom + batchSize, batchSize);
- });
- } else {
- alert("All Done Downloading (7/7)");
- //downloadProjectUnits(blProject);
- }
- }
- $("#PageProjectSyncProject").click(function (e) {
- e.preventDefault();
- domain = $("#PageProjectSyncDomain").val();
- username = $("#PageProjectSyncUsername").val();
- password = $("#PageProjectSyncPassword").val();
- details = $("#PageProjectSyncDetails");
- if ("" == domain) {
- alert("Domain can not be blank");
- return;
- }
- if ("" == username) {
- alert("Username can not be blank");
- return;
- }
- if ("" == password) {
- alert("Password can not be blank");
- return;
- }
- details.append("Starting Sync\n");
- details.append("Domain: " + domain + "\n");
- details.append("Username: " + username + "\n");
- details.append("Password: " + password + "\n");
- details.append("Calling Authentication\n");
- var hash = true;
- if (password.length != 32) {
- hash = false;
- }
- console.log(domain + ", " + username + ", " + password);
- $.post("http://" + domain + "/cc/tablet/UserTestPassword.jsp", {UserName: username, Password: password, Hash: hash}, function(data) {
- // alert(data.AuthenticationRequestResult);
- console.log(data);
- console.log(data.AuthenticationPassword);
- console.log(data.AuthenticationUsername);
- console.log(data.AuthenticationRequestResult);
- details.append("AuthenticationRequestResult: '" + data.AuthenticationRequestResult + "'\n");
- if ("Successful Login" == data.AuthenticationRequestResult) {
- details.append("Sending Deficiencies\n");
- var defsToSync = BLDeficiency.all().filter("RemoteID", '=', "0").filter("BLProject", '=', document.BLProject.id).prefetch("BLRoom").prefetch("BLDeficiencyType").prefetch("BLUnit").prefetch("BLSupplierDepartment");
- defsToSync.list(null, function(results, err) {
- if (results) {
- $("#PageProjectSyncSliderRecords").attr("value", 0);
- $("#PageProjectSyncSliderRecords").attr("max", results.length);
- console.log("Def Count: " + results.length);
- details.append("Deficiency Count: " + results.length + "\n");
- var countDefs = results.length;
- var countSent = 0;
- var countResult = 0;
- var countSuccess = 0;
- var countError = 0;
- for (var i = 0; i < results.length; i ++) {
- var def = results[i];
- details.append("Deficiency: " + i + " Sending\n");
- if (def.BLDeficiencyType == null) {
- persistence.remove(def);
- } else {
- $("#PageProjectSyncSliderRecords").attr("value", i);
- $("#PageProjectSyncSliderRecords").attr("val", i);
- $("#PageProjectSyncSliderRecords").slider("refresh", true);
- $("#PageProjectSyncSliderRecords").slider();
- var sdid = -1;
- if (def.BLSupplierDepartment != null) {
- sdid = def.BLSupplierDepartment.RemoteID;
- }
- countSent ++;
- //DEBUG
- console.log(JSON.stringify(def.BLUnit.RemoteID));
- console.log(def.Source);
- console.log(def.BLPicGallery);
- //END
- $.getJSON("http://" + domain + "/cc/tablet/UploadDeficiency.jsp",
- //$.getJSON("https://builderlynx-679b0.firebaseio.com/",
- {Description: def.Description,
- Source: def.Source,
- Status: def.Status,
- DeficiencyType: def.BLDeficiencyType.RemoteID,
- Room: def.BLRoom.RemoteID,
- Unit: def.BLUnit.RemoteID,
- SupplierDepartment: sdid,
- ImageGallery: def.ImageGallery,
- ImageTaken: def.ImageTaken,
- ImageDynamic: def.ImageDynamic},
- function(data) {
- //console.log(JSON.stringify(data));
- try {
- countResult ++;
- console.log("Deficiency: " + i + " Result\n");
- details.append("Deficiency: " + i + " Result\n");
- var defRemoteID = data.Deficiency[0].ID;
- details.append("Deficiency: " + i + " defRemoteID:" + defRemoteID + "\n");
- console.log("Deficiency: " + i + " defRemoteID:" + defRemoteID + "\n");
- def.RemoteID = defRemoteID;
- persistence.add(def);
- persistence.flush();
- countSuccess ++;
- console.log("After Flush: Success:" + countSuccess);
- if (i = results.length) {
- alert("Sync Finished. \n" +
- "Count Objects: " + countDefs + "\n" +
- "Count Sent : " + countSent + "\n" +
- "Count Result : " + countResult + "\n" +
- "Count Success: " + countSuccess + "\n" +
- "Count Error : " + countError + "\n");
- }
- } catch (ex) {
- countError ++;
- console.log(ex.toString());
- }
- //console.log(BLDeficiency);
- });
- }
- }
- }
- });
- }
- }, "json");
- });
- $("#PageSetupCreateSchema").click(function (e) {
- databaseCreateSchema(true, false, true);
- });
- $("#PageSetupSetupDemoProjects").click(function (e) {
- databaseCreateSchema(false, true, true);
- });
- //********************************************
- //Utils and testing functions
- //********************************************
- function syncTest() {
- console.log("Starting Sync Test");
- var sync = callWhenDone(function() { console.log("all jobs are done!"); });
- var endJob = function(){ console.log("one job ended"); sync(-1); };
- for (var i=0; i<10; ++i) {
- sync(+1);
- console.log("starting job: " + i);
- setTimeout(endJob, Math.random()*10000); // to replace with your async function
- }
- }
- /**
- * callWhenDone: a simple synchronized callback closure
- * @author adrienjoly
- */
- var callWhenDone = function(callback) {
- var counter = 0;
- return function (incr) {
- if (0 == (counter += incr))
- callback();
- };
- };
- // example use:
- //var sync = callWhenDone(function() { console.log("all jobs are done!"); });
- //var endJob = function(){ console.log("one job ended"); sync(-1); };
- //for (var i=0; i<10; ++i) {
- // sync(+1);
- // setTimeout(endJob, Math.random()*10000); // to replace with your async function
- //}
- //NEVER USED FUNCTIONS!!!
- function pSchemaSync() {
- var sync = callWhenDone(function() {
- console.log("done sync");
- });
- sync(+1);
- persistence.schemaSync(function(tx) {
- console.log("schema sync done");
- sync(-1);
- });
- }
- // Query the database
- //NEVER USED FUNCTIONS!!! ?
- function queryDB(tx) {
- tx.executeSql('SELECT * FROM BLUnit', [], querySuccess, errorCB);
- console.log("TEST");
- }
- // Query the success callback
- //
- function querySuccess(tx, results) {
- console.log("TEST");
- var len = results.rows.length;
- console.log("DEMO table: " + len + " rows found.");
- for (var i=0; i<len; i++){
- console.log("Row = " + i + " BLID = " + results.rows.item(i).BLID + " Data = " + results.rows.item(i).Name);
- }
- }
- // Transaction error callback
- //
- function errorCB(err) {
- console.log("TEST");
- SQLErrors ++;
- console.log("Error processing SQL: "+err.code + ": Message: " + err.message);
- }
- function nullCB() {
- console.log("TEST");
- SQLErrors ++;
- console.log("NullCallBack");
- }
- // Transaction success callback
- //
- function successCB() {
- console.log("TEST");
- if (SQLDatabase != null) {
- SQLDatabase.transaction(queryDB, errorCB);
- }
- logDatabaseStatus();
- }
- //END NEVER USED FUNCTION
- //NEVER USED FUNCTION!!! ?
- function getDatabaseObject(table, ID, jquerySelectorText) {
- SQLDatabase.transaction(
- function(transaction) {
- console.log("mess1: " + ID);
- transaction.executeSql(
- 'SELECT * FROM BLProject WHERE BLID = ?',
- [parseInt(ID)],
- function(transaction, result) {
- console.log("inner result: " + result.rows.length);
- if (result != null && result.rows != null) {
- for (var i = 0; i < result.rows.length; i++) {
- var row = result.rows.item(i);
- $(jquerySelectorText).html(row.Name);
- }
- }
- },
- errorCB
- );
- },
- errorCB,
- nullCB
- );
- }
- function applyFunctionToDatabaseObject(table, ID, functionToApply) {
- SQLDatabase.transaction(
- function(transaction) {
- console.log("mess1: " + ID);
- transaction.executeSql(
- 'SELECT * FROM ' + table + ' WHERE BLID = ?',
- [parseInt(ID)],
- functionToApply,
- errorCB
- );
- },
- errorCB,
- nullCB
- );
- }
- function applyFunctionToDatabaseResult(query, functionToApply) {
- SQLDatabase.transaction(
- function(transaction) {
- console.log("applyFunctionToDatabaseResult.query: " + query);
- transaction.executeSql(
- query,
- [],
- functionToApply,
- errorCB
- );
- },
- errorCB,
- nullCB
- );
- }
- function getDatabaseObjectSuccess(tx, results) {
- var len = results.rows.length;
- console.log("DEMO table: " + len + " rows found.");
- for (var i=0; i<len; i++){
- console.log("getDatabaseObject.Row = " + i + " ID = " + results.rows.item(i).ID + " Data = " + results.rows.item(i).Name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement