define(function (require, exports, module) { var ko = require("lib/knockout"); var util = require("viewModel/util"); function LocationViewModel(application) { /// <summary> /// The view model that backs the a search based on a location string /// </summary> // ----- framework fields this.factoryName = "LocationViewModel"; // ----- public fields // the string used to search the Nestoria APIs this.searchString = undefined; // this string displayed to the end-user this.displayString = undefined; this.totalResults = 0; // ----- framework functions this.initialise = function (searchString) { /// <summary> /// Initializes the state of this view model. /// </summary> this.searchString = searchString; this.displayString = searchString; }; this.initialiseDisambiguated = function (location) { /// <summary> /// Initializes the state of this view model via a location that has a 'display name' which is shown to the /// user, which differs from the name used to search the Nestoria APIs /// </summary> this.searchString = location.placeName; this.displayString = location.longTitle; }; this.executeSearch = function (pageNumber) { /// <summary> /// Executes a search by the search string represented by this view model for the given page /// </summary> return application.propertyDataSource.findProperties(this.searchString, pageNumber); }; } util.registerFactory("LocationViewModel", LocationViewModel); module.exports = LocationViewModel; });
define(function (require, exports, module) { var ko = require("lib/knockout"); var util = require("viewModel/util"); function LogInViewModel(application) { /// <summary> /// The 'top level' welcome view model. /// </summary> this.initialize = function() { console.log("initialize LogInViewModel") $('#emailtxt').focus(); } // ----- private fields var synchroniseSearchStrings = true, that = this; // ----- framework fields this.template = "loginViewModel"; this.factoryName = "LogInViewModel"; // ----- public fields this.user_name = ko.observable(); this.user_pass = ko.observable(); this.event_name = ko.observable(); this.initialize = function() { that.user_name( "" ); that.user_pass( "" ); } this.getData = function() { }; this.getData(); this.signin = function() { console.log(that.user_name()); window.localStorage.setItem('user_name', that.user_name()==null?"":that.user_name()); window.localStorage.setItem('user_pass', that.user_pass()==null?"":that.user_pass()); } } util.registerFactory("LogInViewModel", LogInViewModel); module.exports = LogInViewModel; });
define("viewModel/FavouritesViewModel", function (require) { var util = require("viewModel/util"); function FavouritesViewModel(propertySearchViewModel) { /// <summary> /// The view model that backs the favourites view /// </summary> // ----- framework fields this.template = "favouritesView"; this.factoryName = "FavouritesViewModel"; // ----- public fields this.properties = propertySearchViewModel.favourites; } util.registerFactory("FavouritesViewModel", FavouritesViewModel); return FavouritesViewModel; });
define(function(require, exports, module) { require("lib/i18next-1.6.3.min"); var ko = require("lib/knockout"); var util = require("viewModel/util"); var Challenge = require("model/Challenge"); function MissionListViewModel(application) { //this.factoryName = "MissionListViewModel"; this.missionListModel = new MissionListModel(application); this.initialize = function(mapViewModel, data) { this.missionListModel.initialize(mapViewModel); this.template = "missionListView" + data["@id"]; } } function MissionListModel(application) { // ----- private fields var synchroniseSearchStrings = true, that = this; that.application = application; // ----- framework fields this.backTxt = ko.observable($.t('ns.common:ctrl.back')); this.logoutTxt = ko.observable($.t('ns.common:ctrl.logout')); this.missionTxt = ko.observable($.t('ns.common:mission.mission')); if (application.whitelbl.appType == "timeTbl") { this.missionTxt($.t('ns.common:mission.general')); } this.showLogout = ko.observable(true); if (application.whitelbl.skipLogin === true) this.showLogout(false); this.headtitle = ko.observable(""); this.backButton = ko.observable("Back"); this.align = ko.observable(""); this.challengies = ko.observableArray([]); this.mission; this.mapViewModel; this.initialize = function(mapViewModel) { that.mapViewModel = mapViewModel; that.align(mapViewModel.align()); that.headtitle(mapViewModel.name()); that.challengies.removeAll(); //console.error (that.challengies().length + "<=" + mapViewModel.challengies.length); $.each(mapViewModel.challengies, function(key, data) { that.challengies.push(data); }); console.log("chalenges: " + that.challengies().length); } this.gotoMission = function(mission) { setTimeout(function() { that.mapViewModel.gotoMission(mission); }, 600); } this.logout = function() { window.localStorage.removeItem('user_name'); window.localStorage.removeItem('team_name'); that.application.user_name(""); that.application.team_name(""); that.application.navigateToHome(); } } util.registerFactory("MissionListViewModel", MissionListViewModel); module.exports = MissionListViewModel; });
Titanium.Geolocation.getCurrentPosition(successCallback); }; this.selectLocation = function () { /// <summary> /// A function that is invoked when a search location is clicked /// </summary> var location = this; synchroniseSearchStrings = false; that.searchLocation = location; that.searchDisplayString(location.displayString); synchroniseSearchStrings = true; that.locations.removeAll(); that.executeSearch(); }; this.viewFavourites = function () { /// <summary> /// Navigates to the favourites view /// </summary> application.navigateToFavourites(this.favourites); }; } util.registerFactory("PropertySearchViewModel", PropertySearchViewModel); module.exports = PropertySearchViewModel;
this.initialize = function (searchLocation, results) { this.properties(_.map(results.data, function (property) { var viewModel = new PropertyViewModel(application); viewModel.initialize(property); return viewModel; })); that.searchLocation(searchLocation); that.totalResults(results.totalResults); }; this.loadMore = function () { this.pageNumber(this.pageNumber() + 1); this.isLoading(true); this.searchLocation().executeSearch(this.pageNumber(), function (results) { that.isLoading(false); _.each(results.data, function (property) { var viewModel = new PropertyViewModel(application); viewModel.initialize(property); that.properties.push(viewModel); }); that.pageNumber(that.pageNumber() + 1); }); }; } util.registerFactory("SearchResultsViewModel", SearchResultsViewModel); module.exports = SearchResultsViewModel;
// ----- public fields this.lat = undefined; this.lon = undefined; this.displayString = undefined; this.totalResults = 0; // ----- public functions this.initialise = function (lat, lon) { /// <summary> /// Initializes the state of this view model. /// </summary> this.lat = lat; this.lon = lon; this.displayString = lat.toFixed(2) + ", " + lon.toFixed(2); }; this.executeSearch = function (pageNumber, callback, errorCallback) { /// <summary> /// Executes a search by the geolocation represented by this view model for the given page /// </summary> application.propertyDataSource.findPropertiesByCoordinate( this.lat, this.lon, pageNumber, callback, errorCallback); }; } util.registerFactory("GeolocationViewModel", GeolocationViewModel); module.exports = GeolocationViewModel;
define(function(require, exports, module) { var ko = require("lib/knockout"); var util = require("viewModel/util"); function ActivitiesViewModel(application) { console.log("new ActivitiesViewModel") // ----- private fields var synchroniseSearchStrings = true, that = this; var isloadactivity = false; var isShowedInfo = false; // ----- framework fields this.template = "activitiesView"; this.factoryName = "ActivitiesViewModel"; this.activitiesList = application.activitiesList; this.initialize = function(acts) { console.log("initialize ActivitiesViewModel") // that.activitiesList = acts; that.activitiesList.removeAll(); $.each(acts(), function(key, act) { console.log("push activity : " + key + " = " + act["align"]); that.activitiesList.push(act); }); } this.gotoInfoView = function() { application.navigateTo(application.viewModels.infoViewModel); }; $("#activitiesViewBack").click(function(event) { application.exitDialog(); }); this.getActivitylist_run = 0; this.getActivitylist = function() { if (that.getActivitylist_run === 1) { return; } that.getActivitylist_run = 1; setTimeout(function() { that.getActivitylist_run = 0; }); that.activitiesList.removeAll(); application.showLoader(); console.log("ActivitiesViewModel.getActivitylist"); align = "rtl"; { // if (navigator.globalization) { // navigator.globalization.getPreferredLanguage( // function (language) { // switch (language.value) { // case "עברית": // align = "rtl"; // break; // case "he": // align = "rtl"; // break; // default: // align = "ltr"; // } // }, // function () { // }); // } } $.post( application.builder_srv + "get_activities", "group=" + application.whitelbl.group, function(data, textStatus /* , jqXHR */ ) { that.ispreactivity = true; $.each( data, function(key, act) { act["@name"] = (typeof act["@name"] === "undefined" || act["@name"] == "") ? "" : act["@name"]; act["@type"] = (typeof act["@type"] === "undefined" || act["@type"] == "") ? "" : act["@type"]; act["@content_provider"] = (typeof act["@content_provider"] === "undefined" || act["@content_provider"] == "") ? "" : act["@content_provider"]; act["@image_url"] = (typeof act["@image_url"] === "undefined" || act["@image_url"] == "") ? application.builder_srv + "/javax.faces.resource/copy-icon.png.jsf?ln=images" : act["@image_url"]; console.log("push data into activities list "); // console.log(act["@id"]+" , "+act["@name"]+" , "+act["@type"]+" , "+act["@content_provider"]+" , "+act["@image_url"]+" , "+act["@align"]); that.activitiesList .push({ id: act["@id"], name: act["@name"], type: act["@type"], content_provider: act["@content_provider"], image_url: act["@image_url"], align: align }); window.localStorage.removeItem('activity_' + act["@id"]); }); }, "json") .fail( function(jqXHR, textStatus) { console.log(application.builder_srv + "get_initial_dat [post fail]"); console.log("Request failed: " + textStatus + ", \n" + jqXHR.responseText); }) .always(function() { application.hideLoader(); }); }; this.gotoActivity = function(act) { application.showLoader(); application.gotoActivity(act); } } //navigator.app.exitApp(); util.registerFactory("ActivitiesViewModel", ActivitiesViewModel); module.exports = ActivitiesViewModel; });
define(function(require, exports, module) { var ko = require("lib/knockout"); var util = require("viewModel/util"); function MissionMediaViewModel(application) { this.nohistory = true; that = this; this.missionMediaModel = new MissionMediaModel(application); this.missionMediaModel.viewModel = this; this.initialize = function(challenge) { this.template = "missionMediaView" + challenge.actInfo["parentId"] + "_" + challenge.actInfo["@index"]; this.missionMediaModel.initialize(challenge); } } function MissionMediaModel(application) { // ----- private fields var synchroniseSearchStrings = true, that = this; // ----- framework fields this.template = "missionMediaView"; this.backTxt = ko.observable($.t('ns.common:ctrl.back')); this.missionTxt = ko.observable($.t('ns.common:mission.mission')); if (application.whitelbl.appType == "timeTbl") { this.missionTxt($.t('ns.common:mission.general')); } this.infoTxt = ko.observable($.t('ns.common:mission.info')); this.mediaTxt = ko.observable($.t('ns.common:mission.media')); this.headtitle = ko.observable(""); this.mission = ko.observable(""); this.align = ko.observable(""); this.currentQuiz = ko.observable(""); this.enableDisableInfo = ko.observable("missionInfoEnable"); this.initialize = function(challenge) { $("#" + this.viewModel.template).on("pageshow", function(event, ui) { that.resetNav(); setTimeout(function() { that.fixHeight(); }, 100); }); this.missionViewModel = application.missionViewModels[challenge.actInfo["parentId"]][challenge.actInfo["@index"]]; this.missionInfoViewModel = application.missionInfoViewModels[challenge.actInfo["parentId"]][challenge.actInfo["@index"]]; //that.align ( mapViewModel.align() ); that.headtitle(challenge.actname()); that.mission(challenge); that.align(challenge.align()); // setting global application.challenge = challenge; if (challenge.info.text == "") { //$(".missTab12").addClass("missionInfoDisable"); this.enableDisableInfo("missionInfoDisable"); } else { //$(".missTab12").removeClass("missionInfoDisable"); this.enableDisableInfo("missionInfoEnable"); } } this.onNavTab1 = function() { application.navigateTo(that.missionViewModel); } this.onNavTab2 = function() { if (this.enableDisableInfo() == "missionInfoDisable") { $(".missTab33").addClass("ui-btn-active"); return; } application.navigateTo(that.missionInfoViewModel); } this.onNavTab3 = function() {} this.mediaClickHanlder = function() { console.log("mediaClickHanlder"); } this.resetNav = function() { $(".missTab31").removeClass("ui-btn-active"); $(".missTab32").removeClass("ui-btn-active"); $(".missTab33").addClass("ui-btn-active"); } this.fixHeight = function() { d = $(document) var w = $(".mediaImgWrapper", d).css("width"); $(".mediaImgWrapper", d).each(function() { if ($(this).attr("wasFixed") != "1") { $(this).attr("wasFixed", "1"); //$(this).css("height",w) // $("img", this).css("height", w); if ($(this).attr("category") == "video") { p = $(this) p.append('<img class="media_video_play" width="10" src="assets/image/play-button.png"></img>'); } } }); }; this.mediaClick = function() { //var url = $(this).attr("video_url"); var index = $(this).attr("index"); application.navigateToMediaSlideshow({ index: index, challenge: that.mission() }); } } util.registerFactory("MissionMediaViewModel", MissionMediaViewModel); module.exports = MissionMediaViewModel; });
define(function (require, exports, module) { var ko = require("lib/knockout"); var PropertySearchResponseCode = require("model/PropertySearchResponseCode"); var LocationViewModel = require("viewModel/LocationViewModel"); var GeolocationViewModel = require("viewModel/GeolocationViewModel"); var util = require("viewModel/util"); function PropertySearchViewModel(application) { /// <summary> /// The 'top level' property search view model. /// </summary> // ----- private fields var synchroniseSearchStrings = true, that = this; // ----- framework fields this.template = "propertySearchView"; this.factoryName = "PropertySearchViewModel"; // ----- public fields this.searchDisplayString = ko.observable(""); this.userMessage = ko.observable(); this.searchLocation = new LocationViewModel(application); this.isSearchEnabled = ko.observable(true); this.locationEnabled = ko.observable(true); this.locations = ko.observableArray(); this.recentSearches = application.recentSearches; // synchronised the search display string and the search-string this.searchDisplayString.subscribe(function () { if (synchroniseSearchStrings) { var newLocation = new LocationViewModel(application); newLocation.initialise(that.searchDisplayString()); that.searchLocation = newLocation; } }); // ----- public functions this.executeSearch = function () { /// <summary> /// Executes a search based on the current search string /// </summary> that.userMessage(""); that.isSearchEnabled(false); function errorCallback(error) { /// <summary> /// A callback that is invoked if the search fails, in order to report the failure to the end user /// </summary> that.userMessage("An error occurred while searching. Please check your network connection and try again."); that.isSearchEnabled(true); } function successCallback(results) { /// <summary> /// A callback that is invoked if the search succeeds /// </summary> if (results.responseCode === PropertySearchResponseCode.propertiesFound) { if (results.totalResults === null) { that.userMessage("There were no properties found for the given location."); } else { // if properties were found, navigate to the search results view model that.searchLocation.totalResults = results.totalResults; application.addToRecentSearches(that.searchLocation); application.navigateToSearchResults(that.searchLocation, results); } } else if (results.responseCode === PropertySearchResponseCode.ambiguousLocation) { // if the location was ambiguous, display the list of options that.locations.removeAll(); results.data.forEach(function (item) { var viewModel = new LocationViewModel(application); viewModel.initialiseDisambiguated(item); that.locations.push(viewModel); }); } else { that.userMessage("The location given was not recognised."); } that.isSearchEnabled(true); } this.searchLocation.executeSearch(1, successCallback, errorCallback); }; this.searchMyLocation = function () { /// <summary> /// Performs a search based on the current geolocation /// </summary> // check that the use of location is enabled. if (this.locationEnabled() === false) { that.userMessage("The use of location is currently disabled. Please enable via the 'about' page."); return; } function successCallback(result) { var location = new GeolocationViewModel(application); location.initialise(result.coords.latitude, result.coords.longitude); synchroniseSearchStrings = false; that.searchLocation = location; that.searchDisplayString(location.displayString); synchroniseSearchStrings = true; that.executeSearch(); } function errorCallback() { that.userMessage("Unable to detect current location. Please ensure location is turned on in your phone settings and try again."); } navigator.geolocation.getCurrentPosition(successCallback, errorCallback); }; this.selectLocation = function () { /// <summary> /// A function that is invoked when a search location is clicked /// </summary> var location = this; synchroniseSearchStrings = false; that.searchLocation = location; that.searchDisplayString(location.displayString); synchroniseSearchStrings = true; that.locations.removeAll(); that.executeSearch(); }; this.viewFavourites = function () { /// <summary> /// Navigates to the favourites view /// </summary> application.navigateToFavourites(this.favourites); }; } util.registerFactory("PropertySearchViewModel", PropertySearchViewModel); module.exports = PropertySearchViewModel; });
define(function(require, exports, module) { var ko = require("lib/knockout"); var util = require("viewModel/util"); function MediaSlideshowModel(application) { /// <summary> /// The 'top level' welcome view model. /// </summary> // ----- private fields this.application = application; var synchroniseSearchStrings = true, that = this; // ----- framework fields this.template = "mediaSlideshow"; this.factoryName = "MediaSlideshowModel"; this.video_url = ko.observable(""); this.img_url = ko.observable(""); this.isVideo = ko.observable(false) this.isImg = ko.observable(true) that.MediaHeight = ko.observable(""); this.mission = ko.observable(""); this.headtitle = ko.observable(""); this.currentMedia = ko.observable(""); this.mediaSlideshowLbl = ko.observable("Lable"); this.align = ko.observable(""); this.calcMediaHeight = function() { d = $(document); //$('iframe').get(0).contentDocument // return Math.floor($(window).height() - $('.headerOuter',d).height()); return Math.floor($(window).width() - $('.headerOuter', d).height()); } this.setMediaHeight = function() { that.MediaHeight(that.calcMediaHeight() * 0.85 + "px"); } this.moveForward = function() { console.log("moveForward") that.showMedia(that.currentMedia() + 1); } this.moveBack = function() { console.log("moveBack") that.showMedia(that.currentMedia() - 1); } this.showMedia = function(idx) { $(".mediaContentVideo").empty(); $(".mediaContentImg").empty(); that.setMediaHeight(); idx = idx % that.mission().media.length; if (idx < 0) idx = that.mission().media.length + idx; var media = that.mission().media[idx]; that.mediaSlideshowLbl(media.title); that.currentMedia(idx); if (media.isVideo) { $(".mediaContentImg").hide(); $(".mediaContentVideo").show(); var url = media.video_url; that.isVideo(true); that.isImg(false); patt = /www\.youtube\.com\/watch\?.*v=([^&]*)/; m = patt.exec(url); if (m.length == 2) { url = "http://www.youtube.com/embed/" + m[1] //+ "?autoplay=1" console.log("url = " + url) } that.video_url(url); // $(".uIframe").attr("src",url) var iframe = $(".mediaContentVideo iframe") $(".mediaContentVideo").html( '<iframe class="uIframe" src="' + url + '" frameborder="0" allowfullscreen></iframe>' //'<object width="100%" height="100%"><param name="movie" value="//www.youtube.com/v/'+m[1]+'?hl=en_US&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/xajQUEPXRyg?hl=en_US&version=3" type="application/x-shockwave-flash" width="100%" height="100%" allowscriptaccess="always" allowfullscreen="true"></embed></object>' ) } else { var url = media.url; that.isVideo(false); that.isImg(true); $(".mediaContentImg").show(); $(".mediaContentVideo").hide(); that.img_url(url); $(".mediaContentImg").html( '<img class="mediaSlideshowImg" src="' + url + '" />' //'<object width="100%" height="100%"><param name="movie" value="//www.youtube.com/v/'+m[1]+'?hl=en_US&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/xajQUEPXRyg?hl=en_US&version=3" type="application/x-shockwave-flash" width="100%" height="100%" allowscriptaccess="always" allowfullscreen="true"></embed></object>' ) } } this.initialize = function(opt) { //window.plugins.screenOrientation.set('fullSensor'); //var url = opt.url; var challenge = opt.challenge; that.align(application.activity.align()); that.headtitle(opt.challenge.actname()); that.mission(opt.challenge); that.showMedia(opt.index); } } util.registerFactory("MediaSlideshowModel", MediaSlideshowModel); module.exports = MediaSlideshowModel; });