Merge branch 'js_pop_up'

This commit is contained in:
chris2tof 2011-12-28 20:52:33 +08:00
commit a57dd62281
18 changed files with 1621 additions and 706 deletions

View File

@ -5,4 +5,7 @@
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require jquery_ujs
//= require jquery.form
//= require rss
//= require ajax_form

View File

@ -0,0 +1,7 @@
$('#submit_button').live('click', function(){
$('#ajaxForm').ajaxSubmit({
beforeSubmit: function(a,f,o) {
o.dataType = 'script';
}
});
});

View File

@ -0,0 +1,980 @@
/*!
* jQuery Form Plugin
* version: 2.94 (13-DEC-2011)
* @requires jQuery v1.3.2 or later
*
* Examples and documentation at: http://malsup.com/jquery/form/
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
;(function($) {
/*
Usage Note:
-----------
Do not use both ajaxSubmit and ajaxForm on the same form. These
functions are intended to be exclusive. Use ajaxSubmit if you want
to bind your own submit handler to the form. For example,
$(document).ready(function() {
$('#myForm').bind('submit', function(e) {
e.preventDefault(); // <-- important
$(this).ajaxSubmit({
target: '#output'
});
});
});
Use ajaxForm when you want the plugin to manage all the event binding
for you. For example,
$(document).ready(function() {
$('#myForm').ajaxForm({
target: '#output'
});
});
When using ajaxForm, the ajaxSubmit function will be invoked for you
at the appropriate time.
*/
/**
* ajaxSubmit() provides a mechanism for immediately submitting
* an HTML form using AJAX.
*/
$.fn.ajaxSubmit = function(options) {
// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
if (!this.length) {
log('ajaxSubmit: skipping submit process - no element selected');
return this;
}
var method, action, url, $form = this;
if (typeof options == 'function') {
options = { success: options };
}
method = this.attr('method');
action = this.attr('action');
url = (typeof action === 'string') ? $.trim(action) : '';
url = url || window.location.href || '';
if (url) {
// clean url (don't include hash vaue)
url = (url.match(/^([^#]+)/)||[])[1];
}
options = $.extend(true, {
url: url,
success: $.ajaxSettings.success,
type: method || 'GET',
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
}, options);
// hook for manipulating the form data before it is extracted;
// convenient for use with rich editors like tinyMCE or FCKEditor
var veto = {};
this.trigger('form-pre-serialize', [this, options, veto]);
if (veto.veto) {
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
return this;
}
// provide opportunity to alter form data before it is serialized
if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
log('ajaxSubmit: submit aborted via beforeSerialize callback');
return this;
}
var traditional = options.traditional;
if ( traditional === undefined ) {
traditional = $.ajaxSettings.traditional;
}
var qx,n,v,a = this.formToArray(options.semantic);
if (options.data) {
options.extraData = options.data;
qx = $.param(options.data, traditional);
}
// give pre-submit callback an opportunity to abort the submit
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
log('ajaxSubmit: submit aborted via beforeSubmit callback');
return this;
}
// fire vetoable 'validate' event
this.trigger('form-submit-validate', [a, this, options, veto]);
if (veto.veto) {
log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
return this;
}
var q = $.param(a, traditional);
if (qx) {
q = ( q ? (q + '&' + qx) : qx );
}
if (options.type.toUpperCase() == 'GET') {
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
options.data = null; // data is null for 'get'
}
else {
options.data = q; // data is the query string for 'post'
}
var callbacks = [];
if (options.resetForm) {
callbacks.push(function() { $form.resetForm(); });
}
if (options.clearForm) {
callbacks.push(function() { $form.clearForm(options.includeHidden); });
}
// perform a load on the target only if dataType is not provided
if (!options.dataType && options.target) {
var oldSuccess = options.success || function(){};
callbacks.push(function(data) {
var fn = options.replaceTarget ? 'replaceWith' : 'html';
$(options.target)[fn](data).each(oldSuccess, arguments);
});
}
else if (options.success) {
callbacks.push(options.success);
}
options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
var context = options.context || options; // jQuery 1.4+ supports scope context
for (var i=0, max=callbacks.length; i < max; i++) {
callbacks[i].apply(context, [data, status, xhr || $form, $form]);
}
};
// are there files to upload?
var fileInputs = $('input:file:enabled[value]', this); // [value] (issue #113)
var hasFileInputs = fileInputs.length > 0;
var mp = 'multipart/form-data';
var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
var fileAPI = !!(hasFileInputs && fileInputs.get(0).files && window.FormData);
log("fileAPI :" + fileAPI);
var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
// options.iframe allows user to force iframe mode
// 06-NOV-09: now defaulting to iframe mode if file input is detected
if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
// hack to fix Safari hang (thanks to Tim Molendijk for this)
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
if (options.closeKeepAlive) {
$.get(options.closeKeepAlive, function() {
fileUploadIframe(a);
});
}
else {
fileUploadIframe(a);
}
}
else if ((hasFileInputs || multipart) && fileAPI) {
options.progress = options.progress || $.noop;
fileUploadXhr(a);
}
else {
$.ajax(options);
}
// fire 'notify' event
this.trigger('form-submit-notify', [this, options]);
return this;
// XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
function fileUploadXhr(a) {
var formdata = new FormData();
for (var i=0; i < a.length; i++) {
if (a[i].type == 'file')
continue;
formdata.append(a[i].name, a[i].value);
}
$form.find('input:file:enabled').each(function(){
var name = $(this).attr('name'), files = this.files;
if (name) {
for (var i=0; i < files.length; i++)
formdata.append(name, files[i]);
}
});
if (options.extraData) {
for (var k in options.extraData)
formdata.append(k, options.extraData[k])
}
options.data = null;
var s = $.extend(true, {}, $.ajaxSettings, options, {
contentType: false,
processData: false,
cache: false,
type: 'POST'
});
s.context = s.context || s;
s.data = null;
var beforeSend = s.beforeSend;
s.beforeSend = function(xhr, o) {
o.data = formdata;
if(xhr.upload) { // unfortunately, jQuery doesn't expose this prop (http://bugs.jquery.com/ticket/10190)
xhr.upload.onprogress = function(event) {
o.progress(event.position, event.total);
};
}
if(beforeSend)
beforeSend.call(o, xhr, options);
};
$.ajax(s);
}
// private function for handling file uploads (hat tip to YAHOO!)
function fileUploadIframe(a) {
var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
var useProp = !!$.fn.prop;
if (a) {
if ( useProp ) {
// ensure that every serialized input is still enabled
for (i=0; i < a.length; i++) {
el = $(form[a[i].name]);
el.prop('disabled', false);
}
} else {
for (i=0; i < a.length; i++) {
el = $(form[a[i].name]);
el.removeAttr('disabled');
}
};
}
if ($(':input[name=submit],:input[id=submit]', form).length) {
// if there is an input with a name or id of 'submit' then we won't be
// able to invoke the submit fn on the form (at least not x-browser)
alert('Error: Form elements must not have name or id of "submit".');
return;
}
s = $.extend(true, {}, $.ajaxSettings, options);
s.context = s.context || s;
id = 'jqFormIO' + (new Date().getTime());
if (s.iframeTarget) {
$io = $(s.iframeTarget);
n = $io.attr('name');
if (n == null)
$io.attr('name', id);
else
id = n;
}
else {
$io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
}
io = $io[0];
xhr = { // mock object
aborted: 0,
responseText: null,
responseXML: null,
status: 0,
statusText: 'n/a',
getAllResponseHeaders: function() {},
getResponseHeader: function() {},
setRequestHeader: function() {},
abort: function(status) {
var e = (status === 'timeout' ? 'timeout' : 'aborted');
log('aborting upload... ' + e);
this.aborted = 1;
$io.attr('src', s.iframeSrc); // abort op in progress
xhr.error = e;
s.error && s.error.call(s.context, xhr, e, status);
g && $.event.trigger("ajaxError", [xhr, s, e]);
s.complete && s.complete.call(s.context, xhr, e);
}
};
g = s.global;
// trigger ajax global events so that activity/block indicators work like normal
if (g && ! $.active++) {
$.event.trigger("ajaxStart");
}
if (g) {
$.event.trigger("ajaxSend", [xhr, s]);
}
if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
if (s.global) {
$.active--;
}
return;
}
if (xhr.aborted) {
return;
}
// add submitting element to data if we know it
sub = form.clk;
if (sub) {
n = sub.name;
if (n && !sub.disabled) {
s.extraData = s.extraData || {};
s.extraData[n] = sub.value;
if (sub.type == "image") {
s.extraData[n+'.x'] = form.clk_x;
s.extraData[n+'.y'] = form.clk_y;
}
}
}
var CLIENT_TIMEOUT_ABORT = 1;
var SERVER_ABORT = 2;
function getDoc(frame) {
var doc = frame.contentWindow ? frame.contentWindow.document : frame.contentDocument ? frame.contentDocument : frame.document;
return doc;
}
// Rails CSRF hack (thanks to Yvan Barthelemy)
var csrf_token = $('meta[name=csrf-token]').attr('content');
var csrf_param = $('meta[name=csrf-param]').attr('content');
if (csrf_param && csrf_token) {
s.extraData = s.extraData || {};
s.extraData[csrf_param] = csrf_token;
}
// take a breath so that pending repaints get some cpu time before the upload starts
function doSubmit() {
// make sure form attrs are set
var t = $form.attr('target'), a = $form.attr('action');
// update form attrs in IE friendly way
form.setAttribute('target',id);
if (!method) {
form.setAttribute('method', 'POST');
}
if (a != s.url) {
form.setAttribute('action', s.url);
}
// ie borks in some cases when setting encoding
if (! s.skipEncodingOverride && (!method || /post/i.test(method))) {
$form.attr({
encoding: 'multipart/form-data',
enctype: 'multipart/form-data'
});
}
// support timout
if (s.timeout) {
timeoutHandle = setTimeout(function() { timedOut = true; cb(CLIENT_TIMEOUT_ABORT); }, s.timeout);
}
// look for server aborts
function checkState() {
try {
var state = getDoc(io).readyState;
log('state = ' + state);
if (state.toLowerCase() == 'uninitialized')
setTimeout(checkState,50);
}
catch(e) {
log('Server abort: ' , e, ' (', e.name, ')');
cb(SERVER_ABORT);
timeoutHandle && clearTimeout(timeoutHandle);
timeoutHandle = undefined;
}
}
// add "extra" data to form if provided in options
var extraInputs = [];
try {
if (s.extraData) {
for (var n in s.extraData) {
extraInputs.push(
$('<input type="hidden" name="'+n+'">').attr('value',s.extraData[n])
.appendTo(form)[0]);
}
}
if (!s.iframeTarget) {
// add iframe to doc and submit the form
$io.appendTo('body');
io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
}
setTimeout(checkState,15);
form.submit();
}
finally {
// reset attrs and remove "extra" input elements
form.setAttribute('action',a);
if(t) {
form.setAttribute('target', t);
} else {
$form.removeAttr('target');
}
$(extraInputs).remove();
}
}
if (s.forceSync) {
doSubmit();
}
else {
setTimeout(doSubmit, 10); // this lets dom updates render
}
var data, doc, domCheckCount = 50, callbackProcessed;
function cb(e) {
if (xhr.aborted || callbackProcessed) {
return;
}
try {
doc = getDoc(io);
}
catch(ex) {
log('cannot access response document: ', ex);
e = SERVER_ABORT;
}
if (e === CLIENT_TIMEOUT_ABORT && xhr) {
xhr.abort('timeout');
return;
}
else if (e == SERVER_ABORT && xhr) {
xhr.abort('server abort');
return;
}
if (!doc || doc.location.href == s.iframeSrc) {
// response not received yet
if (!timedOut)
return;
}
io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
var status = 'success', errMsg;
try {
if (timedOut) {
throw 'timeout';
}
var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
log('isXml='+isXml);
if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
if (--domCheckCount) {
// in some browsers (Opera) the iframe DOM is not always traversable when
// the onload callback fires, so we loop a bit to accommodate
log('requeing onLoad callback, DOM not available');
setTimeout(cb, 250);
return;
}
// let this fall through because server response could be an empty document
//log('Could not access iframe DOM after mutiple tries.');
//throw 'DOMException: not available';
}
//log('response detected');
var docRoot = doc.body ? doc.body : doc.documentElement;
xhr.responseText = docRoot ? docRoot.innerHTML : null;
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
if (isXml)
s.dataType = 'xml';
xhr.getResponseHeader = function(header){
var headers = {'content-type': s.dataType};
return headers[header];
};
// support for XHR 'status' & 'statusText' emulation :
if (docRoot) {
xhr.status = Number( docRoot.getAttribute('status') ) || xhr.status;
xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
}
var dt = (s.dataType || '').toLowerCase();
var scr = /(json|script|text)/.test(dt);
if (scr || s.textarea) {
// see if user embedded response in textarea
var ta = doc.getElementsByTagName('textarea')[0];
if (ta) {
xhr.responseText = ta.value;
// support for XHR 'status' & 'statusText' emulation :
xhr.status = Number( ta.getAttribute('status') ) || xhr.status;
xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
}
else if (scr) {
// account for browsers injecting pre around json response
var pre = doc.getElementsByTagName('pre')[0];
var b = doc.getElementsByTagName('body')[0];
if (pre) {
xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
}
else if (b) {
xhr.responseText = b.textContent ? b.textContent : b.innerText;
}
}
}
else if (dt == 'xml' && !xhr.responseXML && xhr.responseText != null) {
xhr.responseXML = toXml(xhr.responseText);
}
try {
data = httpData(xhr, dt, s);
}
catch (e) {
status = 'parsererror';
xhr.error = errMsg = (e || status);
}
}
catch (e) {
log('error caught: ',e);
status = 'error';
xhr.error = errMsg = (e || status);
}
if (xhr.aborted) {
log('upload aborted');
status = null;
}
if (xhr.status) { // we've set xhr.status
status = (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error';
}
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
if (status === 'success') {
s.success && s.success.call(s.context, data, 'success', xhr);
g && $.event.trigger("ajaxSuccess", [xhr, s]);
}
else if (status) {
if (errMsg == undefined)
errMsg = xhr.statusText;
s.error && s.error.call(s.context, xhr, status, errMsg);
g && $.event.trigger("ajaxError", [xhr, s, errMsg]);
}
g && $.event.trigger("ajaxComplete", [xhr, s]);
if (g && ! --$.active) {
$.event.trigger("ajaxStop");
}
s.complete && s.complete.call(s.context, xhr, status);
callbackProcessed = true;
if (s.timeout)
clearTimeout(timeoutHandle);
// clean up
setTimeout(function() {
if (!s.iframeTarget)
$io.remove();
xhr.responseXML = null;
}, 100);
}
var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
if (window.ActiveXObject) {
doc = new ActiveXObject('Microsoft.XMLDOM');
doc.async = 'false';
doc.loadXML(s);
}
else {
doc = (new DOMParser()).parseFromString(s, 'text/xml');
}
return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
};
var parseJSON = $.parseJSON || function(s) {
return window['eval']('(' + s + ')');
};
var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
var ct = xhr.getResponseHeader('content-type') || '',
xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
data = xml ? xhr.responseXML : xhr.responseText;
if (xml && data.documentElement.nodeName === 'parsererror') {
$.error && $.error('parsererror');
}
if (s && s.dataFilter) {
data = s.dataFilter(data, type);
}
if (typeof data === 'string') {
if (type === 'json' || !type && ct.indexOf('json') >= 0) {
data = parseJSON(data);
} else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
$.globalEval(data);
}
}
return data;
};
}
};
/**
* ajaxForm() provides a mechanism for fully automating form submission.
*
* The advantages of using this method instead of ajaxSubmit() are:
*
* 1: This method will include coordinates for <input type="image" /> elements (if the element
* is used to submit the form).
* 2. This method will include the submit element's name/value data (for the element that was
* used to submit the form).
* 3. This method binds the submit() method to the form for you.
*
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
* passes the options argument along after properly binding events for submit elements and
* the form itself.
*/
$.fn.ajaxForm = function(options) {
// in jQuery 1.3+ we can fix mistakes with the ready state
if (this.length === 0) {
var o = { s: this.selector, c: this.context };
if (!$.isReady && o.s) {
log('DOM not ready, queuing ajaxForm');
$(function() {
$(o.s,o.c).ajaxForm(options);
});
return this;
}
// is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
return this;
}
return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
e.preventDefault();
$(this).ajaxSubmit(options);
}
}).bind('click.form-plugin', function(e) {
var target = e.target;
var $el = $(target);
if (!($el.is(":submit,input:image"))) {
// is this a child element of the submit el? (ex: a span within a button)
var t = $el.closest(':submit');
if (t.length == 0) {
return;
}
target = t[0];
}
var form = this;
form.clk = target;
if (target.type == 'image') {
if (e.offsetX != undefined) {
form.clk_x = e.offsetX;
form.clk_y = e.offsetY;
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
var offset = $el.offset();
form.clk_x = e.pageX - offset.left;
form.clk_y = e.pageY - offset.top;
} else {
form.clk_x = e.pageX - target.offsetLeft;
form.clk_y = e.pageY - target.offsetTop;
}
}
// clear form vars
setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
});
};
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
$.fn.ajaxFormUnbind = function() {
return this.unbind('submit.form-plugin click.form-plugin');
};
/**
* formToArray() gathers form element data into an array of objects that can
* be passed to any of the following ajax functions: $.get, $.post, or load.
* Each object in the array has both a 'name' and 'value' property. An example of
* an array for a simple login form might be:
*
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
*
* It is this array that is passed to pre-submit callback functions provided to the
* ajaxSubmit() and ajaxForm() methods.
*/
$.fn.formToArray = function(semantic) {
var a = [];
if (this.length === 0) {
return a;
}
var form = this[0];
var els = semantic ? form.getElementsByTagName('*') : form.elements;
if (!els) {
return a;
}
var i,j,n,v,el,max,jmax;
for(i=0, max=els.length; i < max; i++) {
el = els[i];
n = el.name;
if (!n) {
continue;
}
if (semantic && form.clk && el.type == "image") {
// handle image inputs on the fly when semantic == true
if(!el.disabled && form.clk == el) {
a.push({name: n, value: $(el).val(), type: el.type });
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
}
continue;
}
v = $.fieldValue(el, true);
if (v && v.constructor == Array) {
for(j=0, jmax=v.length; j < jmax; j++) {
a.push({name: n, value: v[j]});
}
}
else if (v !== null && typeof v != 'undefined') {
a.push({name: n, value: v, type: el.type});
}
}
if (!semantic && form.clk) {
// input type=='image' are not found in elements array! handle it here
var $input = $(form.clk), input = $input[0];
n = input.name;
if (n && !input.disabled && input.type == 'image') {
a.push({name: n, value: $input.val()});
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
}
}
return a;
};
/**
* Serializes form data into a 'submittable' string. This method will return a string
* in the format: name1=value1&amp;name2=value2
*/
$.fn.formSerialize = function(semantic) {
//hand off to jQuery.param for proper encoding
return $.param(this.formToArray(semantic));
};
/**
* Serializes all field elements in the jQuery object into a query string.
* This method will return a string in the format: name1=value1&amp;name2=value2
*/
$.fn.fieldSerialize = function(successful) {
var a = [];
this.each(function() {
var n = this.name;
if (!n) {
return;
}
var v = $.fieldValue(this, successful);
if (v && v.constructor == Array) {
for (var i=0,max=v.length; i < max; i++) {
a.push({name: n, value: v[i]});
}
}
else if (v !== null && typeof v != 'undefined') {
a.push({name: this.name, value: v});
}
});
//hand off to jQuery.param for proper encoding
return $.param(a);
};
/**
* Returns the value(s) of the element in the matched set. For example, consider the following form:
*
* <form><fieldset>
* <input name="A" type="text" />
* <input name="A" type="text" />
* <input name="B" type="checkbox" value="B1" />
* <input name="B" type="checkbox" value="B2"/>
* <input name="C" type="radio" value="C1" />
* <input name="C" type="radio" value="C2" />
* </fieldset></form>
*
* var v = $(':text').fieldValue();
* // if no values are entered into the text inputs
* v == ['','']
* // if values entered into the text inputs are 'foo' and 'bar'
* v == ['foo','bar']
*
* var v = $(':checkbox').fieldValue();
* // if neither checkbox is checked
* v === undefined
* // if both checkboxes are checked
* v == ['B1', 'B2']
*
* var v = $(':radio').fieldValue();
* // if neither radio is checked
* v === undefined
* // if first radio is checked
* v == ['C1']
*
* The successful argument controls whether or not the field element must be 'successful'
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
* The default value of the successful argument is true. If this value is false the value(s)
* for each element is returned.
*
* Note: This method *always* returns an array. If no valid value can be determined the
* array will be empty, otherwise it will contain one or more values.
*/
$.fn.fieldValue = function(successful) {
for (var val=[], i=0, max=this.length; i < max; i++) {
var el = this[i];
var v = $.fieldValue(el, successful);
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
continue;
}
v.constructor == Array ? $.merge(val, v) : val.push(v);
}
return val;
};
/**
* Returns the value of the field element.
*/
$.fieldValue = function(el, successful) {
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
if (successful === undefined) {
successful = true;
}
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
(t == 'checkbox' || t == 'radio') && !el.checked ||
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
tag == 'select' && el.selectedIndex == -1)) {
return null;
}
if (tag == 'select') {
var index = el.selectedIndex;
if (index < 0) {
return null;
}
var a = [], ops = el.options;
var one = (t == 'select-one');
var max = (one ? index+1 : ops.length);
for(var i=(one ? index : 0); i < max; i++) {
var op = ops[i];
if (op.selected) {
var v = op.value;
if (!v) { // extra pain for IE...
v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
}
if (one) {
return v;
}
a.push(v);
}
}
return a;
}
return $(el).val();
};
/**
* Clears the form data. Takes the following actions on the form's input fields:
* - input text fields will have their 'value' property set to the empty string
* - select elements will have their 'selectedIndex' property set to -1
* - checkbox and radio inputs will have their 'checked' property set to false
* - inputs of type submit, button, reset, and hidden will *not* be effected
* - button elements will *not* be effected
*/
$.fn.clearForm = function(includeHidden) {
return this.each(function() {
$('input,select,textarea', this).clearFields(includeHidden);
});
};
/**
* Clears the selected form elements.
*/
$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
return this.each(function() {
var t = this.type, tag = this.tagName.toLowerCase();
if (re.test(t) || tag == 'textarea' || (includeHidden && /hidden/.test(t)) ) {
this.value = '';
}
else if (t == 'checkbox' || t == 'radio') {
this.checked = false;
}
else if (tag == 'select') {
this.selectedIndex = -1;
}
});
};
/**
* Resets the form data. Causes all form elements to be reset to their original value.
*/
$.fn.resetForm = function() {
return this.each(function() {
// guard against an input with the name of 'reset'
// note that IE reports the reset function as an 'object'
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
this.reset();
}
});
};
/**
* Enables or disables any matching elements.
*/
$.fn.enable = function(b) {
if (b === undefined) {
b = true;
}
return this.each(function() {
this.disabled = !b;
});
};
/**
* Checks/unchecks any matching checkboxes or radio buttons and
* selects/deselects and matching option elements.
*/
$.fn.selected = function(select) {
if (select === undefined) {
select = true;
}
return this.each(function() {
var t = this.type;
if (t == 'checkbox' || t == 'radio') {
this.checked = select;
}
else if (this.tagName.toLowerCase() == 'option') {
var $sel = $(this).parent('select');
if (select && $sel[0] && $sel[0].type == 'select-one') {
// deselect all other options
$sel.find('option').selected(false);
}
this.selected = select;
}
});
};
// expose debug var
$.fn.ajaxSubmit.debug = false;
// helper fn for console logging
function log() {
if (!$.fn.ajaxSubmit.debug)
return;
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
if (window.console && window.console.log) {
window.console.log(msg);
}
else if (window.opera && window.opera.postError) {
window.opera.postError(msg);
}
};
})(jQuery);

