text: ﻿var CurrentAppId;
  var CurrentExportUrl;
  
  $(function () {
      appPropertiesDialog = $("#app-properties-dialog").dialog({
          autoOpen: false,
          resizable: false,
          width: 600,
          height: 320,
          buttons: {
              "Save": function () {
                  appPropertiesDialog_SubmitData();
              },
              "Cancel": function () {
                  appPropertiesDialog.dialog("close");
              }
          },
          create: function () {
              $(this).keypress(function (e) {
                  if (e.keyCode == $.ui.keyCode.ENTER) {
                      appPropertiesDialog_SubmitData();
                      return false;
                  }
              });
          },
          open: function () {
              appPropertiesDialog.find("#app-name").val("");
              appPropertiesDialog.find("#cbAllowAll").val("");
              appPropertiesDialog.find("#cbAllowGuests").val("");
              appPropertiesDialog.find("#template").val(1);
              appPropertiesDialog.find("#tile-width").val(2);
              appPropertiesDialog.find("#tile-height").val(1);
              appPropertiesDialog.find("#bg-color").val(0);
              appPropertiesDialog.find("#icon-class").val("");
              $.ajax({
                  type: "GET",
                  url: "/api/master/apps/" + CurrentAppId + "/properties",
                  dataType: "json",
                  success: function (data) {
                      if (data.IsAllowedForAll) { //set if application is allowed for all users.
                          $("#cbAllowAll").prop("checked",true);
                      } else {
                          $("#cbAllowAll").prop("checked", false);
  
                      }
                      if (data.IsAllowedGuests) { //set if application is allowed for guests.
                          $("#cbAllowGuests").prop("checked", true);
                      } else {
                          $("#cbAllowGuests").prop("checked", false);
  
                      }
                      appPropertiesDialog.find("#app-name").val(data.DisplayName);
                      appPropertiesDialog.find("#template").val(data.CSSTemplateId);
                      appPropertiesDialog.find("#tile-width").val(data.TileWidth);
                      appPropertiesDialog.find("#tile-height").val(data.TileHeight);
                      appPropertiesDialog.find("#bg-color").val(data.Color);
                      appPropertiesDialog.find("#icon-class").val(data.Icon);
                  }
              });
          }
      });
      function appPropertiesDialog_SubmitData() {
  
          appPropertiesDialog.dialog("close");
          postData = {
              DisplayName: appPropertiesDialog.find("#app-name").val(),
              CSSTemplateId: appPropertiesDialog.find("#template").val(),
              TileWidth: appPropertiesDialog.find("#tile-width").val(),
              TileHeight: appPropertiesDialog.find("#tile-height").val(),
              Color: appPropertiesDialog.find("#bg-color").val(),
              Icon: appPropertiesDialog.find("#icon-class").val(),
              IsAllowedForAll: $("#cbAllowAll").is(":checked") == true ? true : false,
              IsAllowedGuests: $("#cbAllowGuests").is(":checked") == true ? true : false
          }
          $.ajax({
              type: "POST",
              url: "/api/master/apps/" + CurrentAppId + "/properties",
              data: postData,
              success: function () {
                  alert("OK");
                  // Reload page to change application name in AppManager table
                  // after application name was changed
                  location.reload();
              }
          });
      }
      addAppDialog = $("#new-app-dialog").dialog({
          autoOpen: false,
          resizable: false,
          width: 600,
          height: 320,
          buttons: {
              "Add": function () {
                  addAppDialog_SubmitData();
              },
              "Cancel": function () {
                  addAppDialog.dialog("close");
              }
          },
          create: function () {
              $(this).keypress(function (e) {
                  if (e.keyCode == $.ui.keyCode.ENTER) {
                      addAppDialog_SubmitData();
                      return false;
                  }
              });
          },
          open: function () {
              addAppDialog.find("#app-name").val("");
              addAppDialog.find("#template").val(1);
              addAppDialog.find("#tile-width").val(2);
              addAppDialog.find("#tile-height").val(1);
              addAppDialog.find("#bg-color").val(0);
              addAppDialog.find("#icon-class").val("fa-question");
          }
      });
      function addAppDialog_SubmitData() {
          addAppDialog.dialog("close");
          postData = {
              DisplayName: addAppDialog.find("#app-name").val(),
              Template: addAppDialog.find("#template").val(),
              TileWidth: addAppDialog.find("#tile-width").val(),
              TileHeight: addAppDialog.find("#tile-height").val(),
              Color: addAppDialog.find("#bg-color").val(),
              Icon: addAppDialog.find("#icon-class").val()
          }
          $.ajax({
              type: "POST",
              url: "/api/master/apps",
              data: postData,
              success: function () {
                  location.reload();
              }
          });
      }
      appBuildDialog = $("#app-build-dialog").dialog({
          autoOpen: false,
          resizable: false,
          width: 640,
          height: 320
      });
      exportAppDialog = $("#export-application-dialog").dialog({
          autoOpen: false,
          resizable: false,
          width: 660,
          height: 380,
          buttons: {
              "Export": function () {
                  exportAppDialog_SubmitData();
              },
              "Cancel": function () {
                  exportAppDialog.dialog("close");
              }
          },
          create: function () {
              $(this).keypress(function (e) {
                  if (e.keyCode == $.ui.keyCode.ENTER) {
                      exportAppDialog_SubmitData();
                      return false;
                  }
              });
          }
      });
      function exportAppDialog_SubmitData() {
          $("#export-application-dialog form").attr('action', CurrentExportUrl).submit();
          exportAppDialog.dialog('close');
      }
  });
  