<commit_before>﻿
var nBraneAdminSuitePagesViewModel = function () {
    var self = this;
	self.Pages = ko.observableArray();
	self.SelectedPage = ko.observable();
	self.DefaultAction = ko.observable('edit');
	
	self.ParentId = ko.observable(-1);
	self.PageId = ko.observable(-1);
	self.PortalId = ko.observable(-1);
	self.PageName = ko.observable('');
	self.PageDescription = ko.observable('');
	self.PageVisible = ko.observable(true);
	self.PageDisabled = ko.observable(false);
	self.PageSecure = ko.observable(false);
	self.PagePosition = ko.observable('');
	self.PagePositionTarget = ko.observable('');
	self.PageVisibility = ko.observable('');
	self.PageTheme = ko.observable('');
	self.PageContainer = ko.observable('');
	self.PageUrls = ko.observableArray();
	self.PageList = ko.observableArray();
	self.ThemeList = ko.observableArray();
	self.ContainerList = ko.observableArray();
	self.ShowManagementLinks = ko.observable(false);
	self.ShowBackLink = ko.observable(false);
	self.FocusOn = ko.observable(false);
	self.SslEnabled = ko.observable("[data-bind: sslenabled]");

	self.LoadInitialView = function() {
		self.ParentNode().ToggleLoadingScreen(true);

		if (self.ParentNode().CurrentSubaction() == 'all') {
		    self.ShowManagementLinks(true);
		}
		else if (self.ParentNode().CurrentSubaction() == 'settings') {
		    self.ShowManagementLinks(false);
		    self.DefaultAction('edit');
		} else {
			self.DefaultAction('view');
		}

		if (self.ParentNode().CurrentSubaction() == 'settings') {
		    self.ShowEditPageDialog({ Value: controlPanelTabId, Name: 'Current' });
		} else {
		    self.ParentNode().ServerCallback('Pages', 'ListPages', 'parent=' + self.ParentNode().CurrentSubaction(), function (serverData) {
		    	if (serverData.Success){
		    		self.Pages(serverData.CustomObject);

		    		self.ParentNode().ToggleLoadingScreen(false);
		    	}
		    	else{
		    		self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
		    	}
		    });
		}
	};
	
	self.ShowAdvancedSettings = function() {
		self.ParentNode().ToggleLoadingScreen(true);
		location.href = self.PageUrls()[0].Value + "?ctl=tab&action=edit&returntabid=" + controlPanelTabId;
	};
	
	self.ShowEditPageDialog = function(page, event) {

	    if (event && $(event.target).hasClass("page-with-children")) {
	        self.ParentNode().ServerCallback('Pages', 'ListPages', 'parent=' + page.Value, function (serverData) {
	            if (serverData.Success) {
	                self.ParentId(page.Value);
	                self.ShowBackLink(true);
	                self.Pages(serverData.CustomObject);

	                self.ParentNode().ToggleLoadingScreen(false);
	            }
	            else {
	                self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
	            }
	        });
	    }
	    else {
	        self.SelectedPage(page);

	        if (self.DefaultAction() == 'delete') {

	            self.ParentNode().ToggleConfirmScreen('Are you sure you want to delete the following page?', 'Id: ' + page.Value + ', Name: ' + page.Name, function () {
	                self.ParentNode().ToggleLoadingScreen(true);

	                var pageObject = {};
	                pageObject.Id = page.Value;

	                self.ParentNode().ServerCallback('Pages', 'DeletePage', JSON.stringify(pageObject), function (serverData) {
	                    if (serverData.Success) {

	                        self.ParentNode().ToggleLoadingScreen(false);
	                        if (serverData.CustomObject.Redirect) {
	                            location.href = serverData.CustomObject.Url;
	                        } else {
	                            self.LoadInitialView();
	                        }
	                    }
	                    else {
	                        self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
	                    }
	                }, null, null, 'POST');
	            });
	        } else {
	            self.ParentNode().ToggleLoadingScreen(true);

	            self.ParentNode().ServerCallback('Pages', 'LoadPageDetails', 'id=' + page.Value, function (serverData) {
	                if (serverData.Success) {
	                    self.PageId(serverData.CustomObject.Id);
	                    self.PageName(serverData.CustomObject.Name);
	                    self.PageDescription(serverData.CustomObject.Description);
	                    self.PageVisible(serverData.CustomObject.Visible);
	                    self.PageDisabled(serverData.CustomObject.Disabled);
	                    self.PageSecure(serverData.CustomObject.Secure);
	                    self.PageUrls(serverData.CustomObject.Urls);
	                    self.PageList(serverData.CustomObject.AllPages);
	                    self.ThemeList(serverData.CustomObject.Themes);
	                    self.ContainerList(serverData.CustomObject.Containers);
	                    self.PageTheme(serverData.CustomObject.Theme);
	                    self.PageContainer(serverData.CustomObject.Container);

	                    if (self.DefaultAction() == 'edit') {
	                        self.ParentNode().ToggleLoadingScreen(false);
	                        $('.nbr-dialog').fadeIn();
	                        self.FocusOn(false);
	                    }
	                    else if (self.DefaultAction() == 'view') {
	                        location.href = serverData.CustomObject.Urls[0].Value;
	                    }
	                }
	                else {
	                    self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
	                }
	            });
	        }
	    }
	};
	
	self.ShowAddNewPageDialog = function() {
		self.SelectedPage(null);
		self.ParentNode().ToggleLoadingScreen(true);
		
		self.ParentNode().ServerCallback('Pages', 'LoadPageDetails', 'id=-1', function (serverData) {
			if (serverData.Success){
				self.PageId(serverData.CustomObject.Id);
				self.PageName('');
				self.PageDescription('');
				self.PageVisible(true);
				self.PageDisabled(false);

				if (self.SslEnabled()) {
				    self.PageSecure(true);
				}

				self.PageTheme();
				self.PageContainer();
				
				self.PageUrls(null);
				self.PageList(serverData.CustomObject.AllPages);
				self.ThemeList(serverData.CustomObject.Themes);
				self.ContainerList(serverData.CustomObject.Containers);

				self.ParentNode().ToggleLoadingScreen(false);
				$('.nbr-dialog').fadeIn();
				self.FocusOn(true);
			}
			else{
				self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
			}
		});

		$('.nbr-dialog').fadeIn();
	};
	<commit_msg>when adding a new page, default to after the current page for it's position.<commit_after>﻿
var nBraneAdminSuitePagesViewModel = function () {
    var self = this;
	self.Pages = ko.observableArray();
	self.SelectedPage = ko.observable();
	self.DefaultAction = ko.observable('edit');
	
	self.ParentId = ko.observable(-1);
	self.PageId = ko.observable(-1);
	self.PortalId = ko.observable(-1);
	self.PageName = ko.observable('');
	self.PageDescription = ko.observable('');
	self.PageVisible = ko.observable(true);
	self.PageDisabled = ko.observable(false);
	self.PageSecure = ko.observable(false);
	self.PagePosition = ko.observable('');
	self.PagePositionTarget = ko.observable('');
	self.PageVisibility = ko.observable('');
	self.PageTheme = ko.observable('');
	self.PageContainer = ko.observable('');
	self.PageUrls = ko.observableArray();
	self.PageList = ko.observableArray();
	self.ThemeList = ko.observableArray();
	self.ContainerList = ko.observableArray();
	self.ShowManagementLinks = ko.observable(false);
	self.ShowBackLink = ko.observable(false);
	self.FocusOn = ko.observable(false);
	self.SslEnabled = ko.observable("[data-bind: sslenabled]");

	self.LoadInitialView = function() {
		self.ParentNode().ToggleLoadingScreen(true);

		if (self.ParentNode().CurrentSubaction() == 'all') {
		    self.ShowManagementLinks(true);
		}
		else if (self.ParentNode().CurrentSubaction() == 'settings') {
		    self.ShowManagementLinks(false);
		    self.DefaultAction('edit');
		} else {
			self.DefaultAction('view');
		}

		if (self.ParentNode().CurrentSubaction() == 'settings') {
		    self.ShowEditPageDialog({ Value: controlPanelTabId, Name: 'Current' });
		} else {
		    self.ParentNode().ServerCallback('Pages', 'ListPages', 'parent=' + self.ParentNode().CurrentSubaction(), function (serverData) {
		    	if (serverData.Success){
		    		self.Pages(serverData.CustomObject);

		    		self.ParentNode().ToggleLoadingScreen(false);
		    	}
		    	else{
		    		self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
		    	}
		    });
		}
	};
	
	self.ShowAdvancedSettings = function() {
		self.ParentNode().ToggleLoadingScreen(true);
		location.href = self.PageUrls()[0].Value + "?ctl=tab&action=edit&returntabid=" + controlPanelTabId;
	};
	
	self.ShowEditPageDialog = function(page, event) {

	    if (event && $(event.target).hasClass("page-with-children")) {
	        self.ParentNode().ServerCallback('Pages', 'ListPages', 'parent=' + page.Value, function (serverData) {
	            if (serverData.Success) {
	                self.ParentId(page.Value);
	                self.ShowBackLink(true);
	                self.Pages(serverData.CustomObject);

	                self.ParentNode().ToggleLoadingScreen(false);
	            }
	            else {
	                self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
	            }
	        });
	    }
	    else {
	        self.SelectedPage(page);

	        if (self.DefaultAction() == 'delete') {

	            self.ParentNode().ToggleConfirmScreen('Are you sure you want to delete the following page?', 'Id: ' + page.Value + ', Name: ' + page.Name, function () {
	                self.ParentNode().ToggleLoadingScreen(true);

	                var pageObject = {};
	                pageObject.Id = page.Value;

	                self.ParentNode().ServerCallback('Pages', 'DeletePage', JSON.stringify(pageObject), function (serverData) {
	                    if (serverData.Success) {

	                        self.ParentNode().ToggleLoadingScreen(false);
	                        if (serverData.CustomObject.Redirect) {
	                            location.href = serverData.CustomObject.Url;
	                        } else {
	                            self.LoadInitialView();
	                        }
	                    }
	                    else {
	                        self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
	                    }
	                }, null, null, 'POST');
	            });
	        } else {
	            self.ParentNode().ToggleLoadingScreen(true);

	            self.ParentNode().ServerCallback('Pages', 'LoadPageDetails', 'id=' + page.Value, function (serverData) {
	                if (serverData.Success) {
	                    self.PageId(serverData.CustomObject.Id);
	                    self.PageName(serverData.CustomObject.Name);
	                    self.PageDescription(serverData.CustomObject.Description);
	                    self.PageVisible(serverData.CustomObject.Visible);
	                    self.PageDisabled(serverData.CustomObject.Disabled);
	                    self.PageSecure(serverData.CustomObject.Secure);
	                    self.PageUrls(serverData.CustomObject.Urls);
	                    self.PageList(serverData.CustomObject.AllPages);
	                    self.ThemeList(serverData.CustomObject.Themes);
	                    self.ContainerList(serverData.CustomObject.Containers);
	                    self.PageTheme(serverData.CustomObject.Theme);
	                    self.PageContainer(serverData.CustomObject.Container);

	                    if (self.DefaultAction() == 'edit') {
	                        self.ParentNode().ToggleLoadingScreen(false);
	                        $('.nbr-dialog').fadeIn();
	                        self.FocusOn(false);
	                    }
	                    else if (self.DefaultAction() == 'view') {
	                        location.href = serverData.CustomObject.Urls[0].Value;
	                    }
	                }
	                else {
	                    self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
	                }
	            });
	        }
	    }
	};
	
	self.ShowAddNewPageDialog = function() {
		self.SelectedPage(null);
		self.ParentNode().ToggleLoadingScreen(true);
		
		self.ParentNode().ServerCallback('Pages', 'LoadPageDetails', 'id=-1', function (serverData) {
			if (serverData.Success){
				self.PageId(serverData.CustomObject.Id);
				self.PageName('');
				self.PageDescription('');
				self.PageVisible(true);
				self.PageDisabled(false);

				if (self.SslEnabled()) {
				    self.PageSecure(true);
				}

				self.PageTheme();
				self.PageContainer();
				
				self.PageUrls(null);
				self.PageList(serverData.CustomObject.AllPages);
				self.ThemeList(serverData.CustomObject.Themes);
				self.ContainerList(serverData.CustomObject.Containers);

				self.PagePosition(1);
				self.PagePositionTarget(controlPanelTabId);

				self.ParentNode().ToggleLoadingScreen(false);
				$('.nbr-dialog').fadeIn();
				self.FocusOn(true);
			}
			else{
				self.ParentNode().ToggleConfirmScreen('Sorry, We ran into a problem.', 'Please try again');
			}
		});

		$('.nbr-dialog').fadeIn();
	};
	
{'fraction_non_alphanumeric': 0.13658428949691084, 'fraction_numerical': 0.0009561635775228008, 'mean_word_length': 2.290658276863504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2233283', 'n_tokens_mistral': 4154, 'n_tokens_neox': 3636, 'n_words': 555}