View File

@ -1,57 +0,0 @@
<div id="UserRole_block" class="roles_block <%= @class %>">
<h2><%= t("admin.user_#{@attribute}") %></h2>
<div class="info_input">
<table border="0" cellspacing="0" cellpadding="0">
<thead class="list_head">
<tr>
<td><%= t('admin.key') %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
<% end %>
</tr>
</thead>
<tbody>
<tr class="list_item">
<td><%= is_new ? (f.text_field :key, {:style => "width:150px"}) : @user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %>
<td>
<%= text_field_tag "user_#{@attribute}_model[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:150px" %>
</td>
<% end %>
</tr>
</tbody>
</table>
</div>
</div>
<div id="attributes_block" class="roles_block <%= @class %>">
<h2>Attributes</h2>
<div class="info_input">
<table id='attributes' border="0" cellspacing="0" cellpadding="0">
<thead class="list_head">
<tr>
<td><%= t('admin.key') %></td>
<td><%= t('admin.multilingual') %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
<% end %>
<td><%= t('admin.type')%></td>
<td>&nbsp;</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5"><a href="#" class="add"><%= t(:add) %></a></td>
</tr>
</tfoot>
<tbody>
<%= render :partial => 'admin/user_attribute_models/attribute_model', :collection => @user_attribute_model.attribute_models %>
</tbody>
</table>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "user_attribute_model_form" %>
<% end -%>

