Skip to content

Commit

Permalink
major cleanup and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylukasavage committed Sep 13, 2011
1 parent ca77a1c commit 5bb1c63
Show file tree
Hide file tree
Showing 10 changed files with 1,679 additions and 1,743 deletions.
332 changes: 139 additions & 193 deletions Resources/drupal/db.insert.js

Large diffs are not rendered by default.

322 changes: 151 additions & 171 deletions Resources/drupal/drupal.js
Expand Up @@ -14,49 +14,48 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with CODESTRONG Mobile. If not, see <http://www.gnu.org/licenses/>. * along with CODESTRONG Mobile. If not, see <http://www.gnu.org/licenses/>.
*/ */

/** /**
* Main Drupal factory. * Main Drupal factory.
* *
* This object serves as a central router for Drupal integration. * This object serves as a central router for Drupal integration.
*/ */
var Drupal = { var Drupal = {


/** /**
* Sets default values for an object. * Sets default values for an object.
* *
* This is similar to jQuery.extend() or PHP's += for arrays, and can be * This is similar to jQuery.extend() or PHP's += for arrays, and can be
* used for much the same purpose. * used for much the same purpose.
* *
* @param settings * @param settings
* The object on which to set default values. Note that this object will * The object on which to set default values. Note that this object will
* be modified directly. * be modified directly.
* @param defaults * @param defaults
* The default values to use for each key if the settings object does not * The default values to use for each key if the settings object does not
* yet have a value for that key. * yet have a value for that key.
* @returns * @returns
* The settings object. * The settings object.
*/ */
setDefaults: function(settings, defaults) { setDefaults: function (settings, defaults) {
if (!settings) { if (!settings) {
settings = {}; settings = {};
} }
for (var key in defaults) { for (var key in defaults) {
if (defaults.hasOwnProperty(key) && settings[key] === undefined) { if (defaults.hasOwnProperty(key) && settings[key] === undefined) {
settings[key] = defaults[key]; settings[key] = defaults[key];
} }
}
return settings;
} }
return settings;
}
}; };


/** /**
* For fancy-schmancy inheritance building. * For fancy-schmancy inheritance building.
*/ */
Drupal.constructPrototype = function(o) { Drupal.constructPrototype = function (o) {
var f = function() {}; var f = function () {};
f.prototype = o.prototype; f.prototype = o.prototype;
return new f(); return new f();
}; };


/** /**
Expand All @@ -74,128 +73,114 @@ Drupal.constructPrototype = function(o) {
* @return {string} * @return {string}
* The ISO formatted version of the date object. * The ISO formatted version of the date object.
*/ */
Drupal.getISODate = function(date, utc) { Drupal.getISODate = function (date, utc) {

function pad(n) {return n < 10 ? '0' + n : n;}

if (utc) {
return date.getUTCFullYear() + '-'
+ pad(date.getUTCMonth() + 1) + '-'
+ pad(date.getUTCDate()) + 'T'
+ pad(date.getUTCHours()) + ':'
+ pad(date.getUTCMinutes()) + ':'
+ pad(date.getUTCSeconds());
}
else {
return date.getFullYear() + '-'
+ pad(date.getMonth() + 1) + '-'
+ pad(date.getDate()) + 'T'
+ pad(date.getHours()) + ':'
+ pad(date.getMinutes()) + ':'
+ pad(date.getSeconds());
}
};



Drupal.getObjectProperties = function(o) {
var properties = [];
var values = [];
var prop;


// Apparently hasOwnProperty() is sometimes missing from objects in Titanium. function pad(n) {
// My best guess is that it's on objects deserialized from JSON, but I'm not return n < 10 ? '0' + n : n;
// really sure. At this point I no longer care.
if(o.hasOwnProperty) {
for (prop in o) {
if (o.hasOwnProperty(prop)) {
properties.push(prop);
values.push(o[prop]);
}
} }
}
else { if (utc) {
for (prop in o) { return date.getUTCFullYear() + '-' + pad(date.getUTCMonth() + 1) + '-' + pad(date.getUTCDate()) + 'T' + pad(date.getUTCHours()) + ':' + pad(date.getUTCMinutes()) + ':' + pad(date.getUTCSeconds());
properties.push(prop); } else {
values.push(o[prop]); return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + 'T' + pad(date.getHours()) + ':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds());
} }
}
return properties;
}; };


