aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/editredirect.js
diff options
context:
space:
mode:
authorEinar Egilsson <einar@einaregilsson.com>2015-09-09 14:53:22 +0000
committerEinar Egilsson <einar@einaregilsson.com>2015-09-09 14:53:22 +0000
commit8a77401f48360fe0d5501d4fd6b4cc194279d4f0 (patch)
tree6c6069b54de898c72a2281caa9702039df8a2bfb /js/controllers/editredirect.js
parenta7506a34544f4df3ba65a854c81fadcca2eb303f (diff)
Plenty of changes
Diffstat (limited to 'js/controllers/editredirect.js')
-rw-r--r--js/controllers/editredirect.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/js/controllers/editredirect.js b/js/controllers/editredirect.js
new file mode 100644
index 0000000..f24f3e6
--- /dev/null
+++ b/js/controllers/editredirect.js
@@ -0,0 +1,82 @@
+redirectorApp.controller('EditRedirectCtrl', ['$scope', function($s) {
+
+
+ $s.requestTypes = Redirect.requestTypes;
+
+ // Ok, this is pretty ugly. But I want to make this controller to control
+ // everything about the editing process, so I make this available on
+ // the parent scope, so the RedirectListCtrl can access it.
+ $s.$parent.editRedirect = function(index) {
+ $s.redirect = new Redirect($s.redirects[index]);
+ $s.editIndex = index;
+ $s.redirect.updateExampleResult();
+ if ($s.redirect.escapeMatches || $s.redirect.unescapeMatches || $s.redirect.excludePattern
+ || !($s.redirect.appliesTo.length == 1 && $s.redirect.appliesTo[0] == "main_frame")) {
+ $s.showAdvanced = true; //Auto show advanced if redirect uses advanced options
+ }
+ $s.$parent.showEditForm = true;
+ };
+
+ // Same, this is for the Create New button, which is starting
+ // the edit form, so I want to control it from here.
+ $s.$parent.createNewRedirect = function() {
+ $s.redirect = new Redirect({});
+ $s.$parent.showEditForm = true;
+ };
+
+ $s.saveRedirect = function() {
+ if ($s.redirect.error) {
+ return; //Button is already disabled, but we still get the click
+ }
+
+ if ($s.editIndex >= 0) {
+ $s.redirects[$s.editIndex] = $s.redirect;
+ } else {
+ $s.redirects.push($s.redirect);
+ }
+ closeEditForm();
+ $s.saveChanges();
+ };
+
+ $s.cancelEdit = function() {
+ closeEditForm();
+ }
+
+ // To bind a list of strings to a list of checkboxes
+ $s.appliesTo = function(key) {
+ if (!$s.redirect) {
+ return;
+ }
+ return $s.redirect.appliesTo.indexOf(key) != -1;
+ };
+
+ // Add or remove string from array based on whether checkbox is checked
+ $s.toggleApplies = function(key) {
+ if (!$s.redirect) {
+ return;
+ }
+ var arr = $s.redirect.appliesTo;
+
+ var index = arr.indexOf(key);
+ if (index == -1) {
+ arr.push(key);
+ } else {
+ arr.splice(index, 1);
+ }
+
+ var order = 'main_frame,sub_frame,stylesheet,script,image,object,xmlhttprequest,other';
+
+ arr.sort(function(a,b) {
+ return order.indexOf(a) - order.indexOf(b);
+ });
+
+ $s.redirect.updateExampleResult();
+ };
+
+ function closeEditForm() {
+ $s.editIndex = -1;
+ $s.redirect = null;
+ $s.showAdvanced = false;
+ $s.$parent.showEditForm = false;
+ }
+}]);