View File

@ -0,0 +1,513 @@
//Created by Harry Bomrah on Sep 21 2011
$rss = jQuery.noConflict();
var rcom={
//Pass dom and will return binded dom with starting year till current
insertDatePanel : function(dom,year){
if(!year)year=1901;
if(dom=="")return false;
domid=dom.attr("id");
var dt = new Date();
current_year=dt.getFullYear();
var dthtml="Year: <select name='"+domid+"_year'>";
for(i=current_year;i>=year;i--){
dthtml+="<option value='"+i+"'>"+i+"</option>";
}
dthtml+="</select> Date: <select name='"+domid+"_date'>";
for(i=1;i<=31;i++){
if(i<10)
dthtml+="<option value='0"+i+"'>"+i+"</option>";
else
dthtml+="<option value='"+i+"'>"+i+"</option>";
}
dthtml+="</select> Month: <select name='"+domid+"_month'>";
var months= Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
for(i=1;i<12;i++){
if(i<10)
dthtml+="<option value='0"+i+"'>"+months[i]+"</option>";
else
dthtml+="<option value='"+i+"'>"+months[i]+"</option>";
}
dthtml+="</select>";
dom.html(dthtml);
},
//loading overlay around a dom...
loadingWrapper : function(dom, display){
if(display){
dom.prepend("<div id='loading_wrapper' class='loading'></div>");
$rss("#loading_wrapper").height(dom.height());
$rss("#loading_wrapper").width(dom.width());
}else{
domId=dom.attr("id");
$rss("#"+domId+" #loading_wrapper").remove();
}
},
//validating a dom....
validate : function(dom, validation, errormsg){
var domValue = dom.val();
var error = false;
var regex="";
var msg = "";
switch(validation){
case "required":
if(domValue=="")error=true;
msg="Cannot be empty.";
break;
case "email":
regex=/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
msg="Invalid Email Address.";
break;
case "number":
regex=/^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
msg = "Only numbers are accepted.";
break;
case "alphanumeric":
regex=/^\s*[a-zA-Z0-9,\s]+\s*$/;
msg="Only numbers, alphabets and spaces are allowed.";
break;
}
domId=dom.attr("name");
if(errormsg=="")errormsg=msg;
if(regex!="")if(!regex.test(domValue))error=true;
if(error){$rss("#"+domId+"_error").remove();dom.after("<span id='"+domId+"_error' class='error'>"+errormsg+"</span>");return false;} else{ $rss("#"+domId+"_error").remove();return true;}
},
bindToSpinner : function(dom,data,callbackFn){
var domId = dom.attr("id");
var dhtml="";
var spinnerValue=Array();
var spinnerDisplay=Array();
$rss.each(data,function(i,it){
$rss.each(data[i],function(key,it){
spinnerValue.push(it);
});
});
dhtml="<select name='"+domId+"'>";
for(i=0,y=1,z=0;i<spinnerValue.length/2;i++,y+=2,z+=2){
dhtml+="<option value='"+spinnerValue[z]+"'>"+spinnerValue[y]+"</option>";
}
dhtml+="</select>";
dom.html(dhtml);
if(typeof callbackFn=="function")
callbackFn.call(this, dhtml);
},
//binds the recieved json to a table
bindToTable : function(dom,data,headers,actions,css_class,callbackFn){
if(!css_class)css_class="";
var dhtml="<table width='100%' cellpadding='5' cellspacing='5' class='"+css_class+"' ><thead><tr>";
var domId = dom.attr("id");
if(actions){
var btnTitles=Array();
var btnFunctions=Array();
$rss.each(actions,function(title,func){
btnTitles.push(title);
btnFunctions.push(func);
});
rcom.translate(btnTitles,function(convertedData){
btnTitles=convertedData.slice();
rcom.translate(headers,function(convertedData){
headers=convertedData;
if(!data)return;
$rss.each(headers,function(i,head){
dhtml+="<th>"+head+"</th>";
});
dhtml+="</thead></tr>";
if(data.length==0)dhtml+="<tr><td colspan='"+headers.length+"' align='center'>No Data</td></tr>";
$rss.each(data,function(i,item){
var cl="";
if(i%2!=0)cl="even";
dhtml+="<tr id='"+domId+"_"+item.id+"' class='"+cl+"'>";
$rss.each(item,function(i,it){
if(i!="id"){
if(it==null)it="Not Set";
dhtml+="<td align='center'>"+it+"</td>";
}
})
dhtml+="<td align='center'>";
for(x=0;x<btnTitles.length;x++){
dhtml+="<button onclick='"+btnFunctions[x]+"("+item.id+")'>"+btnTitles[x]+"</button>";
}
dhtml+="</td>";
dhtml+="</tr>";
});
dhtml+="</table>";
dom.html(dhtml);
});
});
}else{
rcom.translate(headers,function(convertedData){
headers=convertedData;
if(!data)return;
if(headers.length>0){
$rss.each(headers,function(i,head){
dhtml+="<th>"+head+"</th>";
});
}
dhtml+="</thead></tr>";
if(data.length==0)dhtml+="<tr><td colspan='"+headers.length+"' align='center'>No Data</td></tr>";
$rss.each(data,function(i,item){
var cl="";
if(i%2!=0)cl="even";
dhtml+="<tr id='"+domId+"_"+item.id+"' class='"+cl+"'>";
$rss.each(item,function(i,it){
if(i!="id"){
if(it==null)it="Not Set";
dhtml+="<td align='center'>"+it+"</td>";
}
})
dhtml+="</tr>";
});
dhtml+="</table>";
dom.html(dhtml);
});
}
if(typeof callbackFn=="function")
callbackFn.call(this, dhtml);
},
//convert to date string which can be directly inserted in database or according to any format.
convertToInsertableDate : function(y,m,d,format){
var dt="";
if(m<10)m="0"+m;
if(d<10)d="0"+d;
switch(format){
case "yyyy-mm-dd":
dt= y+"-"+m+"-"+d;
break;
case "dd-mm-yyyy":
dt= d+"-"+m+"-"+y;
break;
case "mm-dd-yyyy":
dt= m+"-"+d+"-"+y;
break;
default:
dt= y+"-"+m+"-"+d;
break;
}
return dt;
},
//a fucntion to show specific divs and hide all other
showDoms : function(doms){
$rss("body").find("div").each(function(){$rss(this).hide();});
$rss.each(doms,function(i,dom){
dom.show();
});
},
//a function to translate the word or array..
translate : function(data,callbackFn){
var cdata="";
var status =true;
if(!data){
if(typeof callbackFn=="function")
callbackFn.call(this,cdata);
status=false;
}
if(data==""){
if(typeof callbackFn=="function")
callbackFn.call(this,cdata);
status=false;
}
if(status){
$rss.getJSON("../../classes/translate.php", {fn:"translateThis",tData:data},function(convertedData){
if(typeof callbackFn=="function")
callbackFn.call(this, convertedData);
});
}
},
// a function to bind JSON to list
bindToList : function(dom,data,callbackFn){
var domId = dom.attr("id");
var dhtml="";
var listValue=Array();
var listDisplay=Array();
$rss.each(data,function(i,it){
$rss.each(data[i],function(key,it){
listValue.push(it);
});
});
dhtml="<ul id='"+domId+"_list'>";
for(i=0,y=1,z=0;i<listValue.length/2;i++,y+=2,z+=2){
dhtml+="<li id='li_"+listValue[z]+"'>"+listValue[y]+"</li>";
}
dhtml+="</ul>";
dom.html(dhtml);
if(typeof callbackFn=="function")
callbackFn.call(this,dhtml);
},
makeDraggable : function(handler,dom){
handler.css("position","absolute");
dom.css("position","absolute");
var puranix=0;
var nayeex=0;
var puraniy=0;
var nayeey=0;
var offset="";
var zIndex=dom.css("z-index");
handler.mousedown(function(e){
puranix=e.clientX;
puraniy=e.clientY;
offset=dom.offset();
$rss(this).mousemove(function(e){
nayeex=e.clientX-puranix;
nayeex+=offset.left;
nayeey=e.clientY-puraniy;
nayeey+=offset.top;
dom.css({"left":nayeex+"px","top":nayeey+"px","z-index":"9999"});
})
}).mouseup(function(){
$rss(this).unbind("mousemove");
dom.css("z-index",zIndex);
})
},
//automatically scrolls to the bottom of the div
scrollToBottom : function(dom){
var domId = dom.attr("id");
// var domScrollHeight = document.getElementById(domId).scrollHeight;
var obj = document.getElementById(domId);
if((obj.scrollTop+100) >= (obj.scrollHeight - obj.offsetHeight))
dom.scrollTop(obj.scrollHeight);
},
/*ajax loading of images... needs following settings
dom:in which images ve to be loaded
url:the server url for making ajax calls
limit:how many images to load
divClass:the class of div surrounding each image
nameClass:class for span showing name
fn:function to be called in on the server
imageSrc:the image source of all the images.
bindTo:to bind images to a onclick function or else will be binded to normal a tag.
urlKey:to specify the key of the value.. if bindTo is used, this will be neglected..
returns json;
*/
loadImages : function(settings,callbackFn){
var dom = settings.dom;
var domid= dom.attr("id");
var temp_array=Array();
var starting = $rss("#"+domid+" img:last").attr("id");
if(typeof starting != 'undefined'){
starting = starting.substr(4,starting.length-1);
}else{starting = 0};
var temp_var="";
var json = "";
var dhtml="";
var extraparam="";
if(typeof settings.extraParam != "undefined"){
extraparam = settings.extraParam;
}
$rss.getJSON(settings.url,{fn:settings.fn,id:settings.whereId,limit:settings.limit,start:starting,extra:extraparam},function(images){
json = eval(images);
$rss.each(images,function(i,pic){
var temp_array=Array();
var a_var=Array();
var name_var="";
var title="";
$rss.each(pic,function(i,value){
temp_array.push(value);
})
if(temp_array.length>=4){
name_var="<span class='"+settings.nameClass+"'>"+temp_array[3]+"</span></div>"
}
if(temp_array[2]==null)
title = "";
else
title = temp_array[2];
if(typeof settings.bindTo!="undefined"){
a_var[1]="onclick='"+settings.bindTo+"("+temp_array[0]+");return false;'";
a_var[0]="";
}else{a_var[0]='?'+settings.urlKey+'='+temp_array[0];a_var[1]="";}
dhtml="<div class='"+settings.divClass+"' id='img_holder_"+temp_array[0]+"' ><a href='"+a_var[0]+"' "+a_var[1]+" title='"+title+"'><img id='pic_"+temp_array[0]+"' style='display:none' src='"+settings.imageSrc+temp_array[1]+"' /></a>"+name_var;
dom.delay(100).append(dhtml);
$rss("#pic_"+pic.id).delay(100).fadeIn(200);
})
if(typeof callbackFn=="function")
callbackFn.call(this,json);
})
},
//function to get url variables...
getUrlVars : function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++){
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
/*function to open a modalwindow on a page.. self reliant no images, no css needed.
settings
width:in percentage or pixcel
height:in percentage or pixcel
closeBtn:true or false
envClose:closing through background click, true or flase
loadDiv:load html from a div
loadPage:load a page
loadHtml: load html
*/
modalWindow : function(settings,callbackFn){
var envClose = settings.envClose;
var dhtml="";
if(typeof envClose == "undefined")
envClose = true;
var closeBtn = settings.closeBtn;
if(typeof closeBtn == "undefined")
closeBtn = true;
var rgmaskHeight = $rss(window).height();
var rgmaskWidth = $rss(window).width();
var tempheight = settings.height;
var tempwidth = settings.width;
if(typeof tempheight!="undefined"){
if(tempheight.charAt(tempheight.length-1)=='%')
tempheight=(rgmaskHeight*parseInt(tempheight.substr(0,tempheight.length)))/100;
}else{tempheight="auto";}
if(typeof tempwidth!="undefined"){
if(tempwidth.charAt(tempwidth.length-1)=='%')
tempwidth=(rgmaskWidth*parseInt(tempwidth.substr(0,tempwidth.length)))/100;
}else{tempwidth="auto";}
$rss("body").append('<div class="rgmask" id="rgsheath" style="height:'+rgmaskHeight+'px"></div>');
$rss("#rgsheath").css({background: "#000", width: "100%", position: "fixed", top: 0, left: 0,opacity:0.9,'z-index':199});
$rss("body").append('<div id="rgWindow"></div>');
$rss("#rgWindow").css({"position": "fixed", "z-index": "999", "background": "#fff", "border": "solid 3px #ccc", "padding": "20px", "overflow": "hidden", "border-radius": "12px", "-webkit-border-radius": "12px", "-moz-border-radius": "12px", "-ms-border-radius": "12px", "box-shadow": "0 0 20px rgba(0,0,0,0.9)","-webkit-box-shadow": "0 0 20px rgba(0,0,0,0.9)","-moz-box-shadow": "0 0 20px rgba(0,0,0,0.9)","-ms-box-shadow": "0 0 20px rgba(0,0,0,0.9)"});
var rgWTop = (rgmaskHeight-20)/2;
var rgWLeft = (rgmaskWidth-20)/2;
$rss("#rgWindow").css({top:rgWTop+"px", left:rgWLeft+"px"});
if(typeof settings.loadDiv!="undefined"){
dhtml = $rss("#"+settings.loadDiv).html();
$rss("#rgWindow").html(dhtml).hide();
prepareWindow();
}
if(typeof settings.loadHtml!="undefined"){
dhtml = settings.loadHtml;
$rss("#rgWindow").html(dhtml).hide();
prepareWindow();
}
if(typeof settings.loadPage!="undefined"){
$rss("#rgWindow").load(settings.loadPage,function(){$rss(this).hide();dhtml=$rss(this).html();prepareWindow();});
}
function prepareWindow(){
if(tempheight!="auto")
rgWTop = (rgmaskHeight-tempheight)/2;
else{
tempheight=$rss("#rgWindow").height();
rgWTop=(rgmaskHeight-tempheight)/2;
}
if(tempwidth!="auto")
rgWLeft = (rgmaskWidth-tempwidth)/2;
else{
tempwidth=$rss("#rgWindow").width();
rgWLeft=(rgmaskWidth-tempwidth)/2;
}
$rss("#rgWindow").empty().show();
var closebtn = "";
if(closeBtn)
closebtn='<a href="" style="display:block; width:28px; height:28px; line-height:28px; text-align:center; position:absolute; right:6px; top: 6px; font-family:Tahoma; font-weight:bold; border:solid 1px #ccc; border-radius: 15px;text-shadow:1px 1px 0 #fff; background:#f6f6f6; font-size:14px; text-decoration:none; color:#666" id="close_modal">X</a>';
$rss("#rgWindow").animate({"width":tempwidth+"px","height":tempheight+"px",top:rgWTop+"px", left:rgWLeft+"px"},500,function(){$rss("#rgWindow").html(closebtn+"<div id='rgContent' style='overflow:auto; overflow-x:none; height:"+tempheight+"px;'>"+dhtml+"</div>");
$rss("#close_modal").mouseover(function(){$rss(this).css("color","#999");}).mouseout(function(){$rss(this).css("color","#666");})
$rss("#close_modal").click(function(){
$rss("#rgWindow").empty();
var x = (rgmaskHeight-20)/2;
var y = (rgmaskWidth-20)/2;
$rss("#rgWindow").animate({top:x+"px", left:y+"px","width":"50px","height":"50px"},300,function(){$rss(this).fadeOut(100).remove();$rss("#rgsheath").fadeOut(500).remove();});
return false;
})
if(envClose)
$rss("#rgsheath").click(function(){
$rss("#rgWindow").empty();
var x = (rgmaskHeight-20)/2;
var y = (rgmaskWidth-20)/2;
$rss("#rgWindow").animate({top:x+"px", left:y+"px","width":"50px","height":"50px"},300,function(){$rss(this).fadeOut(100).remove();$rss("#rgsheath").fadeOut(500).remove();});})
if(typeof callbackFn=="function")
callbackFn.call(this,dhtml);
});
}
},
modalWindowClose : function(callbackFn){
if($rss("#rgWindow").length>0){
$rss("#rgWindow").empty();
var rgmaskHeight = $rss(window).height();
var rgmaskWidth = $rss(window).width();
var x = (rgmaskHeight-20)/2;
var y = (rgmaskWidth-20)/2
$rss("#rgWindow").animate({top:x+"px", left:y+"px","width":"50px","height":"50px"},300,function(){$rss(this).fadeOut(100).remove();$rss("#rgsheath").fadeOut(500).remove();})
}
if(typeof callbackFn=="function")
callbackFn.call(this,"harry");
},
bindDomToHead : function(dom){
var gc = dom.css("background");
var t = dom.offset();
var gw = dom.width();
$rss(window).scroll(function(){
var wt = $rss(window).scrollTop();
if ( wt > t.top ) {
var cssObj = {
'position':'fixed',
'top':0,
'width':gw,
'background':gc,
'box-shadow':'0 1px 0 rgba(0,0,0,0.2)',
'z-index':99
}
dom.css(cssObj);
} else {
dom.attr('style',"");
}
});
},
progressBar : function(dom,settings){
var domid = dom.prop("id");
if($rss("#rss_progressbar_div_"+domid).length==0){
if(typeof settings.top == "undefined")
settings.value = 1;
if(typeof settings.top == "undefined")
settings.top = (dom.height()-12)/2;
dom.append("<div id='rss_progressbar_div_"+domid+"' style='display:none;padding: 2px;background: #333;background: -webkit-linear-gradient(#111, #333);background: -moz-linear-gradient(#111, #333);background: -ms-linear-gradient(#111, #333);position: absolute;top: "+settings.top+"px;left: 50%;margin-left: -45%;width: 84%;box-shadow: inset 0 0 2px #000;border-radius: 4px;'><div id='rss_progressbar_"+domid+"' style='height: 8px; background: #36c;background: -webkit-linear-gradient(#7A98E7, #36c);background: -moz-linear-gradient(#7A98E7, #36c);background: -ms-linear-gradient(#7A98E7, #36c);border-radius: 2px; width: "+settings.value+"%;'></div></div>");
$rss("#rss_progressbar_div_"+domid).fadeIn(500);
}
},
progressBarValue : function(dom,value){
var domid = dom.prop("id");
if($rss("#rss_progressbar_div_"+domid).length==1){
$rss("#rss_progressbar_"+domid).animate({"width":value+"%"},100);
}
},
progressBarClose : function(dom){
var domid = dom.prop("id");
$rss("#rss_progressbar_div_"+domid).fadeOut(500,function(){$(this).remove();});
},
getInternetExplorerVersion: function(){
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
}
$ = jQuery.noConflict();

View File

@ -12,30 +12,49 @@ class Admin::AssetsController < ApplicationController
#TODO
end
def edit
@asset = Asset.find(params[:id])
end
def new
@asset = Asset.new
respond_to do |format|
format.html {}
format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/new'} }
end
end
def edit
@asset = Asset.find(params[:id])
respond_to do |format|
format.html {}
format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/edit'} }
end
end
def create
@asset = Asset.new(params[:asset])
if @asset.save
redirect_to admin_assets_url
respond_to do |format|
format.html { redirect_to admin_assets_url }
format.js { render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'append', :id => 'asset_tbody', :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil} }
end
else
render :action => :new
respond_to do |format|
format.html { render :action => :new }
format.js { render 'js/reload_content', :locals => {:function => 'html', :id => 'pop_up_content', :value => @asset, :values => nil, :partial => 'admin/assets/new', :locals => {:is_html => false}} }
end
end
end
def update
@asset = Asset.find(params[:id])
if @asset.update_attributes(params[:asset])
redirect_to admin_assets_url
respond_to do |format|
format.html { redirect_to admin_assets_url }
format.js { render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil} }
end
else
render :action => :edit
respond_to do |format|
format.html { render :action => :edit }
format.js { render 'js/reload_content', :locals => {:function => 'html', :id => 'pop_up_content', :value => @asset, :values => nil, :partial => 'admin/assets/edit', :locals => {:is_html => false}} }
end
end
end
@ -43,8 +62,9 @@ class Admin::AssetsController < ApplicationController
def destroy
@asset = Asset.find(params[:id])
@asset.destroy
redirect_to admin_assets_url
respond_to do |format|
format.js { render 'js/remove_element', :locals => {:id => "asset_#{@asset.id}"} }
end
end
end

