Skip to content

Commit

Permalink
Merge f24e961 into 58a4f6a
Browse files Browse the repository at this point in the history
  • Loading branch information
vidya-ram committed May 14, 2020
2 parents 58a4f6a + f24e961 commit df9dd7d
Show file tree
Hide file tree
Showing 9 changed files with 716 additions and 371 deletions.
422 changes: 288 additions & 134 deletions baseframe/static/css/baseframe-bs3.css

Large diffs are not rendered by default.

352 changes: 247 additions & 105 deletions baseframe/static/css/baseframe.css

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions baseframe/static/css/mui.css
Expand Up @@ -3938,11 +3938,21 @@ li p + ol {
z-index: 2;
}

.map {
position: relative;
}
.map .map__marker {
margin-top: 10px;
width: 100%;
height: 40em;
}
.map .map__clear {
position: absolute;
top: 22px;
right: 0;
z-index: 2;
background: #fff;
}

/* Cookies */
.cookies-required-alert,
Expand Down
129 changes: 69 additions & 60 deletions baseframe/static/js/baseframe-bootstrap.js
Expand Up @@ -44,24 +44,24 @@ function activate_widgets() {
};

// Activate codemirror on all textareas with class='markdown'
$('textarea.markdown').each(function() {
$('textarea.markdown').each(function () {
var editor = CodeMirror.fromTextArea(this, cm_markdown_config);
var delay;
editor.on('change', function(instance) {
editor.on('change', function (instance) {
clearTimeout(delay);
delay = setTimeout(function() {
delay = setTimeout(function () {
editor.save();
}, 300);
});
});

// Activate codemirror on all textareas with class='stylesheet'
$('textarea.stylesheet').each(function() {
$('textarea.stylesheet').each(function () {
var editor = CodeMirror.fromTextArea(this, cm_css_config);
var delay;
editor.on('change', function(instance) {
editor.on('change', function (instance) {
clearTimeout(delay);
delay = setTimeout(function() {
delay = setTimeout(function () {
editor.save();
}, 300);
});
Expand All @@ -73,10 +73,8 @@ function radioHighlight(radioName, highlightClass) {
$(selector + ':checked')
.parent()
.addClass(highlightClass);
var handler = function() {
$(selector)
.parent()
.removeClass(highlightClass);
var handler = function () {
$(selector).parent().removeClass(highlightClass);
$(selector + ':checked')
.parent()
.addClass(highlightClass);
Expand All @@ -99,12 +97,12 @@ function activate_geoname_autocomplete(
ajax: {
url: autocomplete_endpoint,
dataType: 'jsonp',
data: function(params, page) {
data: function (params, page) {
return {
q: params.term,
};
},
processResults: function(data, page) {
processResults: function (data, page) {
var rdata = [];
if (data.status == 'ok') {
for (var i = 0; i < data.result.length; i++) {
Expand All @@ -122,14 +120,14 @@ function activate_geoname_autocomplete(
//Setting label for Geoname ids
var val = $(selector).val();
if (val) {
val = val.map(function(id) {
val = val.map(function (id) {
return 'name=' + id;
});
var qs = val.join('&');
$.ajax(getname_endpoint + '?' + qs, {
accepts: 'application/json',
dataType: 'jsonp',
}).done(function(data) {
}).done(function (data) {
$(selector).empty();
var rdata = [];
if (data.status == 'ok') {
Expand All @@ -143,19 +141,17 @@ function activate_geoname_autocomplete(
);
rdata.push(data.result[i].geonameid);
}
$(selector)
.val(rdata)
.trigger('change');
$(selector).val(rdata).trigger('change');
}
});
}
}

$(function() {
$(function () {
// activate all widgets
activate_widgets();

var matchtab = function() {
var matchtab = function () {
var url = document.location.toString(),
tabmatch = null;
if (url.match('#/')) {
Expand All @@ -177,7 +173,7 @@ $(function() {
// Load correct tab when the page loads
matchtab();
// Change hash for tab click
$('.nav-tabs.nav-tabs-auto a').on('shown', function(e) {
$('.nav-tabs.nav-tabs-auto a').on('shown', function (e) {
window.location.hash = '#/' + e.target.hash.slice(1);
});
var url = document.location.toString();
Expand All @@ -190,7 +186,7 @@ $(function() {
}
});

$(function() {
$(function () {
// Code notice
console.log(
'Hello, curious geek. Our source is at https://github.com/hasgeek. Why not contribute a patch?'
Expand All @@ -206,18 +202,18 @@ window.Baseframe.Config = {
};

window.Baseframe.Forms = {
preventSubmitOnEnter: function(id) {
$('#' + id).on('keyup keypress', function(e) {
preventSubmitOnEnter: function (id) {
$('#' + id).on('keyup keypress', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
e.preventDefault();
return false;
}
});
},
lastuserAutocomplete: function(options) {
var assembleUsers = function(users) {
return users.map(function(user) {
lastuserAutocomplete: function (options) {
var assembleUsers = function (users) {
return users.map(function (user) {
return { id: user.buid, text: user.label };
});
};
Expand All @@ -230,7 +226,7 @@ window.Baseframe.Forms = {
ajax: {
url: options.autocomplete_endpoint,
dataType: 'jsonp',
data: function(params, page) {
data: function (params, page) {
if ('client_id' in options) {
return {
q: params.term,
Expand All @@ -243,7 +239,7 @@ window.Baseframe.Forms = {
};
}
},
processResults: function(data, page) {
processResults: function (data, page) {
var users = [];
if (data.status == 'ok') {
users = assembleUsers(data.users);
Expand All @@ -253,7 +249,7 @@ window.Baseframe.Forms = {
},
});
},
textAutocomplete: function(options) {
textAutocomplete: function (options) {
$('#' + options.id).select2({
placeholder: 'Type to select',
multiple: options.multiple,
Expand All @@ -262,16 +258,16 @@ window.Baseframe.Forms = {
ajax: {
url: options.autocomplete_endpoint,
dataType: 'json',
data: function(params, page) {
data: function (params, page) {
return {
q: params.term,
page: page,
};
},
processResults: function(data, page) {
processResults: function (data, page) {
return {
more: false,
results: data[options.key].map(function(item) {
results: data[options.key].map(function (item) {
return { id: item, text: item };
}),
};
Expand All @@ -296,9 +292,9 @@ window.Baseframe.Forms = {
using the unique form id. And the newly created 'p' tag
is inserted in the DOM below the field.
*/
showValidationErrors: function(formId, errors) {
showValidationErrors: function (formId, errors) {
var form = document.getElementById(formId);
Object.keys(errors).forEach(function(fieldName) {
Object.keys(errors).forEach(function (fieldName) {
if (Array.isArray(errors[fieldName])) {
var fieldWrapper = form.querySelector('#field-' + fieldName);
if (fieldWrapper) {
Expand Down Expand Up @@ -329,17 +325,17 @@ window.Baseframe.Forms = {
displays the loading indicator and submits the form via ajax.
On completing the ajax request, calls the onSuccess/onError callback function.
*/
handleFormSubmit: function(formId, url, onSuccess, onError, config) {
handleFormSubmit: function (formId, url, onSuccess, onError, config) {
$('#' + formId)
.find('button[type="submit"]')
.click(function(event) {
.click(function (event) {
event.preventDefault();
$.ajax({
url: url,
type: 'POST',
data: $('#' + formId).serialize(),
dataType: config.dataType ? config.dataType : 'json',
beforeSend: function() {
beforeSend: function () {
// Disable submit button to prevent double submit
$('#' + formId)
.find('button[type="submit"]')
Expand All @@ -351,23 +347,23 @@ window.Baseframe.Forms = {
if (config.beforeSend) config.beforeSend();
},
})
.done(function(remoteData) {
.done(function (remoteData) {
onSuccess(remoteData);
})
.fail(function(response) {
.fail(function (response) {
onError(response);
});
});
},
};

window.Baseframe.MapMarker = function(field) {
window.Baseframe.MapMarker = function (field) {
this.field = field;
this.activate();
return this;
};

window.Baseframe.MapMarker.prototype.activate = function() {
window.Baseframe.MapMarker.prototype.activate = function () {
var self = this;
Baseframe.Forms.preventSubmitOnEnter(this.field.location_id);

Expand All @@ -382,43 +378,56 @@ window.Baseframe.MapMarker.prototype.activate = function() {
locationNameInput: $('#' + this.field.location_id),
},
enableAutocomplete: true,
onchanged: function(currentLocation, radius, isMarkerDropped) {},
onlocationnotfound: function(locationName) {},
oninitialized: function(component) {},
onchanged: function (currentLocation, radius, isMarkerDropped) {
if ($('#' + self.field.location_id).val()) {
$('#' + self.field.map_id).removeClass('hidden');
}
},
onlocationnotfound: function (locationName) {},
oninitialized: function (component) {
// Locationpicker sets latitude and longitude field value to 0,
// this is to empty the fields and hide the map
if (!$('#' + self.field.location_id).val()) {
$('#' + self.field.latitude_id).val('');
$('#' + self.field.longitude_id).val('');
$('#' + self.field.map_id).addClass('hidden');
}
},
});

// On clicking clear, empty latitude, longitude, location fields and hide map
$('#' + this.field.clear_id).on('click', function (event) {
event.preventDefault();
$('#' + self.field.latitude_id).val('');
$('#' + self.field.longitude_id).val('');
$('#' + self.field.location_id).val('');
$('#' + self.field.map_id).addClass('hidden');
});
};

window.Baseframe.MapMarker.prototype.getDefaultLocation = function() {
window.Baseframe.MapMarker.prototype.getDefaultLocation = function () {
var latitude, longitude;
if (
$('#' + this.field.latitude_id).val() === '' &&
$('#' + this.field.longitude_id).val() === ''
) {
latitude = Baseframe.Config.defaultLatitude;
longitude = Baseframe.Config.defaultLongitude;
} else {
latitude = $('#' + this.field.latitude_id).val();
longitude = $('#' + this.field.longitude_id).val();
}
latitude = $('#' + this.field.latitude_id).val();
longitude = $('#' + this.field.longitude_id).val();
return { latitude: latitude, longitude: longitude };
};

window.ParsleyConfig = {
errorsWrapper: '<div></div>',
errorTemplate: '<p class="help-error"></p>',
errorClass: 'has-error',
classHandler: function(ParsleyField) {
classHandler: function (ParsleyField) {
return ParsleyField.$element.closest('.form-group');
},
errorsContainer: function(ParsleyField) {
errorsContainer: function (ParsleyField) {
return ParsleyField.$element.closest('.controls');
},
i18n: {
en: {},
},
};

$(function() {
$(function () {
// Override Parsley.js's default messages after the page loads.
// Our versions don't use full stops after phrases.
window.ParsleyConfig.i18n.en = $.extend(window.ParsleyConfig.i18n.en || {}, {
Expand Down Expand Up @@ -449,13 +458,13 @@ $(function() {
}
);

var csrfRefresh = function() {
var csrfRefresh = function () {
$.ajax({
type: 'GET',
url: '/api/baseframe/1/csrf/refresh',
timeout: 5000,
dataType: 'json',
success: function(data) {
success: function (data) {
$('meta[name="csrf-token"]').attr('content', data.csrf_token);
$('input[name="csrf_token"]').val(data.csrf_token);
},
Expand Down

0 comments on commit df9dd7d

Please sign in to comment.