Bootstrap Modals with Angular

The not-so-simple approach — embedding a template into the html itself. This is probably not a recommended solution, but I was pressed for time. Anyway, the docs say you need: 1) a template and 2) a controller.  

Then…you need to listen to the controller

Then…you need to do something about the response

Ok, it’s not that easy, but I’m catching on!!


*** STEP 1 ***

For the HTML side of things (should be it’s own file):


<script type="text/ng-template" id="myModalContent.html">
 <div class="modal-header">
   <h3 class="modal-title" id="modal-title">Send this goal</h3>
 </div>
 <div class="modal-body" id="modal-body">
   <p>Email (s): <input class="form-control" type="text" ng-model="$ctrl.details.emailto" placeholder="Enter email(s) here" /></p>
   <p>Add comments for the beginning of your email here:</p>
   <textarea ng-model="$ctrl.details.emailnotes" class="form-control"></textarea>
 </div>

 <div class="modal-footer">
   <button class="btn btn-primary" type="button" ng-click="$ctrl.ok()">Send</button>
   <button class="btn btn-warning" type="button" ng-click="$ctrl.cancel()">Cancel</button>
 </div>
</script>

*** STEP 2 ***

Somewhere on the html document, call the method that fires up the modal:


<button class="btn btn-warning" title="Email Goal" ng-click="emailGoal(goal)"><i class="glyphicon glyphicon-envelope"></i> Email</button>

*** STEP 3 ***

In the controller for the page, respond to the click event:


$scope.emailGoal = function (goal) {
  $ctrl.details.goal = goal;
  var modalInstance = $uibModal.open({
    animation: true,
    component: 'modalComponent',
    resolve: {
       details: function () {
          return $ctrl.details;
       }
    }
  });
  modalInstance.result.then(function (details) {
    $ctrl.details = details;
    // process the request to send email
    $scope.shareGoal( details );
  }, function () {
    // unless it gets dismissed, then do nothing!
    console.info('modal-component dismissed at: ' + new Date());
  });
};

*** STEP 4 ***

Of course, you have to have a modalComponent built in order for this to work. In my case, I have a separate file (cc-modals.js) for this purpose. Basically, it handles the bindings and passes the data back to the resolve “promise” above.


angular.module('ccModals').component('modalComponent', {
  templateUrl: 'myModalContent.html',
  bindings: {
    resolve: '<',
    close: '&',
    dismiss: '&'
  },
  controller: function () {
    'use strict';
    var $ctrl = this;
    $ctrl.$onInit = function() {
      $ctrl.details = $ctrl.resolve.details;
    };
    $ctrl.ok = function () {
      // console.log('send details: ' + JSON.stringify($ctrl.details));
      $ctrl.close({$value: $ctrl.details});
    };
    $ctrl.cancel = function () {
      $ctrl.details.emailto='';
      $ctrl.details.emailnotes='';
      $ctrl.dismiss({$value: 'cancel'});
    };
  }
});

*** STEP 5 ***

This is called in STEP 3 modalInstance.result.then

with the details. Basically, we just process the request now that the modal is closed


$scope.shareGoal = function( details ){
  console.log('shareGoal called '); // + JSON.stringify( details ) );
  GoalsService.SendGoal( details, function(results){
    if ( results.success ) {
      console.log('dashboard controller: Successfully sent email');
      $scope.buttonMessage = '<span class="alert alert-success">Successfully emailed this goal.</span>';
    } else {
      console.error('dashboard controller: unable to send email');
      $scope.buttonMessage = '<span class="alert alert-warning">Unable to send this goal. Please check your email and try again.</span>';
    }
  });
  $timeout(function () { $scope.buttonMessage = ''; }, 3000);
};

Simple, right?

WordPress Child Themes

Child Themes are still the best way to customize WordPress based on an excellent theme like http://vpthemes.com/portfolio/terrifico/. By using a child theme, you can personalize your theme without affecting the parent theme and, most importantly, when the parent theme is updated, you don’t have to worry about losing your custom code. Of course you’ll need to make sure to check the Changelog to ensure nothing drastic has been modified.

Here’s the process of incorporating a child theme:

1. Create a unique folder in your wp-content/themes folder. For example, I created a folder named hgctools_terrifico

2. Create a style.css file in that folder with the template below, using your details of course:

/* 
 Theme Name: HGCTools as Child Theme of Terrifico
 Theme URI: http://HGCTools.com
 Description: Healthy Growing Churches -- Tools -- WordPress Theme based on http://vpthemes.com/portfolio/terrifico/
 Author: Dave Phillips
 Author URI: http://teracomp.net
 Template: terrificopro
 Version: 1.0
 */

