| 
									
										
										
										
											2018-01-10 14:54:08 -07:00
										 |  |  | (function () { | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  |   var cache = { recordsMap: {} }; | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |   var myZone; | 
					
						
							|  |  |  |   window.ADNS = { cache: cache, $qs: $qs  }; | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |   if (!Element.prototype.matches) { | 
					
						
							|  |  |  |     Element.prototype.matches = Element.prototype.msMatchesSelector; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |   function $qs(qs, el) { | 
					
						
							|  |  |  |     return (el||document).querySelector(qs); | 
					
						
							| 
									
										
										
										
											2018-01-10 14:54:08 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-17 02:17:39 -07:00
										 |  |  |   function $qsa(qs, el) { | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |     return Array.prototype.slice.call((el||document).querySelectorAll(qs)); | 
					
						
							| 
									
										
										
										
											2018-01-17 02:17:39 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |   function $on(selector, eventname, cb) { | 
					
						
							|  |  |  |     if (!$on._events[eventname]) { | 
					
						
							|  |  |  |       $on._events[eventname] = $on._dispatcher(eventname); | 
					
						
							|  |  |  |       document.addEventListener(eventname, $on._events[eventname]); | 
					
						
							| 
									
										
										
										
											2018-01-10 14:54:08 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |     if (!$on._handlers[eventname]) { | 
					
						
							|  |  |  |       $on._handlers[eventname] = {}; | 
					
						
							| 
									
										
										
										
											2018-01-10 14:54:08 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |     if (!$on._handlers[eventname][selector]) { | 
					
						
							|  |  |  |       $on._handlers[eventname][selector] = []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $on._handlers[eventname][selector].push(cb); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   $on._events = {}; | 
					
						
							|  |  |  |   $on._handlers = {}; | 
					
						
							|  |  |  |   $on._dispatcher = function (eventname) { | 
					
						
							|  |  |  |     return function (ev) { | 
					
						
							|  |  |  |       //console.log('event: ' + ev.type);
 | 
					
						
							|  |  |  |       if (!$on._handlers[eventname]) { | 
					
						
							|  |  |  |         console.warn('no handlers for event'); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       var matches = Object.keys($on._handlers[eventname]).some(function (selector) { | 
					
						
							|  |  |  |         if (ev.target.matches(selector)) { | 
					
						
							|  |  |  |           $on._handlers[eventname][selector].forEach(function (cb) { cb(ev); }); | 
					
						
							|  |  |  |           return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |       if (matches) { | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |         console.warn("no handlers for selector"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |   function verifyAuth(/*ev*/) { | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |     auth = $qs('input.js-jwt').value; | 
					
						
							|  |  |  |     return window.fetch( | 
					
						
							|  |  |  |       '/api/verify-auth' | 
					
						
							|  |  |  |     , { method: 'GET' | 
					
						
							|  |  |  |       , headers: new window.Headers({ 'Authorization': 'Bearer ' + auth }) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ).then(function (resp) { | 
					
						
							|  |  |  |       return resp.json().then(function (data) { | 
					
						
							|  |  |  |         if (data.error) { | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |           localStorage.removeItem('auth'); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |           console.error(data.error); | 
					
						
							|  |  |  |           window.alert('Bad HTTP Response: ' + data.error.message); | 
					
						
							|  |  |  |           throw new Error('Bad HTTP Response: ' + data.error.message); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |         console.log('verify-auth:'); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |         console.log(data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         localStorage.setItem('auth', auth); | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |         changeAuth(); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return fetchPeers(auth).then(function () { | 
					
						
							|  |  |  |           return fetchZones(auth); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |   } | 
					
						
							|  |  |  |   function fetchPeers(auth) { | 
					
						
							|  |  |  |     return window.fetch('/api/peers', { | 
					
						
							|  |  |  |       method: 'GET' | 
					
						
							|  |  |  |     , headers: new window.Headers({ 'Authorization': 'Bearer ' + auth }) | 
					
						
							|  |  |  |     }).then(function (resp) { | 
					
						
							|  |  |  |       return resp.json().then(function (data) { | 
					
						
							|  |  |  |         var tpl = ''; | 
					
						
							|  |  |  |         var el; | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |         cache.peers = data.peers; | 
					
						
							|  |  |  |         cache.peers.forEach(function (peer) { | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |           el = document.createElement('div'); | 
					
						
							|  |  |  |           el.innerHTML = tpls.peer; | 
					
						
							|  |  |  |           console.log(el); | 
					
						
							|  |  |  |           console.log($qs('.js-peer-name', el)); | 
					
						
							|  |  |  |           $qs('.js-peer-name', el).innerText = peer.name; | 
					
						
							|  |  |  |           $qs('.js-peer-name', el).dataset.id = peer.name; | 
					
						
							| 
									
										
										
										
											2018-01-30 12:03:25 -07:00
										 |  |  |           $qs('.js-peer', el).dataset.id = peer.name; | 
					
						
							|  |  |  |           $qs('.js-peer-address', el).innerText = peer.address || ''; | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |           console.log(el.innerHTML); | 
					
						
							|  |  |  |           tpl += el.innerHTML; | 
					
						
							|  |  |  |           console.log(tpl); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         $qs('.js-peer-tpl').innerHTML = tpl; | 
					
						
							|  |  |  |         console.log($qs('.js-peer-tpl').innerHTML); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  |   function renderZones() { | 
					
						
							|  |  |  |     var tpl = ''; | 
					
						
							|  |  |  |     var el; | 
					
						
							|  |  |  |     cache.zones.forEach(function (zone) { | 
					
						
							|  |  |  |       el = document.createElement('div'); | 
					
						
							|  |  |  |       el.innerHTML = tpls.zone; | 
					
						
							|  |  |  |       console.log(el); | 
					
						
							|  |  |  |       console.log($qs('.js-zone', el)); | 
					
						
							|  |  |  |       $qs('.js-zone-name', el).innerText = zone.name; | 
					
						
							|  |  |  |       $qs('.js-zone', el).dataset.id = zone.id; | 
					
						
							|  |  |  |       $qs('.js-zone', el).dataset.name = zone.name; | 
					
						
							|  |  |  |       console.log(el.innerHTML); | 
					
						
							|  |  |  |       tpl += el.innerHTML; | 
					
						
							|  |  |  |       console.log(tpl); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     $qs('.js-zone-tpl').innerHTML = tpl; | 
					
						
							|  |  |  |     console.log($qs('.js-zone-tpl').innerHTML); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |   function fetchZones(auth) { | 
					
						
							|  |  |  |     return window.fetch('/api/zones', { | 
					
						
							|  |  |  |       method: 'GET' | 
					
						
							|  |  |  |     , headers: new window.Headers({ 'Authorization': 'Bearer ' + auth }) | 
					
						
							|  |  |  |     }).then(function (resp) { | 
					
						
							|  |  |  |       return resp.json().then(function (data) { | 
					
						
							|  |  |  |         if (!tpls.zone) { | 
					
						
							|  |  |  |           tpls.zone = $qs('.js-zone-tpl').innerHTML; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  |         cache.zones = data.zones; | 
					
						
							|  |  |  |         renderZones(); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |   function renderRecords() { | 
					
						
							|  |  |  |     var tpl = ''; | 
					
						
							|  |  |  |     var el; | 
					
						
							|  |  |  |     console.log('tpls.recordsMap:'); | 
					
						
							|  |  |  |     console.log(tpls.recordsMap); | 
					
						
							|  |  |  |     cache.records.forEach(function (record) { | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |       if (record.soa) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |       el = document.createElement('div'); | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |       console.log('record.type:', record.type); | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |       el.innerHTML = tpls.recordsMap[record.type.toLowerCase()]; | 
					
						
							|  |  |  |       console.log(el); | 
					
						
							|  |  |  |       console.log($qs('.js-record-name', el)); | 
					
						
							|  |  |  |       Object.keys(record).sort().forEach(function (key) { | 
					
						
							|  |  |  |         if ('id' === key) { return; } | 
					
						
							|  |  |  |         var x = $qs('.js-record-' + key, el); | 
					
						
							|  |  |  |         if (x) { | 
					
						
							|  |  |  |           x.innerText = record[key]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       el.dataset.recordId = record.id; | 
					
						
							|  |  |  |       $qs('input.js-record-id', el).value = record.id; | 
					
						
							|  |  |  |       cache.recordsMap[record.id] = record; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       //$qs('.js-record-type', el).innerText = record.type;
 | 
					
						
							|  |  |  |       //$qs('.js-record-name', el).innerText = record.name;
 | 
					
						
							|  |  |  |       //$qs('.js-record-address', el).innerText = record.address;
 | 
					
						
							|  |  |  |       console.log('el.innerHTML:'); | 
					
						
							|  |  |  |       console.log(el.innerHTML); | 
					
						
							|  |  |  |       tpl += el.innerHTML; | 
					
						
							|  |  |  |       console.log(tpl); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     $qs('.js-record-tpl').innerHTML = tpl; | 
					
						
							|  |  |  |     console.log($qs('.js-record-tpl').innerHTML); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |   function fetchRecords(zone) { | 
					
						
							|  |  |  |     return window.fetch('/api/zones/' + zone + '/records', { | 
					
						
							|  |  |  |       method: 'GET' | 
					
						
							|  |  |  |     , headers: new window.Headers({ 'Authorization': 'Bearer ' + auth }) | 
					
						
							|  |  |  |     }).then(function (resp) { | 
					
						
							|  |  |  |       return resp.json().then(function (data) { | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  |         cache.records = data.records; | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |         renderRecords(); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // BEGIN
 | 
					
						
							|  |  |  |   var tpls = {}; | 
					
						
							|  |  |  |   var auth = localStorage.getItem('auth'); | 
					
						
							|  |  |  |   if (auth) { | 
					
						
							|  |  |  |     $qs('input.js-jwt').value = auth; | 
					
						
							|  |  |  |     verifyAuth(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $on('body', 'click', function () { | 
					
						
							|  |  |  |     console.log('woo-hoo, that tickles my body!'); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |   $on('button.js-jwt', 'click', verifyAuth); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |   function changeAuth() { | 
					
						
							|  |  |  |     $qs('a.js-peers').href = | 
					
						
							|  |  |  |       $qs('a.js-peers').dataset.href.replace(/:token/, auth); | 
					
						
							|  |  |  |     $qs('a.js-zones').href = | 
					
						
							|  |  |  |       $qs('a.js-zones').dataset.href.replace(/:token/, auth); | 
					
						
							|  |  |  |     $qs('a.js-records').href = | 
					
						
							|  |  |  |       $qs('a.js-records').dataset.href.replace(/:token/, auth); | 
					
						
							|  |  |  |     changeZone(); | 
					
						
							|  |  |  |     changeRecord(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   function changeZone(ev) { | 
					
						
							|  |  |  |     var val = (ev && ev.target.value || $qs('input.js-zone').value) || ':zone'; | 
					
						
							|  |  |  |     $qs('code.js-zone').innerHTML = val; | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |     // $qs('a.js-zone').setAttribute('data-href', ...)
 | 
					
						
							|  |  |  |     $qs('a.js-zone').href = | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |       $qs('a.js-zone').dataset.href.replace(/:zone/, val).replace(/:token/, auth); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   $on('input.js-zone', 'keyup', changeZone); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |   function changeRecord(ev) { | 
					
						
							|  |  |  |     var val = (ev && ev.target.value || $qs('input.js-name').value) || ':name'; | 
					
						
							|  |  |  |     $qs('code.js-name').innerHTML = val; | 
					
						
							| 
									
										
										
										
											2018-01-12 02:03:41 -07:00
										 |  |  |     $qs('a.js-name').href = | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |       $qs('a.js-name').dataset.href.replace(/:name/, val).replace(/:token/, auth); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   $on('input.js-name', 'keyup', changeRecord); | 
					
						
							| 
									
										
										
										
											2018-01-31 19:09:26 -07:00
										 |  |  |   $on('button.js-zone-destroy', 'click', function (ev) { | 
					
						
							|  |  |  |     var zoneId = ev.target.parentElement.dataset.id; | 
					
						
							|  |  |  |     var zoneName = ev.target.parentElement.dataset.name; | 
					
						
							| 
									
										
										
										
											2018-01-10 14:54:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-31 19:09:26 -07:00
										 |  |  |     if (!window.confirm("Remove zone '" + zoneName + "' and all associated records?")) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return window.fetch( | 
					
						
							|  |  |  |       '/api/zones/' + zoneId | 
					
						
							|  |  |  |     , { method: 'DELETE' | 
					
						
							|  |  |  |       , headers: new window.Headers({ | 
					
						
							|  |  |  |           'Authorization': 'Bearer ' + auth | 
					
						
							|  |  |  |         , 'Content-Type': 'application/json;charset=UTF-8' | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ).then(function (resp) { | 
					
						
							|  |  |  |       return resp.json().then(function (data) { | 
					
						
							|  |  |  |         var zone; | 
					
						
							| 
									
										
										
										
											2018-01-31 19:19:11 -07:00
										 |  |  |         var records = []; | 
					
						
							| 
									
										
										
										
											2018-01-31 19:09:26 -07:00
										 |  |  |         if (data.error) { | 
					
						
							|  |  |  |           console.error(data); | 
					
						
							|  |  |  |           window.alert(data.error.message); | 
					
						
							|  |  |  |           return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         console.log('zone undo data:'); | 
					
						
							|  |  |  |         console.log(data); | 
					
						
							| 
									
										
										
										
											2018-01-31 19:19:11 -07:00
										 |  |  |         cache.zones.some(function (z, i) { | 
					
						
							|  |  |  |           if (z.id === zoneId) { | 
					
						
							|  |  |  |             zone = cache.zones.splice(i, 1)[0]; | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-01-31 19:09:26 -07:00
										 |  |  |         function removeRecord(r, i) { | 
					
						
							| 
									
										
										
										
											2018-01-31 19:19:11 -07:00
										 |  |  |           if (r.zone === zone.name || 'SOA' === r.type && r.name === zone.name) { | 
					
						
							|  |  |  |             records.push(cache.records.splice(i, 1)[0]); | 
					
						
							| 
									
										
										
										
											2018-01-31 19:09:26 -07:00
										 |  |  |             return true; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         while (cache.records.some(removeRecord)) { continue; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         renderZones(); | 
					
						
							|  |  |  |         renderRecords(); | 
					
						
							|  |  |  |         console.log('result:', data); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |   $on('button.js-zone-view', 'click', function (ev) { | 
					
						
							|  |  |  |     var zone = ev.target.parentElement.dataset.name; | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     myZone = zone; | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  |     return fetchRecords(zone);/*.then(function () { | 
					
						
							|  |  |  |     });*/ | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  |   function setZoneNs(zone) { | 
					
						
							|  |  |  |     cache.peers.forEach(function (p, i) { | 
					
						
							|  |  |  |       var $vns = $qsa('.js-zone-form-tpl .js-zone-form-vns')[i]; | 
					
						
							|  |  |  |       $qs('.js-record-zone', $vns).innerText = zone; | 
					
						
							|  |  |  |       if (p.address) { | 
					
						
							|  |  |  |         $qs('.js-record-address', $vns).value = p.address; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     $qs('.js-zone-form-tpl .js-recordx-primary').value = 'nsx.' + zone; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |   function openZoneForm(myZone, ns) { | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |     var d = new Date(); | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |     var zone = { | 
					
						
							|  |  |  |       name: myZone.name || myZone | 
					
						
							|  |  |  |     , admin: myZone.admin || ('admin.' + myZone) | 
					
						
							|  |  |  |     , expiration: myZone.expiration || 2419200 // 4 weeks
 | 
					
						
							|  |  |  |     , minimum: myZone.expiration || 5 | 
					
						
							|  |  |  |     , serial: myZone.serial || (d.getFullYear() | 
					
						
							|  |  |  |         + '' + (d.getMonth() + 1) | 
					
						
							|  |  |  |         + '' + d.getDate() | 
					
						
							|  |  |  |         + '' + (Math.round(Math.random() * 99))) | 
					
						
							|  |  |  |     , retry: myZone.retry || 1800 | 
					
						
							|  |  |  |     , refresh: myZone.refresh || 7200 | 
					
						
							|  |  |  |     , ttl: myZone.ttl || 300 | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |     $qs('.js-zone-form-tpl').innerHTML = tpls.newZone; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |     ns.forEach(function () { | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |       $qs('.js-zone-form-vns-tpl').innerHTML += tpls.newNs; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |     ns.forEach(function (p, i) { | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |       var $vns = $qsa('.js-zone-form-tpl .js-zone-form-vns')[i]; | 
					
						
							|  |  |  |       $qs('.js-record-host', $vns).value = 'ns' + (i + 1); | 
					
						
							|  |  |  |       //$qs('.js-record-name', $vns).value = 'ns' + (i + 1) + '.' + myZone;
 | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  |       $qs('.js-record-zone', $vns).innerText = myZone; | 
					
						
							|  |  |  |       if (p.address) { | 
					
						
							|  |  |  |         $qs('.js-record-address', $vns).value = p.address; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |       $qs('.js-record-ttl', $vns).value = 7200; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |     [ 'name', 'admin', 'expiration', 'minimum', 'retry', 'refresh', 'ttl' ].forEach(function (key) { | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |       $qs('.js-zone-form-tpl .js-record-' + key).value = zone[key]; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |     [ 'primary', 'serial' ].forEach(function (key) { | 
					
						
							|  |  |  |       $qs('.js-zone-form-tpl .js-recordx-' + key).value = zone[key]; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     $qs('input.js-zone-form-vanityns').checked = zone.vanity; | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $qs('input.js-zone-form-vanityns').dispatchEvent(new Event('change', { bubbles: true })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |     console.log('val:', $qs('.js-zone-form-tpl .js-record-ttl').value); | 
					
						
							|  |  |  |     console.log('x', $qs('.js-zone-form-tpl')); | 
					
						
							|  |  |  |     console.log('val:', $qs('.js-zone-form-tpl .js-record-ttl').value); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  |   $on('input.js-zone-form-vanityns', 'change', function (ev) { | 
					
						
							|  |  |  |     console.log('checked:', ev.target.checked); | 
					
						
							|  |  |  |     if (ev.target.checked) { | 
					
						
							|  |  |  |       setZoneNs(myZone); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       setZoneNs(cache.peers[0].name.split('.').slice(1).join('.')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |   $on('form.js-zone-form-create', 'submit', function (ev) { | 
					
						
							|  |  |  |     ev.preventDefault(); | 
					
						
							|  |  |  |     ev.stopPropagation(); | 
					
						
							|  |  |  |     console.log('form submit enter'); | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |     var myZone = $qs('.js-zone-form-name').value; | 
					
						
							|  |  |  |     openZoneForm(myZone, cache.peers); | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-26 03:23:12 -07:00
										 |  |  |   $on('button.js-zone-new', 'click', function (/*ev*/) { | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |     //$qs('select.js-record-form-type').value = 'SOA';
 | 
					
						
							|  |  |  |     //$qs('select.js-record-form-type').dispatchEvent(new Event('change', { bubbles: true }));
 | 
					
						
							|  |  |  |     console.log('form submit click'); | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |     var myZone = $qs('.js-zone-form-name').value; | 
					
						
							|  |  |  |     openZoneForm(myZone, cache.peers); | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |   $on('button.js-zone-edit', 'click', function (ev) { | 
					
						
							|  |  |  |     //var zoneId = ev.target.parentElement.dataset.id;
 | 
					
						
							|  |  |  |     var zoneName = ev.target.parentElement.dataset.name; | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |     myZone = zoneName; | 
					
						
							| 
									
										
										
										
											2018-02-01 11:10:55 -07:00
										 |  |  |     openZoneForm(zoneName, cache.peers); | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  |   $on('button.js-zone-save', 'click', function (/*ev*/) { | 
					
						
							|  |  |  |     var zone = {}; | 
					
						
							|  |  |  |     var nss = []; | 
					
						
							|  |  |  |     [ 'id', 'name', 'admin', 'expiration', 'minimum', 'retry', 'refresh', 'ttl' ].forEach(function (key) { | 
					
						
							|  |  |  |       zone[key] = $qs('.js-zone-form-tpl .js-record-' + key).value; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     $qsa('.js-zone-form-tpl .js-zone-form-vns').forEach(function ($el) { | 
					
						
							|  |  |  |       console.log('$el:'); | 
					
						
							|  |  |  |       console.log($el); | 
					
						
							|  |  |  |       var ns = {}; | 
					
						
							|  |  |  |       [ 'id', 'host'/*, 'name'*/, 'ttl', 'address' ].forEach(function (key) { | 
					
						
							|  |  |  |         ns[key] = $qs('.js-record-' + key, $el).value; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       nss.push(ns); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     console.log('zone:'); | 
					
						
							|  |  |  |     console.log(zone); | 
					
						
							|  |  |  |     console.log('nss:'); | 
					
						
							|  |  |  |     console.log(nss); | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 22:03:05 -07:00
										 |  |  |     zone.vanity = false; | 
					
						
							|  |  |  |     if ($qs('input.js-zone-form-vanityns').checked) { | 
					
						
							|  |  |  |       zone.vanity = true; | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  |       zone.vanityNs = nss; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |     $qs('.js-zone-form-tpl').innerHTML = ''; | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return window.fetch( | 
					
						
							|  |  |  |       '/api/zones/' //+ zone.name
 | 
					
						
							|  |  |  |     , { method: 'POST' | 
					
						
							|  |  |  |       , headers: new window.Headers({ | 
					
						
							|  |  |  |           'Authorization': 'Bearer ' + auth | 
					
						
							|  |  |  |         , 'Content-Type': 'application/json;charset=UTF-8' | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       , body: JSON.stringify(zone) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ).then(function (resp) { | 
					
						
							|  |  |  |       return resp.json().then(function (data) { | 
					
						
							|  |  |  |         if (data.error) { | 
					
						
							|  |  |  |           console.error(data); | 
					
						
							|  |  |  |           window.alert(data.error.message); | 
					
						
							|  |  |  |           return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         console.log('result:', data); | 
					
						
							|  |  |  |         if (!zone.id) { | 
					
						
							|  |  |  |           zone.id = data.id; | 
					
						
							| 
									
										
										
										
											2018-01-30 22:03:05 -07:00
										 |  |  |           cache.zones.push(data); | 
					
						
							|  |  |  |           renderZones(); | 
					
						
							| 
									
										
										
										
											2018-01-30 20:42:14 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-01-26 03:23:12 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-12 02:46:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  |   $on('select.js-record-form-type', 'change', function (ev) { | 
					
						
							|  |  |  |     var type = ev.target.value; | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     var $tpl; | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  |     console.log("form type:", type); | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     $tpl = $qs('.js-record-form-tpl'); | 
					
						
							|  |  |  |     $tpl.innerHTML = tpls.formsMap[type] || ''; | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |     if (!tpls.formsMap[type]) { | 
					
						
							|  |  |  |       console.warn("no tpl for type '" + type + "'"); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     $qs('.js-record-type', $tpl).innerText = type; | 
					
						
							|  |  |  |     $qs('.js-record-zone', $tpl).innerText = myZone; | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-26 03:23:12 -07:00
										 |  |  |   $on('button.js-record-form-new', 'click', function (/*ev*/) { | 
					
						
							|  |  |  |     var type = $qs('select.js-record-form-type').value; | 
					
						
							|  |  |  |     if (!type) { | 
					
						
							|  |  |  |       $qs('select.js-record-form-type').value = 'A'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $qs('select.js-record-form-type').dispatchEvent(new Event('change', { bubbles: true })); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   $on('button.js-record-edit', 'click', function (ev) { | 
					
						
							|  |  |  |     var id = ev.target.parentElement.querySelector('.js-record-id').value; | 
					
						
							|  |  |  |     var record = cache.recordsMap[id]; | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     var formTpl = tpls.formsMap[record.type]; | 
					
						
							|  |  |  |     var $tpl; | 
					
						
							| 
									
										
										
										
											2018-01-20 21:08:29 -07:00
										 |  |  |     if (!formTpl) { | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |       formTpl = tpls.formsMap.typeX; | 
					
						
							| 
									
										
										
										
											2018-01-20 21:08:29 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 21:23:59 -07:00
										 |  |  |     console.log(ev.target); | 
					
						
							|  |  |  |     console.log(id); | 
					
						
							|  |  |  |     console.log(record); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     formTpl = tpls.formsMap[(record.type||'typeX')]; | 
					
						
							|  |  |  |     $qs('select.js-record-form-type').value = (record.type||'typeX'); | 
					
						
							| 
									
										
										
										
											2018-01-20 21:08:29 -07:00
										 |  |  |     $qs('select.js-record-form-type').dispatchEvent(new Event('change', { bubbles: true })); | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     $tpl = $qs('.js-record-form-tpl'); | 
					
						
							|  |  |  |     $tpl.innerHTML = formTpl || ''; | 
					
						
							| 
									
										
										
										
											2018-01-20 21:08:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 21:23:59 -07:00
										 |  |  |     record.host = record.name.replace(new RegExp('\\.?' + (record.zone || record.name).replace(/\./g, '\\.') + '$'), ''); | 
					
						
							| 
									
										
										
										
											2018-01-20 21:08:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     console.log('record.type:'); | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     console.log(record.type); | 
					
						
							| 
									
										
										
										
											2018-01-20 21:23:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 21:08:29 -07:00
										 |  |  |     Object.keys(record).forEach(function (key) { | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |       var $el = $qs('.js-record-' + key, $tpl); | 
					
						
							| 
									
										
										
										
											2018-01-20 21:08:29 -07:00
										 |  |  |       if (!$el) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       $el.value = record[key]; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     if ('SOA' === record.type) { | 
					
						
							|  |  |  |       $qs('.js-record-name').disabled = 'disabled'; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       if (!record.host) { $qs('.js-record-host', $tpl).placeholder = '@'; } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $qs('.js-record-type', $tpl).innerHTML = record.type; | 
					
						
							|  |  |  |     $qs('.js-record-zone', $tpl).innerText = myZone; | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |   $on('button.js-record-save', 'click', function (ev) { | 
					
						
							|  |  |  |     console.log('save'); | 
					
						
							|  |  |  |     var $pel = ev.target.parentElement; | 
					
						
							|  |  |  |     var id = $qs('.js-record-id', $pel).value; | 
					
						
							|  |  |  |     var existingRecord = cache.recordsMap[id]; | 
					
						
							| 
									
										
										
										
											2018-01-21 01:47:37 -07:00
										 |  |  |     var record = {}; | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |     var change; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $qsa('input[class*="js-record-"]', $pel).forEach(function ($el) { | 
					
						
							|  |  |  |       var key; | 
					
						
							|  |  |  |       Array.prototype.some.call($el.classList, function (str) { | 
					
						
							|  |  |  |         if (/^js-record-/.test(str)) { | 
					
						
							|  |  |  |           key = str.replace(/^js-record-(.*)/, '$1'); | 
					
						
							|  |  |  |           return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       if (!key) { return; } | 
					
						
							|  |  |  |       if ('undefined' === typeof $el.value || 'INPUT' !== $el.tagName) { return; } | 
					
						
							|  |  |  |       record[key] = $el.value; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-21 01:47:37 -07:00
										 |  |  |     if (!record.id) { | 
					
						
							|  |  |  |       record.id = ''; | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |     if (!record.zone) { | 
					
						
							|  |  |  |       record.zone = myZone; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!record.name) { | 
					
						
							|  |  |  |       if (record.host) { | 
					
						
							|  |  |  |         record.name = record.host + '.' + myZone; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         record.name = myZone; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     record.type = record.type || $qs('.js-record-type', $pel).innerHTML || $qs('.js-record-type', $pel).value; | 
					
						
							|  |  |  |     console.log('record.type:', record.type); | 
					
						
							|  |  |  |     /* | 
					
						
							|  |  |  |     if (!tpls.recordsMap[record.type.toLowerCase()]) { | 
					
						
							|  |  |  |       record.typex = 'typex'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!existingRecord) { | 
					
						
							|  |  |  |       change = true; | 
					
						
							|  |  |  |       cache.recordsMap[record.id] = record; | 
					
						
							|  |  |  |       cache.records.push(record); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       console.log('keys:', Object.keys(record)); | 
					
						
							|  |  |  |       Object.keys(record).forEach(function (key) { | 
					
						
							| 
									
										
										
										
											2018-01-26 01:42:24 -07:00
										 |  |  |         console.log('key:', key); | 
					
						
							|  |  |  |         //if ('SOA' === record.type && 'zone' === key) { return; }
 | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |         if (existingRecord[key].toString() !== record[key].toString()) { | 
					
						
							|  |  |  |           change = true; | 
					
						
							|  |  |  |           existingRecord[key] = record[key]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-29 11:35:34 -07:00
										 |  |  |     if (!change) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     renderRecords(); | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-29 11:35:34 -07:00
										 |  |  |     return window.fetch( | 
					
						
							|  |  |  |       '/api/records/' + record.id | 
					
						
							|  |  |  |     , { method: 'POST' | 
					
						
							|  |  |  |       , headers: new window.Headers({ | 
					
						
							|  |  |  |           'Authorization': 'Bearer ' + auth | 
					
						
							|  |  |  |         , 'Content-Type': 'application/json;charset=UTF-8' | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       , body: JSON.stringify(record) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ).then(function (resp) { | 
					
						
							|  |  |  |       return resp.json().then(function (data) { | 
					
						
							|  |  |  |         if (data.error) { | 
					
						
							|  |  |  |           console.error(data); | 
					
						
							|  |  |  |           window.alert(data.error.message); | 
					
						
							|  |  |  |           return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         console.log('result:', data); | 
					
						
							|  |  |  |         if (!record.id) { | 
					
						
							|  |  |  |           record.id = data.id; | 
					
						
							|  |  |  |           renderRecords(); | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-01-29 11:35:34 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-29 14:54:03 -07:00
										 |  |  |   $on('button.js-record-destroy', 'click', function (ev) { | 
					
						
							|  |  |  |     console.log('destroy'); | 
					
						
							|  |  |  |     var $pel = ev.target.parentElement; | 
					
						
							|  |  |  |     var id = $qs('.js-record-id', $pel).value; | 
					
						
							|  |  |  |     var existingRecord = cache.recordsMap[id]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return window.fetch( | 
					
						
							|  |  |  |       '/api/records/' + id | 
					
						
							|  |  |  |     , { method: 'DELETE' | 
					
						
							|  |  |  |       , headers: new window.Headers({ | 
					
						
							|  |  |  |           'Authorization': 'Bearer ' + auth | 
					
						
							|  |  |  |         , 'Content-Type': 'application/json;charset=UTF-8' | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ).then(function (resp) { | 
					
						
							|  |  |  |       return resp.json().then(function (data) { | 
					
						
							|  |  |  |         if (data.error) { | 
					
						
							|  |  |  |           console.error(data); | 
					
						
							|  |  |  |           window.alert(data.error.message); | 
					
						
							|  |  |  |           return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-29 15:01:10 -07:00
										 |  |  |         delete cache.recordsMap[id]; | 
					
						
							|  |  |  |         cache.records.some(function (r, i) { | 
					
						
							|  |  |  |           if (r === existingRecord) { | 
					
						
							|  |  |  |             cache.records.splice(i, 1); | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         renderRecords(); | 
					
						
							| 
									
										
										
										
											2018-01-29 14:54:03 -07:00
										 |  |  |         console.log('result:', data); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-21 01:04:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |   tpls.newNs = $qs('.js-zone-form-tpl .js-zone-form-vns-tpl').innerHTML; | 
					
						
							|  |  |  |   $qs('.js-zone-form-tpl .js-zone-form-vns-tpl').innerHTML = ''; | 
					
						
							|  |  |  |   tpls.newZone = $qs('.js-zone-form-tpl').innerHTML; | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |   tpls.peer = $qs('.js-peer-tpl').innerHTML; | 
					
						
							|  |  |  |   $qs('.js-peer-tpl').innerHTML = ''; | 
					
						
							|  |  |  |   tpls.formsMap = {}; | 
					
						
							|  |  |  |   tpls.formsMap.SOA = $qs('.js-record-form-soa').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.NS = $qs('.js-record-form-ns').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.A = $qs('.js-record-form-a').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.AAAA = $qs('.js-record-form-aaaa').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.ANAME = $qs('.js-record-form-aname').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.CAA = $qs('.js-record-form-caa').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.CNAME = $qs('.js-record-form-cname').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.MX = $qs('.js-record-form-mx').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.PTR = $qs('.js-record-form-ptr').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.SRV = $qs('.js-record-form-srv').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.TXT = $qs('.js-record-form-txt').outerHTML; | 
					
						
							|  |  |  |   tpls.formsMap.typeX = $qs('.js-record-form-typex').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap = {}; | 
					
						
							|  |  |  |   tpls.recordsMap.soa = $qs('.js-record-soa').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.ns = $qs('.js-record-ns').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.a = $qs('.js-record-a').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.aaaa = $qs('.js-record-aaaa').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.aname = $qs('.js-record-aname').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.cname = $qs('.js-record-cname').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.caa = $qs('.js-record-caa').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.ptr = $qs('.js-record-ptr').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.mx = $qs('.js-record-mx').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.txt = $qs('.js-record-txt').outerHTML; | 
					
						
							|  |  |  |   tpls.recordsMap.srv = $qs('.js-record-srv').outerHTML; | 
					
						
							|  |  |  |   $qs('.js-record-tpl').innerHTML = ''; | 
					
						
							| 
									
										
										
										
											2018-01-30 01:33:19 -07:00
										 |  |  |   $qs('.js-zone-form-tpl').innerHTML = ''; | 
					
						
							| 
									
										
										
										
											2018-02-01 15:15:07 -07:00
										 |  |  |   $qs('select.js-record-form-type').value = ''; | 
					
						
							|  |  |  |   // Create a new 'change' event and dispatch it.
 | 
					
						
							|  |  |  |   $qs('select.js-record-form-type').dispatchEvent(new Event('change', { bubbles: true })); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:01:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-10 14:54:08 -07:00
										 |  |  | }()); |