Skip to content

Instantly share code, notes, and snippets.

@samwilson
Last active August 29, 2015 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwilson/078ed434250f49819fdd to your computer and use it in GitHub Desktop.
Save samwilson/078ed434250f49819fdd to your computer and use it in GitHub Desktop.
"No site_path" module for DrupalGap. Now located at https://github.com/samwilson/nositepath
nositepath_temp_path = 'http://example.org';
if (!Drupal.settings.site_path || Drupal.settings.site_path == '') {
Drupal.settings.site_path = variable_get('nositepath_site_path', nositepath_temp_path);
}
/**
* Implements hook_deviceready().
*/
function nositepath_deviceready() {
// Add menu item.
drupalgap.settings.menus['main_menu'].links.push(
{
title: 'Config',
path: 'nositepath',
options: {
attributes: { 'data-icon': 'gear' }
},
}
);
// Redirect to nositepath form if no site_path has been set yet.
if (Drupal.settings.site_path == nositepath_temp_path) {
//drupalgap_goto("nositepath");
var site_path = window.prompt('Drupal URL:', nositepath_temp_path);
nositepath_reconnect(site_path);
}
// Prevent system_connect() by returning false.
return false;
}
/**
* Implements hook_menu().
*/
function nositepath_menu() {
var items = {};
items['nositepath'] = {
title: 'Connect to Drupal',
page_callback: 'drupalgap_get_form',
page_arguments: ['nositepath_form'],
};
return items;
}
function nositepath_form(form, form_state) {
try {
form.prefix = '<h2>Connect to Drupal</h2>';
form.elements['site_path'] = {
type: 'textfield',
title: 'Address of a Drupal site:',
default_value: Drupal.settings.site_path,
required: true,
};
form.elements['submit'] = {
type: 'submit',
value: 'Connect',
};
return form;
} catch (error) {
console.log('nositepath_offline_form - ' + error);
}
}
function nositepath_form_submit(form, form_state) {
try {
nositepath_reconnect(form_state.values['site_path']);
} catch (error) {
console.log('nositepath_offline_form_submit - ' + error);
}
}
function nositepath_reconnect(site_path) {
try {
// Set the site_path variables, and save the persistent one.
Drupal.settings.site_path = site_path;
drupalgap.settings.site_path = site_path;
variable_set('nositepath_site_path', site_path);
// Try to connect, and then bootstrap.
system_connect({
success: function () {
alert('Connection successful!');
// Re-bootstrap. Does this work?
drupalgap_bootstrap();
drupalgap_goto('');
}
});
} catch (error) {
console.log('nositepath_reconnect - ' + error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment