1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2024-12-02 06:24:11 +01:00
OwncloudBookmarksOfficial/js/addBm.js

85 lines
2.0 KiB
JavaScript
Raw Normal View History

(function($){
$.bookmark_dialog = function(el, options){
// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
// Add a reverse reference to the DOM object
2012-07-01 23:08:41 +02:00
base.$el.data('bookmark_dialog', base);
base.form_submit = function search_form_submit(event)
{
event.preventDefault();
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
2012-09-02 17:53:33 +02:00
success: function(data){
if(data.status == 'success'){
base.options['on_success'](data);
} else { // On failure
}
}
});
return false;
}
2012-08-13 21:58:46 +02:00
base.setTitle = function (str) {
base.$el.find('.title').val(str);
}
base.init = function(){
base.options = $.extend({},$.bookmark_dialog.defaultOptions, options);
base.$el.find('form').bind('submit.addBmform',base.form_submit);
// Init Tagging thing
base.$el.find('.tags').tagit({
allowSpaces: true,
availableTags: fullTags,
placeholderText: t('bookmark', 'Tags')
});
2012-06-29 14:12:29 +02:00
if(base.options['record']) { //Fill the form if it's an edit
record = base.options['record'];
base.$el.find('.record_id').val(record.id);
base.$el.find('.title').val(record.title);
base.$el.find('.url_input').val(record.url);
base.$el.find('.desc').val(record.description);
tagit_elem = base.$el.find('.tags');
2012-08-13 21:58:46 +02:00
if(record.tags) {
for(var i=0;i<record.tags.length;i++) {
tagit_elem.tagit('createTag', record.tags[i]);
}
2012-06-29 14:12:29 +02:00
}
}
};
base.init();
};
$.bookmark_dialog.defaultOptions = {
2012-06-29 14:12:29 +02:00
on_success: function(){},
bookmark_record: undefined
};
$.fn.bookmark_dialog = function(options){
return this.each(function(){
(new $.bookmark_dialog(this, options));
});
};
})(jQuery);
$(document).ready(function() {
$('body').bookmark_dialog({
'on_success': function(){
self.close();
}
});
});