walnut_launchpad.html/js/controllers/website-controller.js

91 lines
2.3 KiB
JavaScript
Raw Normal View History

app.controller('websiteCtrl', [
2017-08-15 16:56:46 +00:00
'$scope', 'Auth', 'azp@oauth3.org'
, function ($scope, Auth, Oauth3) {
2017-08-08 06:35:11 +00:00
2017-08-15 16:56:46 +00:00
var vm = this;
vm.oauth3 = Auth.oauth3;
2017-08-16 22:35:04 +00:00
vm.domains = [];
Auth.sessions.forEach(function (session) {
return Auth.select(session).then(function (oauth3) {
return oauth3.api('domains.list', {}).then(function (domains) {
if (domains.error) {
// not all tokens support all apis
return;
}
if (!Array.isArray(domains)) {
console.error('domains are not domains');
console.error(domains);
return;
}
console.log('domains');
console.log(domains);
domains.forEach(function (domain) {
domain.session = session.token.sub + '@' + session.token.iss;
vm.domains.push(domain);
});
});
});
});
2017-08-14 19:45:19 +00:00
vm.getDomains = function () {
vm.oauth3.api('domains.list', {}).then(function (result) {
vm.domains = result.registrations || result;
});
};
2017-08-16 22:35:04 +00:00
vm.setDomain = function () {
if (!vm.domains || !vm.domains.length) {
vm.domain = { domain: vm.newDomain };
return;
}
vm.domains.some(function (domain) {
if (domain.domain === vm.newDomain) {
vm.domain = domain;
return true;
}
});
if (!vm.domain) {
vm.domain = { domain: vm.newDomain };
}
};
2017-08-14 19:45:19 +00:00
vm.selectDomain = function (domain) {
vm.domain = domain;
2017-08-16 22:35:04 +00:00
vm.newDomain = domain.domain;
/*
2017-08-14 19:45:19 +00:00
return vm.oauth3.api('dns.list', { }).then(function (records) {
records = records.filter(function (r) {
return /^A(AAA)?$/i.test(r.type) && ((r.sld + '.' + r.tld) === domain || r.zone === domain.domain);
});
vm.records = records;
console.log('records');
console.log(records);
});
2017-08-16 22:35:04 +00:00
*/
2017-08-14 19:45:19 +00:00
};
vm.selectRecord = function (record) {
vm.record = record;
vm.currentHost = record.host; // .replace(new RegExp('\\.' + vm.domain.domain.replace(/\./g, '\\.') + '$', ''));
};
vm.setFiles = function (files) {
console.log('setFiles');
console.log(files);
console.log(vm.newFiles);
};
vm.createWebsite = function () {
var fd = new window.FormData();
var pkg = vm.oauth3.pkg('www@daplie.com');
return pkg.add({ hostname: vm.currentHost, multipart: { site: vm.currentFiles[0] } });
};
//vm.getDomains();
2017-08-08 20:54:25 +00:00
}]);