Permalink
Browse files

changed folderstructur of branch

  • Loading branch information...
1 parent b4079a1 commit ce3b22725f01034e41252e361fbb804ff0cd6d2c @IfSixWasNine committed Mar 31, 2012
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,200 @@
+/*
+ * requires: jquery-stringifyJSON.js
+ *
+ * jQuery stringifyJSON
+ * http://github.com/flowersinthesand/jquery-stringifyJSON
+ */
+
+if(typeof Object.create !== 'function') {
+ Object.create = function(o) {
+ function F() {};
+ F.prototype = o;
+ return new F();
+ };
+}
+
+var SmoothDataList = {
+
+ _init: function(options, element) {
+ this.options = $.extend({}, this._DEFAULTS, options);
+ this.element = element;
+ this.$element = $(element);
+ this._run();
+ return this;
+ },
+
+ _DEFAULTS: {
+ outputElementId: null,
+ cols: [],
+ rowset: []
+ },
+
+ _run: function() {
+ this.$element.html('').addClass('smoothDataList');
+
+ $(document.createElement('li'))
+ .addClass('smoothDataList-add')
+ .html('create')
+ .click($.proxy(this.openDialog, this))
+ .appendTo(this.element);
+
+ for(i in this.options.rowset) this._addItem(this.options.rowset[i]);
+
+ if(this.options.outputElementId !== null) {
+ $(document.createElement('textarea'))
+ .attr('id', this.options.outputElementId)
+ .css('display', 'none')
+ .appendTo(this.element);
+ this._updateOutputElement(this.options.rowset);
+ }
+ },
+
+ _addItem: function(itemData) {
+ var item = $(document.createElement('li'))
+ .addClass('smoothDataList-item')
+ .data('itemData', itemData)
+ .insertBefore($('.smoothDataList-add'));
+ for(i in itemData) {
+ var strHtml = '';
+ if(typeof itemData[i] === 'string')
+ strHtml = itemData[i];
+ else
+ for(y in itemData[i]) strHtml = itemData[i][y];
+ $(document.createElement('span'))
+ .addClass('smoothDataList-' + i)
+ .html(strHtml)
+ .appendTo(item);
+ }
+
+ $(document.createElement('span'))
+ .addClass('smoothDataList-remove')
+ .html('remove')
+ .click($.proxy(this._removeItem, this))
+ .appendTo(item);
+
+ $(document.createElement('div'))
+ .css({clear: 'both'})
+ .appendTo(item);
+ },
+
+ _submitItem: function() {
+ var itemData = {},
+ prop;
+ $.each($('#smoothDataList-addDialog').children('.smoothDataList-dataItem'), function() {
+ prop = $(this).children('div').html();
+ if($(this).children('input,textarea').length !== 0) {
+ itemData[prop] = $(this).children('input,textarea').val();
+ } else {
+ itemData[prop] = {};
+ itemData[prop][$(this).children('select').children(':selected').val()] = $(this).children('select').children(':selected').text();
+ }
+ });
+ this._addItem(itemData);
+ this.options.rowset.push(itemData);
+ this._updateOutputElement(this.options.rowset);
+ $('#smoothDataList-addDialog').remove();
+ },
+
+ _removeItem: function(e) {
+ var itemData = $(e.target).parent().data('itemData');
+ this.options.rowset.splice(this.options.rowset.indexOf(itemData), 1);
+ this._updateOutputElement(this.options.rowset);
+ $(e.target).parent().remove();
+
+ },
+
+ _updateOutputElement: function(rowset) {
+ if(this.options.outputElementId !== null)
+ $('#' + this.options.outputElementId).html(jQuery.stringifyJSON(rowset));
+ },
+
+ _createTextInput: function(inputData) {
+ return $(document.createElement('input'))
+ .attr('type', 'text')
+ .val(inputData || '');
+ },
+
+ _createSelectInput: function(inputData) {
+ var select = $(document.createElement('select'));
+ for(i in inputData) {
+ $(document.createElement('option'))
+ .val(i)
+ .html(inputData[i])
+ .appendTo(select);
+ }
+ return select;
+ },
+
+ _createTextareaInput: function(inputData) {
+ return $(document.createElement('textarea').html(inputData));
+ },
+
+
+
+
+
+
+
+ openDialog: function() {
+ var viewport = {
+ width: $(window).width(),
+ height: $(window).height()
+ };
+
+ var dialog = $(document.createElement('ul'))
+ .attr('id', 'smoothDataList-addDialog')
+ .appendTo('body');
+
+ var row;
+ for(i in this.options.cols) {
+ row = $(document.createElement('li'))
+ .addClass('smoothDataList-dataItem')
+ .appendTo(dialog);
+
+ $(document.createElement('div'))
+ .html(this.options.cols[i].label)
+ .appendTo(row);
+
+ if(jQuery.inArray(this.options.cols[i].input, 'text select textarea'.split(' ')) !== -1) {
+ var methodName = '_create' + this.options.cols[i].input.substr(0,1).toUpperCase()
+ + this.options.cols[i].input.substr(1, this.options.cols[i].input.length)
+ + 'Input';
+ var inputField = this[methodName](this.options.cols[i].inputData);
+ $(inputField).appendTo(row);
+ }
+ }
+
+ row = $(document.createElement('li'))
+ .addClass('smoothDataList-submitListitem')
+ .appendTo(dialog);
+
+ $(document.createElement('div'))
+ .addClass('smoothDataList-submitButton')
+ .html('add')
+ .click($.proxy(this._submitItem, this))
+ .appendTo(row);
+
+ dialog.css({
+ position: 'absolute',
+ top: viewport.height / 2 - dialog.height() / 2 + 'px',
+ left : viewport.width / 2 - dialog.width() / 2 + 'px'
+ });
+ },
+
+ closDialoge: function() {
+ if($('#smoothDataList-addDialog').length > 0) $('#smoothDataList-addDialog').remove();
+ }
+
+};
+
+(function($, window, document, undefined) {
+ $.fn.smoothDataList = function(options) {
+ if(this.length) {
+ return this.each(function() {
+ var smoothDataList = Object.create(SmoothDataList);
+ smoothDataList._init(options, this);
+ $.data(this, 'smoothDataList', smoothDataList);
+ });
+ }
+ };
+})(jQuery, window, document);

0 comments on commit ce3b227

Please sign in to comment.