NOTE: the Template I’m using is the “pro” version; Template: terrificopro. If you’re using the free version, make this line Template: terrifico

3. Create a functions.php file and include this code at the very beginning:

<?php
function terrificopro_child_enqueue_styles() {
    // This is 'terrificopro-style' for the terrifico Pro theme. 
    $parent_style = 'parent-style';

    wp_enqueue_style( $parent_style, 
        get_template_directory_uri() . '/style.css' );
   
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'terrificopro_child_enqueue_styles' );
?>

4. Activate your new theme in your WordPress admin panel.

Now you can safely update your style.css and functions.php files to make your site your own.

Multidimensional Associative Array Sorting in PHP

I needed to sort a deep multidimensional associative array for PlanterApp, so I looked around for some solutions. The one I found was close enough to the right answer that I was able to make it work by defining a function, then referring to that function as follows:

function sortMyTools( $i, $j ) { // function sort the Tools array by [Tool][name]
    $a = $i['Tool']['name'];
    $b = $j['Tool']['name'];
    if ($a == $b) return 0;
        elseif ($a > $b) return 1;
        else return -1;
    }
    uasort($tools, sortMyTools ); // uasort() using the function

Since the enormous $tools array has many levels, this cool code provides a great answer to sorting on the tool name element quite nicely.
Credits to:
http://stackoverflow.com/users/468793/kapa
re: http://stackoverflow.com/questions/7983822/sort-a-multi-dimensional-associative-array

Note: uasort — Sort an array with a user-defined comparison function and maintain index association

Simone

Created this theme from Morten Rand-Hendrickson’s Lynda.com course on creating custom themes using Underscore as a starting point.

Bible Gateway Shortcode

This is a great tool for your WordPress site if you like to use BibleGateway.com to show scripture references. This plugin was developed at Shoreline  Community Church in Monterey, CA. We’d love to know how it works for you.

=== Convert to Bible Gateway Link ===
Contributors: jperl, teracomp
Donate link: http://teracomp.net/donate/
Tags: shortcode, bible gateway, scripture, post, page, admin, settings
Requires at least: 3.0.1
Tested up to: 4.1
Stable tag: 1.0
License: GPLv2 or later
License URI: http://teracomp.net/bible-gateway-shortcode

Latest version is here: v1, Bible Gateway Shortcode

This plugin sets a shortcode to automatically convert scripture references to Bible Gateway links.

== Description ==

This plugin provides a convenient tool for linking scripture references to BibleGateway.com.
Administrators establish a default translation in the Settings panel, but authors may override
the default setting simply by adding a [version] parameter in their post or page.

Here are a few examples:

  • Default translation applied: Hebrews 10:19-25.
  • Override the default by adding the parameter “version” to specify which translation:
    Hebrews 10:19-25 for the King James Version.

== Installation ==

  1. Download the plugin and unzip it.
  2. Upload the folder bible-gateway-shortcode/ to your /wp-content/plugins/ folder.
  3. Activate the plugin from your WordPress admin panel.
  4. Installation finished.

== Frequently Asked Questions ==

= What is the default translation after installation? =

Our default translation is NIV.

= Where do I change the default translation? =

Use the Settings Panel, Bible Gateway Shortcode Settings option to select the your default translation

== Screenshots ==

  1. This screenshot shows how the plugin will show up in your Settings menu.
  2. This screenshot shows where you set your default version.
  3. Here’s what your post will look like from the user’s perspective.
  4. Here’s how you use the shortcode with both the default version
    as well as an example of overriding the default version by adding the attribute version=”NLT”

== Changelog ==
= 1.0 =
* Added shortcode support for comments and excerpts (originally targeted only post content).

= 0.9.3 =
* Added bgcsc_style.css for the admin options page and code to enqueue this stylesheet
* Added uninstall.php to remove the three default options
* Added bgcsc_helper.php as a separate file to contain the code that generates select dropdowns
= 0.91 =
* Administrative cleanup, getting ready to move to version 1.0.
* Just need to add an uninstall.php file and a function to handle removing the option on deactivation

== Upgrade Notice ==

= 1.0 =
This initial version incorporates all of the basic required functionality for a WordPress plugin.

Settings Menu Item
Settings Menu Item
Settings Panel Options
Settings Panel Options

 

Example 1
Example 1

 

Example 2
Example 2

Latest version is here: v1, Bible Gateway Shortcode