Skip to content

Commit

Permalink
Tagging support
Browse files Browse the repository at this point in the history
  • Loading branch information
murat committed Dec 6, 2017
1 parent 14c025e commit fc6360f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions app/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ <h1>fazlamesai.net'e gönder</h1>
<input class="form-control" type="text" name="link[url]" id="link_url">
</div>

<div class="form-group">
<label class="control-label" for="link_url">Etiketler <abbr title="örn; chrome,extension">(virgüllü)</abbr></label>
<input class="form-control" type="text" name="link[tag_list][]" id="link_tags">
</div>

<div class="form-group">
<input type="submit" value="Gönder">
<span id="status" class="pull-right"></span>
Expand Down
26 changes: 17 additions & 9 deletions app/scripts.babel/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var getOptions = new Promise(function (resolve, reject) {
resolve('Stuff worked!');
} else {
if (document.getElementById('link_form')) {
document.getElementById('link_form').innerHTML = 'Lütfen önce <a style="color:red;" id="options_toggle">eklenti ayarlarından</a> kişisel erişim anahtarınızı ekleyin.';
document.getElementById('link_form').innerHTML = 'Lütfen önce <a style="color:red; cursor:pointer;" id="options_toggle">eklenti ayarlarından</a> kişisel erişim anahtarınızı ekleyin.';
}

if (document.getElementById('options_toggle')) {
Expand Down Expand Up @@ -47,8 +47,13 @@ if (document.getElementById('link_form')) {
event.preventDefault();

var data = new FormData();
var tags = document.getElementById('link_tags').value;
if (tags.length && tags.search()) {
tags = tags.split(/[\s,]+/)
}
data.append('link[title]', document.getElementById('link_title').value);
data.append('link[url]', document.getElementById('link_url').value);
data.append('link[tag_list][]', tags);

var xhr = new XMLHttpRequest()
if (xhr.withCredentials === undefined) {
Expand All @@ -57,22 +62,25 @@ if (document.getElementById('link_form')) {

xhr.addEventListener('readystatechange', function () {
if (this.readyState === 4 && this.status === 200) {
document.getElementById('status').innerHTML = 'Link paylaşıldı. Yayınlamayı/değerlendirmeye göndermeyi unutmayın!!!';
document.getElementById('link_form').reset();
var url = JSON.parse(this.responseText).url;
setTimeout(function() {
chrome.tabs.create({ url: url });
}, 2000);
} else {
var resp = JSON.parse(this.responseText),
url = resp.url;
document.getElementById('status').innerHTML = resp.message;
document.getElementById('link_form').reset();
setTimeout(function() {
chrome.tabs.create({ url: url });
}, 2000);
} else if (this.status === 401) {
document.getElementById('status').innerHTML = 'Oturum açma başarısız!';
} else {
document.getElementById('status').innerHTML = 'Bir sorun oluştu.';
}
});

xhr.open('POST', new_link_url, true);
xhr.setRequestHeader('authorization', 'Bearer ' + auth_token);
xhr.setRequestHeader('cache-control', 'no-cache');
xhr.onerror = function () {
document.getElementById('status').innerHTML = 'Başarısız.';
document.getElementById('status').innerHTML = 'Bir sorun oluştu.';
};
xhr.send(data);
});
Expand Down

0 comments on commit fc6360f

Please sign in to comment.