(function() {

Drupal.createNoticeDialog = function(message) {
return new Drupal.NoticeDialog(message);
};

Drupal.NoticeDialog = function(message) {

var messageWin = Titanium.UI.createWindow({
height:30,
width:250,
bottom:70,
borderRadius:10,
border: 1,
touchEnabled:false,
orientationModes : [
Titanium.UI.PORTRAIT,
Titanium.UI.UPSIDE_PORTRAIT,
Titanium.UI.LANDSCAPE_LEFT,
Titanium.UI.LANDSCAPE_RIGHT
],
debugText: message
});
var messageView = Titanium.UI.createView({
id:'messageview',
height:30,
width:250,
borderRadius:10,
backgroundColor:'#000',
opacity:0.7,
touchEnabled:false
});

var messageLabel = Titanium.UI.createLabel({
id:'messagelabel',
text:'',
color:'#fff',
width:250,
height:'auto',
font:{
fontFamily:'Helvetica Neue',
fontSize:13
},
textAlign:'center'
});

messageLabel.text = message;

messageWin.add(messageView);
messageWin.add(messageLabel);

this.messageWindow = messageWin;

};

var openNoticeWindow;

Drupal.NoticeDialog.prototype.show = function(time) {
// Close any open notice windows first.
if (openNoticeWindow) {
openNoticeWindow.close();
}


this.messageWindow.open();


openNoticeWindow = this.messageWindow; Drupal.getObjectProperties = function (o) {
var properties = [];
var values = [];
var prop;

if (o.hasOwnProperty) {
for (prop in o) {
if (o.hasOwnProperty(prop)) {
properties.push(prop);
values.push(o[prop]);
}
}
} else {
for (prop in o) {
properties.push(prop);
values.push(o[prop]);
}
}
return properties;
};


// Needed to avoid 'this' confusion in the callback. Blech. (function () {
var win = this.messageWindow;
setTimeout(function() { Drupal.createNoticeDialog = function (message) {
win.close({opacity:0,duration:2000}); return new Drupal.NoticeDialog(message);
}, time); };
};
Drupal.NoticeDialog = function (message) {

var messageWin = Titanium.UI.createWindow({
height: 30,
width: 250,
bottom: 70,
borderRadius: 10,
border: 1,
touchEnabled: false,
orientationModes: [
Titanium.UI.PORTRAIT, Titanium.UI.UPSIDE_PORTRAIT, Titanium.UI.LANDSCAPE_LEFT, Titanium.UI.LANDSCAPE_RIGHT],
debugText: message
});
var messageView = Titanium.UI.createView({
id: 'messageview',
height: 30,
width: 250,
borderRadius: 10,
backgroundColor: '#000',
opacity: 0.7,
touchEnabled: false
});

var messageLabel = Titanium.UI.createLabel({
id: 'messagelabel',
text: '',
color: '#fff',
width: 250,
height: 'auto',
font: {
fontFamily: 'Helvetica Neue',
fontSize: 13
},
textAlign: 'center'
});

messageLabel.text = message;

messageWin.add(messageView);
messageWin.add(messageLabel);

this.messageWindow = messageWin;

};

var openNoticeWindow;

Drupal.NoticeDialog.prototype.show = function (time) {
// Close any open notice windows first.
if (openNoticeWindow) {
openNoticeWindow.close();
}

this.messageWindow.open();

openNoticeWindow = this.messageWindow;

// Needed to avoid 'this' confusion in the callback. Blech.
var win = this.messageWindow;
setTimeout(function () {
win.close({
opacity: 0,
duration: 2000
});
}, time);
};


})(); })();


Expand All @@ -218,36 +203,31 @@ Drupal.getObjectProperties = function(o) {
* including seconds. * including seconds.
* @return {Date} * @return {Date}
*/ */

function parseISO8601(str) { function parseISO8601(str) {
// Parses "as is" without attempting timezone conversion // Parses "as is" without attempting timezone conversion

var parts = str.split('T');
var parts = str.split('T'); var dateParts = parts[0].split('-');
var dateParts = parts[0].split('-'); var timeParts = parts[1].split('Z');
var timeParts = parts[1].split('Z'); var timeSubParts = timeParts[0].split(':');
var timeSubParts = timeParts[0].split(':'); var timeSecParts = timeSubParts[2].split('.');
var timeSecParts = timeSubParts[2].split('.'); var timeHours = Number(timeSubParts[0]);
var timeHours = Number(timeSubParts[0]); var _date = new Date();
var _date = new Date();

_date.setFullYear(Number(dateParts[0]));
_date.setFullYear(Number(dateParts[0])); _date.setMonth(Number(dateParts[1]) - 1);
_date.setMonth(Number(dateParts[1])-1); _date.setDate(Number(dateParts[2]));
_date.setDate(Number(dateParts[2])); _date.setHours(Number(timeHours));
_date.setHours(Number(timeHours)); _date.setMinutes(Number(timeSubParts[1]));
_date.setMinutes(Number(timeSubParts[1])); _date.setSeconds(Number(timeSecParts[0]));
_date.setSeconds(Number(timeSecParts[0])); if (timeSecParts[1]) {
if (timeSecParts[1]) { _date.setMilliseconds(Number(timeSecParts[1])); }; _date.setMilliseconds(Number(timeSecParts[1]));

};
return _date;
return _date;
}; };


function strpos (haystack, needle, offset) { function strpos(haystack, needle, offset) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Onno Marsman
// + bugfixed by: Daniel Esteban
// + improved by: Brett Zamir (http://brett-zamir.me)
// * example 1: strpos('Kevin van Zonneveld', 'e', 5);
// * returns 1: 14
var i = (haystack + '').indexOf(needle, (offset || 0)); var i = (haystack + '').indexOf(needle, (offset || 0));
return i === -1 ? false : i; return i === -1 ? false : i;
} }

0 comments on commit 5bb1c63

Please sign in to comment.