/* Authors: * Endi Sukma Dewata * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2 only * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* REQUIRES: ipa.js */ function ipa_widget(spec) { spec = spec || {}; var that = {}; that.id = spec.id; that.name = spec.name; that.label = spec.label; that.read_only = spec.read_only; that._entity_name = spec.entity_name; that.undo = typeof spec.undo == 'undefined' ? true : spec.undo; that.init = spec.init || init; that.create = spec.create || create; that.setup = spec.setup || setup; that.load = spec.load || load; that.save = spec.save || save; that.clear = spec.clear || clear; that.superior = function(name) { var method = that[name]; return function () { return method.apply(that, arguments); }; }; that.__defineGetter__("entity_name", function(){ return that._entity_name; }); that.__defineSetter__("entity_name", function(entity_name){ that._entity_name = entity_name; }); function init() { } function create(container) { } function setup(container) { that.container = container; } function load(result) { } function save() { return []; } function clear() { } that.is_dirty = function(container) { if (!that.values) return true; var values = that.save(); if (values.length != that.values.length) return true; for (var i=0; i', { 'type': 'text', 'name': that.name, 'size': that.size }).appendTo(container); if (that.undo) { $('', { 'name': 'undo', 'style': 'display: none;', 'html': 'undo' }).appendTo(container); } }; that.setup = function(container) { this.widget_setup(container); var input = $('input[name="'+that.name+'"]', that.container); input.keyup(function() { that.show_undo(); }); var undo = that.get_undo(); undo.click(function() { that.reset(); }); }; that.load = function(result) { that.values = result[that.name] || ['']; if (that.read_only) { var input = $('input[name="'+that.name+'"]', that.container); var label = $('