View File

@ -0,0 +1,17 @@
<tr id="asset_<%= asset.id %>" class="have">
<td><%= asset.id %></td>
<td><div class="assets_pic"><%= image_tag(asset.data.url) %></div>
<%#= link_to asset.filename, asset.data.url, :target => '_blank' %>
</td>
<td><%= asset.description %></td>
<td><%= asset.data.file.content_type %></td>
<td><%= asset.data_filename %></td>
<td><%= number_to_human_size(asset.data.file.file_length) %></td>
<td class="action">
<%= link_to t(:edit), edit_admin_asset_path(asset), :remote => true, :class => 'edit' %>
<%= link_to t(:delete), admin_asset_path(asset), :confirm => t('sure?'), :method => :delete, :remote => true, :class => 'delete' %>
</td>
</tr>
<tr>
<td colspan="5"></td>
</tr>

View File

@ -0,0 +1,12 @@
<div id='pop_up_content' class="main2">
<h1><%= t('editing_asset') %></h1>
<%= form_for @asset, :url => admin_asset_path(@asset), :html => {:id => 'ajaxForm', :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<div class="button_bar">
<%= link_back if is_html %>
<a id='submit_button'><%= t(:update) %></a>
</div>
<% end %>
</div>

View File

@ -0,0 +1,14 @@
<div id='pop_up_content' class="main2">
<h1><%= t('admin.new_asset') %></h1>
<%= form_for :asset, :url => admin_assets_path, :html => {:id => 'ajaxForm', :multipart => true }, :remote => true do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<div class="button_bar">
<%= link_back if is_html %>
<a id='submit_button'><%= t(:create) %></a>
</div>
<% end %>
</div>

View File

@ -1,548 +0,0 @@
html, body{
height: 100%;
margin: 0;
padding: 0;
}
html{
background: url(<%= asset_path "body.jpg" %>) no-repeat fixed 0 0 transparent;
background-size: cover;
}
body{
color: #000000;
font-family: Helvetica, '微軟正黑體';
}
#panel_banner_link{
background: url(<%= asset_path "orbitbar1.png" %>) repeat-x scroll 0 0;
height: 50px;
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 5;
}
.hmenu{
height: 40px;
position: absolute;
right: 0;
top: 1px;
width: 250px;
}
#orbit{
background: url(<%= asset_path "bar_orbit.png" %>) no-repeat scroll 0 0 transparent;
cursor:pointer;
height: 43px;
left: 10px;
position: relative;
width: 41px;
}
#orbit:hover{
background-position:0 -43px;
box-shadow: 0 3px 3px #000000;
}
#orbit:hover #orblist{
display:block;
}
#orblist{
background: none repeat scroll 0 0 #FFFFFF;
border-radius: 0 3px 3px 3px;
box-shadow: 0 3px 3px #000000;
display: none;
margin: 0;
padding: 10px;
position: absolute;
top: 43px;
width: 130px;
}
#orblist li{
border-bottom:1px solid #aaa;
list-style:none;
}
.orblink{
color: #333333;
display: block;
font: 12px/100% arial,sans-serif;
padding: 5px;
text-decoration: none;
}
.orblink:hover{
background:#eee;
color:#333;
}
#log_out a{
background: url(<%= asset_path "service_btn.png" %>) no-repeat scroll right 0 transparent;
border: medium none !important;
display: block !important;
height: 40px !important;
line-height: normal !important;
padding: 0 !important;
position: absolute;
right: 0px;
text-indent: -10000px;
top: 0px;
width: 43px !important;
}
#log_out a:hover{
background: url(<%= asset_path "service_btn.png" %>) no-repeat scroll right bottom transparent !important;
}
.lang{
color: #FFFFFF;
font-size: 15px;
line-height: 40px;
position: absolute;
right: 55px;
top: 0;
}
.lang a{
color:#fff;
text-decoration:none;
}
.lang a:hover{
text-decoration:underline;
}
#content{
height: 100%;
}
#panel_footer{
background-color: #101010;
bottom: 0;
color: #FFFFFF;
font-size: 11px;
padding: 10px;
position: fixed;
width: 100%;
left: 0;
box-shadow: 0 -3px 4px #000;
}
#search {
background: url(<%= asset_path "search_block_bg.jpg" %>) repeat-x scroll left top transparent;
height: 20px;
margin-top: 43px;
padding: 15px 12px;
}
#search input {
background: url(<%= asset_path "search_bg.png" %>) no-repeat scroll left top transparent;
border: medium none;
font-family: Helvetica;
height: 20px;
padding: 0 20px;
width: 154px;
}
/*
#sidebar {
background: url(<%= asset_path "75.png" %>) repeat scroll left top transparent;
box-shadow: 3px 0 4px #472A12;
border-right: 1px solid #121212;
height: 100%;
left: 0;
position: fixed;
top: 0;
width: 220px;
}
#sidebar h1 {
background: url(<%= asset_path "h1_bg.png" %>) repeat-x scroll left top transparent;
border-bottom: 1px solid #1B1B1B;
border-top: 1px solid #424344;
color: #FFFFFF;
font-size: 12px;
font-weight: normal;
height: 21px;
line-height: 21px;
margin: 0;
padding-left: 10px;
text-shadow: 0 -1px 0 #000000;
}
#sidebar .list {
color:#fff;
font-size:12px;
background:url(<%= asset_path "line.png" %>) repeat-x left bottom;
}
#sidebar .list li {
background:url(<%= asset_path "sidebar_li.jpg" %>) repeat-x left top;
border-top:1px solid #424344;
border-bottom:1px solid #000000;
}
#sidebar .list li:hover {
background-position:left bottom;
border-top:1px solid #406cc3;
border-bottom:1px solid #242628;
}
#sidebar .list li a {
display: block;
padding: 7px 0 6px 12px;
color:#c4c4c4;
}
#sidebar .list li a span {
background:url(<%= asset_path "add_mamber.png" %>) left top no-repeat;
text-shadow: 0px 1px 0px #000;
line-height: 18px;
padding: 2px 0 1px 35px;
}
#sidebar .list li a:hover span {
background-position:left bottom;
color:#eeeeee;
}
#sidebar .users .list .set_1 {
background-position:left bottom;
border-top:1px solid #406cc3;
border-bottom:1px solid #242628;
}
#sidebar .users .list .set_1 a span {
background-position:left bottom;
color:#eeeeee;
}
#sidebar .roles .list .set_2 {
background-position:left bottom;
border-top:1px solid #406cc3;
border-bottom:1px solid #242628;
}
#sidebar .roles .list .set_2 a span {
background-position:left bottom;
color:#eeeeee;
}
#sidebar .infos .list .set_3 {
background-position:left bottom;
border-top:1px solid #406cc3;
border-bottom:1px solid #242628;
}
#sidebar .infos .list .set_3 a span {
background-position:left bottom;
color:#eeeeee;
}
*/
.main {
height: 100%;
margin-left: 260px;
padding-right: 40px;
position: relative;
}
.main_list {
padding-top: 70px;
}
.main_list ul {
clear:both;
}
#porfile {
padding-top: 100px;
}
/*add_buttom*/
.button_bar {
float: right;
-moz-box-shadow:inset 0px 1px 0px 0px #666, 0px 0px 3px black;
-webkit-box-shadow:inset 0px 1px 0px 0px #666, 0px 0px 3px black;
box-shadow:inset 0px 1px 0px 0px #666, 0px 0px 3px black;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #4f4f4f), color-stop(1, #000000) );
background:-moz-linear-gradient( center top, #4f4f4f 5%, #000000 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#4f4f4f', endColorstr='#000000');
background-color:#4f4f4f;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
display:inline-block;
padding:0;
margin:10px 0 60px;
}
.button_bar a {
text-decoration:none;
text-shadow:0px -1px 0px #000000;
font-size:12px;
color:#EDEDED;
border-right:1px solid #555;
-moz-box-shadow:1px 0px 0px black;
-webkit-box-shadow:1px 0px 0px black;
box-shadow:1px 0px 0px black;
padding: 6px 10px 4px;
display: inline-block;
float: left;
}
.button_bar a:active {
padding: 7px 10px 3px !important;
text-shadow:0px 1px 0px #000000;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #000000), color-stop(1, #4f4f4f) );
background:-moz-linear-gradient( center top, #000000 5%, #4f4f4f 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#4f4f4f');
}
.button_bar a:last-child, .button_bar input {
border-right:none;
-moz-box-shadow:none;
-webkit-box-shadow:none;
box-shadow:none;
-moz-border-radius:0px 5px 5px 0px;
-webkit-border-radius:0px 5px 5px 0px;
border-radius:0px 5px 5px 0px;
}
.button_bar a:first-child {
-moz-border-radius:5px 0px 0px 5px;
-webkit-border-radius:5px 0px 0px 5px;
border-radius:5px 0px 0px 5px;
}
.button_bar a.new {
padding: 5px 10px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.button_bar a:hover {
color:#FFFFFF;
}
.button_bar input {
background-color:transparent;
text-decoration:none;
text-shadow:0px -1px 0px #000000;
font-size:12px;
color:#EDEDED;
border-right:1px solid #555;
border-top:none;
border-left:none;
border-bottom:none;
-moz-box-shadow:1px 0px 0px black;
-webkit-box-shadow:1px 0px 0px black;
box-shadow:1px 0px 0px black;
padding: 3px 10px 1px;
display: inline-block;
float: left;
}
.up {
margin:10px 0;
}
#person {
left: 245px;
position: fixed;
text-align: center;
top: 75px;
width: 140px;
background-color:#FFF;
padding:15px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #180902; /* Firefox */
-webkit-box-shadow: 0px 0px 4px #180902;/* Safari 和 Chrome */
box-shadow: 0px 0px 4px #180902; /* Opera 10.5 + */
}
#file {
display:none;
}
#person img {
}
.user_mail {
border: medium none;
border:1px solid #DDDDDD;
color: #666666;
font-size: 12px;
width: 140px;
}
#person label {
display: block;
margin: 15px 0 0;
}
#person label input {
}
#person label #user_admin {
float:right;
margin: 0;
}
#person label span {
text-align:left;
font-size:11px;
color:#888;
display:block;
}
#person select {
border: 1px solid #DDDDDD;
padding: 0;
width: 140px;
}
#porfile .users{
margin-left: 180px;
}
.roles_block {
background: url(<%= asset_path "75.png" %>) repeat left top;
min-width:710px;
margin-bottom:50px;
position:relative;
padding-bottom: 20px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #180902; /* Firefox */
-webkit-box-shadow: 0px 0px 4px #180902;/* Safari 和 Chrome */
box-shadow: 0px 0px 4px #180902; /* Opera 10.5 + */
}
.roles_block h2 {
color: #FFFFFF;
font-weight: normal;
margin: 0;
padding: 0;
position: absolute;
text-shadow: 0 3px 2px #000000;
top: -30px;
}
.main hr {
height:8px;
border:none;
margin:0;
border-radius: 5px 5px 0px 0px;
-moz-border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
border-bottom:1px solid #000;
}
#basic_block hr {
background-color: #666666;
}
#teacher_block hr {
background-color: #0071A9;
}
#student_block hr {
background-color: #AF0045;
}
.info_input {
padding:10px 20px;
}
.info_input table {
color:#fff;
width:100%;
font-size:14px;
}
.info_input table td {
padding:5px 10px 5px 0;
width: 10%;
}
.info_input .list_head {
background:url(<%= asset_path "line.png" %>) left bottom repeat-x;
}
.info_input .list_head td {
}
.info_input .list_item {
color:#AEAEAE;
}
.info_input .add {
display:block;
padding-left:22px;
font-size:12px;
line-height:21px;
height:19px;
background:url(<%= asset_path "icon.png" %>) no-repeat -59px 0;
margin-top: 10px;
color: #DDDDDD;
}
.main table {
width:100%;
}
.main th {
color:#fff;
}
.main td {
padding-left:20px;
color:#fff;
font-size:14px;
line-height:20px;
}
.main tr.have td{
background: url(<%= asset_path "75.png" %>) repeat left top;
padding-bottom: 10px;
padding-top: 10px;
vertical-align: middle;
}
.main tr.have td:first-child{
border-radius: 5px 0 0 5px;
-moz-border-radius: 5px 0 0 5px;
-webkit-border-radius: 5px 0 0 5px;
}
.main tr.have td:last-child{
border-radius: 0 5px 5px 0;
-moz-border-radius: 0 5px 5px 0;
-webkit-border-radius: 0 5px 5px 0;
}
.main thead td {
line-height:40px;
font-size:16px;
text-shadow: 0px 1px 1px #3e2914;
}
.main thead th {
line-height:40px;
font-size:16px;
text-shadow: 0px 1px 1px #3e2914;
}
.main thead td.action {
width:140px;
}
.main tbody td.roles {
background-image: url(<%= asset_path "roles_type.jpg" %>);
background-repeat: repeat-x;
}
.main tbody td.teacher {
background-position: 0 -54px;
}
.main tbody td.student {
background-position: 0 -5px;
}
.main tbody td.action a {
background-image: url(<%= asset_path "icon.png" %>);
display: inline-block;
height: 19px;
margin-right: 10px;
outline:none;
text-indent: -9999px;
width: 19px;
position: relative;
}
.main tbody td.action a.show {
background-position: left top;
}
.main tbody td.action a.show:hover {
background-position: left -19px;
}
.main tbody td.action a.edit {
background-position: -19px top;
}
.main tbody td.action a.edit:hover {
background-position: -19px -19px;
}
.main tbody td.action a.delete {
background-position: -38px top;
}
.main tbody td.action a.delete:hover {
background-position: -38px -19px;
}
.main tbody td.action a.download {
background-position: -74px top;
}
.main tbody td.action a.download:hover {
background-position: -74px -19px;
}
.main tbody td.action a.switch {
background: url(<%= asset_path "switch.png" %>) no-repeat left 3px;
width: 40px;
}
.main tbody tr.disable td.action a.switch {
background-position:left bottom;
}
.main tbody td.action a.delete:hover {
background-position: -38px -19px;
}
.main tbody tr.have {
}
.main tbody tr.disable {
opacity: 0.7;
}
.main tbody tr {
background:none;
height:15px;
}
.main tbody tr.have .assets_pic {
height: 40px;
overflow: hidden;
width: 40px;
position: relative;
}
.main tbody tr.have .assets_pic img {
left: -15%;
position: absolute;
top: -15%;
width: 130%;
}

