Skip to content

Commit

Permalink
Merge branch 'master' of github.com:klokantech/jekylledit
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMikita committed May 24, 2016
2 parents 37b463d + c228b76 commit edfb799
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/jekylledit/controllers/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def user_profile(site_id, user_id):
# Get current user
# JE uses emails as identificators
if user_id == 'current':
user_id = 'current_user.email'
user_id = current_user.email
if request.method == 'GET':
user = site.get_user(user_id)
return jsonify(user)
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/abstractpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ klokantech.jekylledit.AbstractPage.prototype.start = goog.abstractMethod;


/**
* @param {Function=} opt_callback when done
* @param {function(boolean)=} opt_callback when done
*/
klokantech.jekylledit.AbstractPage.prototype.save = goog.abstractMethod;
6 changes: 5 additions & 1 deletion javascript/src/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ klokantech.jekylledit.Dashboard.prototype.loadClear = function(opt_callback) {
/** @inheritDoc */
klokantech.jekylledit.Dashboard.prototype.save = function(opt_callback) {
if (this.editor_) {
this.editor_.save();
this.editor_.save(opt_callback);
} else {
if (opt_callback) {
opt_callback(false);
}
}
};
25 changes: 24 additions & 1 deletion javascript/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,29 @@ klokantech.jekylledit.Editor.prototype.save = function(opt_callback) {
postData[langId]['metadata']['published'] = this.publishCheckbox_.checked;
}, this);

var missingRequiredFields = [];
goog.object.forEach(this.languages_, function(lang, langId) {
goog.object.forEach(lang.fields, function(el, k) {
if (el['required']) {
var value = postData[langId]['metadata'][k];
if (!value || value.length == 0) {
missingRequiredFields[k] = true;
}
}
}, this);
}, this);

if (goog.object.getKeys(missingRequiredFields).length > 0) {
alert(goog.string.format(
klokantech.jekylledit.lang.get('editor_required_missing'),
goog.object.getKeys(missingRequiredFields).join(', '))
);
if (opt_callback) {
opt_callback(false);
}
return;
}

if (this.editSource_) {
var lang = this.languages_[klokantech.jekylledit.lang.getLanguage()];
if (lang) {
Expand All @@ -527,7 +550,7 @@ klokantech.jekylledit.Editor.prototype.save = function(opt_callback) {
alert(klokantech.jekylledit.lang.get('editor_save_error'));
}
if (opt_callback) {
opt_callback();
opt_callback(e.target.isSuccess());
}
}, this), this.path_ ? 'PUT' : 'POST', JSON.stringify(result), {
'content-type': 'application/json'
Expand Down
3 changes: 3 additions & 0 deletions javascript/src/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ klokantech.jekylledit.lang.data_ = {
'editor_create_lang_btn': {
'en': 'Create "%s" variant of this post'
},
'editor_required_missing': {
'en': 'These fields are required and need to be filled in all languages: %s'
},
'editor_saved': {
'en': 'Changes saved!'
},
Expand Down
9 changes: 6 additions & 3 deletions javascript/src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ klokantech.jekylledit.Popup = function(repo, path, editableContent) {
if (goog.isDef(this.activePage_)) {
var page = this.pages_[this.activePage_];
if (page) {
page.save();
this.setVisible(false);
this.doesNeedClearLoad_ = true;
page.save(goog.bind(function(success) {
if (success) {
this.setVisible(false);
this.doesNeedClearLoad_ = true;
}
}, this));
}
}
}, false, this);
Expand Down
41 changes: 25 additions & 16 deletions javascript/src/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,32 @@ klokantech.jekylledit.Profile.prototype.start = function() {

/** @inheritDoc */
klokantech.jekylledit.Profile.prototype.loadClear = function(opt_callback) {
goog.dom.removeChildren(this.element_);
klokantech.jekylledit.utils.replaceWithSpinner(this.element_);

var fields = (this.config_['profile'] || {})['fields'] || {};
this.auth_.sendRequest('site/' + this.repo_ + '/user/current/profile',
goog.bind(function(e) {
var xhr = e.target;
var data = xhr.getResponseJson();

goog.object.forEach(fields, function(el, k) {
var label = klokantech.jekylledit.lang.getFrom(
el['label'], this.config_['languages']);
var labelEl = goog.dom.createDom(goog.dom.TagName.LABEL, undefined,
(label || k) + ':');
goog.dom.appendChild(this.element_, labelEl);
el['_je_getval'] = klokantech.jekylledit.utils.createField(
el, '', this.element_); //TODO: value
}, this);
goog.dom.removeChildren(this.element_);

var fields = (this.config_['profile'] || {})['fields'] || {};

if (opt_callback) {
opt_callback();
}
goog.object.forEach(fields, function(el, k) {
var label = klokantech.jekylledit.lang.getFrom(
el['label'], this.config_['languages']);
var labelEl = goog.dom.createDom(goog.dom.TagName.LABEL, undefined,
(label || k) + ':');
goog.dom.appendChild(this.element_, labelEl);
var value = data[k];
el['_je_getval'] = klokantech.jekylledit.utils.createField(
el, value, this.element_);
}, this);

if (opt_callback) {
opt_callback();
}
}, this));
};


Expand All @@ -98,15 +107,15 @@ klokantech.jekylledit.Profile.prototype.save = function(opt_callback) {
}
}, this);

this.auth_.sendRequest('site/' + this.repo_ + '/profile',
this.auth_.sendRequest('site/' + this.repo_ + '/user/current/profile',
goog.bind(function(e) {
if (e.target.isSuccess()) {
alert(klokantech.jekylledit.lang.get('profile_saved'));
} else {
alert(klokantech.jekylledit.lang.get('profile_save_error'));
}
if (opt_callback) {
opt_callback();
opt_callback(e.target.isSuccess());
}
}, this), 'PUT', JSON.stringify(result), {
'content-type': 'application/json'
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ klokantech.jekylledit.Translations.prototype.save = function(opt_callback) {
alert(klokantech.jekylledit.lang.get('trans_save_error'));
}
if (opt_callback) {
opt_callback();
opt_callback(e.target.isSuccess());
}
}, this), 'PUT', JSON.stringify(result), {
'content-type': 'application/json'
Expand Down

0 comments on commit edfb799

Please sign in to comment.