From 6211115b2200a9992f5cf8294da767737f1ac9ae Mon Sep 17 00:00:00 2001 From: Tyler Frankenstein Date: Wed, 4 Sep 2013 16:19:24 -0400 Subject: [PATCH] #160. Added the shell for drupalgap.services.taxonomy_vocabulary.index, added the drupalgap.taxonomy_vocabularies variable which will eventually hold the service index result, and brought in a copy of drupalgap_jqm_page_event_script_code() that hasn't been merged in yet from another branch. Started on theme_taxonomy_term_reference() and _theme_taxonomy_term_reference_load_items(). --- drupalgap.js | 20 ++++++++ modules/services/taxonomy_vocabulary.js | 24 +++++++++ modules/taxonomy/taxonomy.js | 66 +++++++++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/drupalgap.js b/drupalgap.js index ab86341b..d40afe20 100644 --- a/drupalgap.js +++ b/drupalgap.js @@ -85,6 +85,7 @@ var drupalgap = { 'router_path':'', /* The current menu router path. */ 'services':{}, 'sessid':null, + taxonomy_vocabularies:null, /* holds the services index of vocabularies */ 'theme_path':'', 'themes':[], 'theme_registry':{}, @@ -723,6 +724,25 @@ function drupalgap_jqm_page_events() { } } +/** + * Given a JSON object with a page id, a jQM page event name, a callback + * function to handle the jQM page event and any page arguments, this function + * will return the inline JS code needed to handle the event. + */ +function drupalgap_jqm_page_event_script_code(options) { + try { + var script_code = ''; + return script_code; + } + catch (error) { drupalgap_error(error); } +} + /** * Show the jQueryMobile loading message. */ diff --git a/modules/services/taxonomy_vocabulary.js b/modules/services/taxonomy_vocabulary.js index f21d66ab..a65de160 100644 --- a/modules/services/taxonomy_vocabulary.js +++ b/modules/services/taxonomy_vocabulary.js @@ -111,6 +111,30 @@ drupalgap.services.taxonomy_vocabulary = { } }, }, // + 'index':{ + 'options':{ + 'type':'get', + 'path':'taxonomy_vocabulary.json', + 'success':function(results){ + dpm(results); + alert('index success'); + }, + }, + 'call':function(options){ + try { + var api_options = drupalgap_chain_callbacks(drupalgap.services.taxonomy_vocabulary.index.options, options); + drupalgap.api.call(api_options); + } + catch (error) { + navigator.notification.alert( + error, + function(){}, + 'taxonomy_vocabulary Index Error', + 'OK' + ); + } + }, + }, // 'getTree':{ 'options':{ 'type':'post', diff --git a/modules/taxonomy/taxonomy.js b/modules/taxonomy/taxonomy.js index 0d5b6d59..de4937ae 100644 --- a/modules/taxonomy/taxonomy.js +++ b/modules/taxonomy/taxonomy.js @@ -404,3 +404,69 @@ function taxonomy_vocabulary_load(vid) { catch (error) { drupalgap_error(error); } } +/** + * + */ +function taxonomy_vocabulary_machine_name_load(name) { + try { + var options = null; + if (arguments[1]) { options = arguments[1]; } + + return entity_load('taxonomy_vocabulary', vid, options); + } + catch (error) { drupalgap_error(error); } +} + +/** + * + */ +function theme_taxonomy_term_reference(variables) { + try { + dpm(variables); + var html = ''; + + // Make this a hidden field since the widget will just populate a value. + variables.attributes.type = 'hidden'; + html += ''; + + // What vocabulary are we using? + var vocabulary = variables.field_info_field.settings.allowed_values[0].vocabulary; + + // Prepare the variables for the widget and render it based on its type. + var widget_type = variables.field_info_instance.widget.type; + if (widget_type == 'options_select') { widget_type = 'select'; } + var widget_function = 'theme_' + widget_type; + var id = variables.attributes.id + '-' + widget_type; + if (drupalgap_function_exists(widget_function)) { + var fn = window[widget_function]; + html += fn.call(null, {'id':id}); + // Attach a pageshow handler to the current page (if it hasn't been + // already) that will load the terms into the widget. + //drupalgap.menu_links[drupalgap_router_path_get()] + var options = { + 'page_id':drupalgap_get_page_id(drupalgap_path_get()), + 'jqm_page_event':'pageshow', + 'jqm_page_event_callback':'_theme_taxonomy_term_reference_load_items', + 'jqm_page_event_args':null + }; + html += drupalgap_jqm_page_event_script_code(options); + } + else { + console.log('WARNING: theme_taxonomy_term_reference() - unsupported widget type! (' + widget_type + ')'); + } + + console.log(html); + return html; + } + catch (error) { drupalgap_error(error); } +} + +/** + * + */ +function _theme_taxonomy_term_reference_load_items() { + try { + alert('_theme_taxonomy_term_reference_load_items'); + } + catch (error) { drupalgap_error(error); } +}