View File

@ -1,12 +1,9 @@
<div class="main2">
<h1><%= t('editing_asset') %></h1>
<% content_for :secondary do %>
<div class="assets_setup">
<ul class="list">
<li><%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :remote => true, :class => 'button positive' %></li>
</ul>
</div>
<% end -%>
<% form_for @asset, :url => admin_asset_path(@asset), :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>
</div>
<%= render :partial => 'edit', :locals => {:is_html => true} %>

View File

@ -1,7 +1,7 @@
<% content_for :secondary do %>
<div class="assets_setup">
<ul class="list">
<li><%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :class => 'button positive' %></li>
<li><%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :remote => true, :class => 'button positive' %></li>
</ul>
</div>
<% end -%>
@ -10,35 +10,19 @@
<h1><%= t('admin.list_assets') %></h1>
<table>
<thead>
<tr>
<td><%= t('admin.id') %></th>
<td><%= t('admin.file_name') %></th>
<td><%= t('admin.description') %></th>
<td><%= t('admin.format') %></th>
<td><%= t('admin.orig_upload_file') %></th>
<td><%= t('admin.file_size') %></th>
<td><%= t('admin.action') %></th>
</tr>
</thead>
<% @assets.each do |asset| %>
<tr class="have">
<td><%= asset.id %></td>
<td><div class="assets_pic"><%= image_tag(asset.data.url) %></div>
<%#= link_to asset.filename, asset.data.url, :target => '_blank' %>
</td>
<td><%= asset.description %></td>
<td><%= asset.data.file.content_type %></td>
<td><%= asset.data_filename %></td>
<td><%= number_to_human_size(asset.data.file.file_length) %></td>
<td class="action">
<%= link_to t(:edit), edit_admin_asset_path(asset), :class => 'edit' %>
<%= link_to t(:delete), admin_asset_path(asset), :confirm => t('sure?'), :method => :delete, :class => 'delete' %>
</td>
</tr>
<tr>
<td colspan="5"></td>
</tr>
<% end %>
<thead>
<tr>
<td><%= t('admin.id') %></th>
<td><%= t('admin.file_name') %></th>
<td><%= t('admin.description') %></th>
<td><%= t('admin.format') %></th>
<td><%= t('admin.orig_upload_file') %></th>
<td><%= t('admin.file_size') %></th>
<td><%= t('admin.action') %></th>
</tr>
</thead>
<tbody id='asset_tbody'>
<%= render :partial => 'asset', :collection => @assets %>
<tbody>
</table>
</div>

View File

@ -1,12 +1,9 @@
<div class="main2">
<h1><%= t('admin.new_asset') %></h1>
<% content_for :secondary do %>
<div class="assets_setup">
<ul class="list">
<li><%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :remote => true, :class => 'button positive' %></li>
</ul>
</div>
<% end -%>
<%= form_for :asset, :url => admin_assets_path, :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<div class="button_bar">
<%= link_back %>
<%= f.submit t('create') %>
</div>
<% end %>
</div>
<%= render :partial => 'new', :locals => {:is_html => true} %>

View File

@ -0,0 +1,8 @@
var to_render = '';
<% if value %>
to_render = "<%= escape_javascript(render(:partial => partial, :object => value, :locals => locals)) %>"
<% elsif values %>
to_render = "<%= escape_javascript(render(:partial => partial, :collection => values, :locals => locals)) %>"
<% end %>
$("#<%= id %>").<%= function %>(to_render);

View File

@ -0,0 +1 @@
$("#<%= id %>").remove()

View File

@ -0,0 +1,2 @@
rcom.modalWindowClose();
<%= render :template => 'js/reload_content', :locals => {:function => function, :id => id, :value => value, :values => values, :partial => partial, :locals => locals} %>

View File

@ -0,0 +1 @@
rcom.modalWindow({loadHtml:"<%= escape_javascript(render(:partial => partial, :locals => {:is_html => false})) %>"});

View File

@ -1,36 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%= @title || APP_CONFIG['orbit'] %></title>
<link rel="shortcut icon" href="/favicon.ico">
<%= stylesheet_link_tag "admin" %>
<%= javascript_include_tag "admin" %>
<%= yield :page_specific_css %>
<%= yield :page_specific_javascript %>
<%= csrf_meta_tag %>
</head>
<body>
<div id="panel_banner_link" >
<div id="orbit"><%= render 'layouts/drop_down_menu' %></div>
<div class="hmenu">
<div class="lang"><%= render 'layouts/lang_menu' %></div>
<%= render 'devise/menu/login_items' %>
</div>
</div>
<div id="panel_container">
<div id="panel_content">
<div class="secondary">
<div class="secondary2"><%= yield :secondary %></div>
</div>
<div class="main">
<div class="main2"><%= yield %></div>
</div>
<div class="tertiary"><%= yield :tertiary %></div>
</div>
<div id="panel_footer"><p><%= APP_CONFIG['ruling_digital'] %></p></div>
</div>
</body>
</html>