{"action":"created","comment":{"url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments/44954466","id":44954466,"diff_hunk":"@@ -1,16 +1,108 @@\n \n-// subscribe to the OnChange event for the model_name listbox\n-var model_list = document.getElementById('id_model_name');\n-if(model_list){\n-    model_list.addEventListener('change', show_model_details);\n+// variable to store the last submitted model program id\n+var mp_old_id = '';\n \n-    // fire the change event to force the html to update the model details table\n-    show_model_details(null);\n+/*\n+  Initialize the view on document ready\n+ */\n+$(document).ready(function(){\n+\n+    // proceed only if selectbox_ exists (i.e. edit page)\n+    if($('[id^=selectbox_]').length > 0) {\n+\n+        // set the initial value of the mp_old_id\n+        mp_old_id = $('[id^=selectbox_]').attr('id').split('_').pop();\n+\n+        // initialize the model program listbox\n+        build_selectbox();\n+\n+        // set the initial selection\n+        set_model_program_selection();\n+\n+        // build metadata table (ajax query)\n+        show_model_details();\n+\n+\n+    }\n+\n+});\n+\n+/*\n+  Sets the selected item in the selectbox if a ModelProgram foreign key relationship has previously been set in the\n+  database.\n+ */\n+function set_model_program_selection(){\n+\n+        // get the value stored in the model_name hidden field\n+        var mp_id = $('[id^=selectbox_]').attr('id').split('_').pop();\n+\n+        // set the initial selection\n+        var model_name = document.getElementById('id_model_name');\n+        model_name.value = mp_id;\n+\n+        // get the selectbox\n+        var options = $('[id^=selectbox_]').find('option');\n+\n+        if (mp_id != \"\")\n+        {\n+            for (var i = 0; i< options.length; i++){\n+                var o = options[i];\n+                if (o.value == mp_id) {\n+                    $(o).attr(\"selected\", 1);\n+                    break;\n+                }\n+            }\n+        }\n+        else {\n+            // set selected to 'Not Specified' if mp_id is empty\n+            $(options[0]).attr(\"selected\", 1);\n+        }\n }\n-function show_model_details(e) {\n \n-    // get the id of the current model program name\n-    var shortid = model_list.item(model_list.selectedIndex).value;\n+\n+/*\n+ Constructs a select box for the ModelProgram elements using JQuery.  This selectbox is used to define the\n+ ModelProgram foreign key relationship.\n+ */\n+function build_selectbox(){\n+\n+    // destroy any existing multiselect widgets\n+    $('.selectbox').multiselect('destroy');","path":"hs_modelinstance/static/js/model_instance.js","position":null,"original_position":79,"commit_id":"0ef5757d454f258246ff0d53e5b5f1252f76b760","original_commit_id":"2ebff599948922485df4a059d86507ace0fa28cc","user":{"login":"Castronova","id":4822372,"avatar_url":"https://avatars.githubusercontent.com/u/4822372?v=3","gravatar_id":"","url":"https://api.github.com/users/Castronova","html_url":"https://github.com/Castronova","followers_url":"https://api.github.com/users/Castronova/followers","following_url":"https://api.github.com/users/Castronova/following{/other_user}","gists_url":"https://api.github.com/users/Castronova/gists{/gist_id}","starred_url":"https://api.github.com/users/Castronova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Castronova/subscriptions","organizations_url":"https://api.github.com/users/Castronova/orgs","repos_url":"https://api.github.com/users/Castronova/repos","events_url":"https://api.github.com/users/Castronova/events{/privacy}","received_events_url":"https://api.github.com/users/Castronova/received_events","type":"User","site_admin":false},"body":"@mauriel133  addressed in 0ef5757d454f258246ff0d53e5b5f1252f76b760","created_at":"2015-11-16T17:33:24Z","updated_at":"2015-11-16T17:33:24Z","html_url":"https://github.com/hydroshare/hydroshare/pull/607#discussion_r44954466","pull_request_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/607","_links":{"self":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments/44954466"},"html":{"href":"https://github.com/hydroshare/hydroshare/pull/607#discussion_r44954466"},"pull_request":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/607"}}},"pull_request":{"url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/607","id":44969712,"html_url":"https://github.com/hydroshare/hydroshare/pull/607","diff_url":"https://github.com/hydroshare/hydroshare/pull/607.diff","patch_url":"https://github.com/hydroshare/hydroshare/pull/607.patch","issue_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/607","number":607,"state":"open","locked":false,"title":"[WIP] 548 link swmi with mp","user":{"login":"Castronova","id":4822372,"avatar_url":"https://avatars.githubusercontent.com/u/4822372?v=3","gravatar_id":"","url":"https://api.github.com/users/Castronova","html_url":"https://github.com/Castronova","followers_url":"https://api.github.com/users/Castronova/followers","following_url":"https://api.github.com/users/Castronova/following{/other_user}","gists_url":"https://api.github.com/users/Castronova/gists{/gist_id}","starred_url":"https://api.github.com/users/Castronova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Castronova/subscriptions","organizations_url":"https://api.github.com/users/Castronova/orgs","repos_url":"https://api.github.com/users/Castronova/repos","events_url":"https://api.github.com/users/Castronova/events{/privacy}","received_events_url":"https://api.github.com/users/Castronova/received_events","type":"User","site_admin":false},"body":"This pull request adds the Model Program foreign key relationship to the SwatModelInstance resource.  The following modifications were necessary to accomplish this:\r\n\r\n* Default values were given to **model_name** and **model_program_fk** fields.\r\n* A *related_name* was given the the **model_program_fk** so that multiple resource can share the same foreign key relationship (i.e. model instance and swat model instance)\r\n* Extended the swat model instance *executebyformhelper* function to display model program info on the edit page.  This is necessary to provide users with model program metadata when they are establishing the *executedby* relationship.\r\n* Added a dropdown list to the swat model instance edit page to display available model programs.\r\n* Fixed a bug in the swat model instance `get_xml()` function that was causing bagit creation and resource saving to fail.\r\n* Updated the swat model instance landing page to display model program metadata if the *executedby* relationship has been established.\r\n* Added a reference to `model_instance.js` in the swat model instance html file to enable interactive model program selection.\r\n* Added migrations for the model instance and swat model instance resources.","created_at":"2015-09-14T19:23:27Z","updated_at":"2015-11-16T17:33:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82525dc1f8ab921d3b17d86794d1d882299788ca","assignee":{"login":"mohamedmorsy","id":5543781,"avatar_url":"https://avatars.githubusercontent.com/u/5543781?v=3","gravatar_id":"","url":"https://api.github.com/users/mohamedmorsy","html_url":"https://github.com/mohamedmorsy","followers_url":"https://api.github.com/users/mohamedmorsy/followers","following_url":"https://api.github.com/users/mohamedmorsy/following{/other_user}","gists_url":"https://api.github.com/users/mohamedmorsy/gists{/gist_id}","starred_url":"https://api.github.com/users/mohamedmorsy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohamedmorsy/subscriptions","organizations_url":"https://api.github.com/users/mohamedmorsy/orgs","repos_url":"https://api.github.com/users/mohamedmorsy/repos","events_url":"https://api.github.com/users/mohamedmorsy/events{/privacy}","received_events_url":"https://api.github.com/users/mohamedmorsy/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/hydroshare/hydroshare/milestones/18","html_url":"https://github.com/hydroshare/hydroshare/milestones/Release%201.6.3%20-%20Further%20Improvements","labels_url":"https://api.github.com/repos/hydroshare/hydroshare/milestones/18/labels","id":1391822,"number":18,"title":"Release 1.6.3 - Further Improvements","description":"Improvements not included in 1.6.2","creator":{"login":"mjstealey","id":5332509,"avatar_url":"https://avatars.githubusercontent.com/u/5332509?v=3","gravatar_id":"","url":"https://api.github.com/users/mjstealey","html_url":"https://github.com/mjstealey","followers_url":"https://api.github.com/users/mjstealey/followers","following_url":"https://api.github.com/users/mjstealey/following{/other_user}","gists_url":"https://api.github.com/users/mjstealey/gists{/gist_id}","starred_url":"https://api.github.com/users/mjstealey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjstealey/subscriptions","organizations_url":"https://api.github.com/users/mjstealey/orgs","repos_url":"https://api.github.com/users/mjstealey/repos","events_url":"https://api.github.com/users/mjstealey/events{/privacy}","received_events_url":"https://api.github.com/users/mjstealey/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":0,"state":"open","created_at":"2015-11-03T17:13:57Z","updated_at":"2015-11-12T23:13:09Z","due_on":"2015-11-17T05:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/607/commits","review_comments_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/607/comments","review_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/607/comments","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/0ef5757d454f258246ff0d53e5b5f1252f76b760","head":{"label":"hydroshare:548-link-swmi-with-mp","ref":"548-link-swmi-with-mp","sha":"0ef5757d454f258246ff0d53e5b5f1252f76b760","user":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"repo":{"id":24703136,"name":"hydroshare","full_name":"hydroshare/hydroshare","owner":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hydroshare/hydroshare","description":"HydroShare is a collaborative website being developed for better access to data and models in the hydrologic sciences. ","fork":false,"url":"https://api.github.com/repos/hydroshare/hydroshare","forks_url":"https://api.github.com/repos/hydroshare/hydroshare/forks","keys_url":"https://api.github.com/repos/hydroshare/hydroshare/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hydroshare/hydroshare/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hydroshare/hydroshare/teams","hooks_url":"https://api.github.com/repos/hydroshare/hydroshare/hooks","issue_events_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/events{/number}","events_url":"https://api.github.com/repos/hydroshare/hydroshare/events","assignees_url":"https://api.github.com/repos/hydroshare/hydroshare/assignees{/user}","branches_url":"https://api.github.com/repos/hydroshare/hydroshare/branches{/branch}","tags_url":"https://api.github.com/repos/hydroshare/hydroshare/tags","blobs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hydroshare/hydroshare/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/refs{/sha}","trees_url":"https://api.github.com/repos/hydroshare/hydroshare/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/{sha}","languages_url":"https://api.github.com/repos/hydroshare/hydroshare/languages","stargazers_url":"https://api.github.com/repos/hydroshare/hydroshare/stargazers","contributors_url":"https://api.github.com/repos/hydroshare/hydroshare/contributors","subscribers_url":"https://api.github.com/repos/hydroshare/hydroshare/subscribers","subscription_url":"https://api.github.com/repos/hydroshare/hydroshare/subscription","commits_url":"https://api.github.com/repos/hydroshare/hydroshare/commits{/sha}","git_commits_url":"https://api.github.com/repos/hydroshare/hydroshare/git/commits{/sha}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/comments{/number}","issue_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/comments{/number}","contents_url":"https://api.github.com/repos/hydroshare/hydroshare/contents/{+path}","compare_url":"https://api.github.com/repos/hydroshare/hydroshare/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hydroshare/hydroshare/merges","archive_url":"https://api.github.com/repos/hydroshare/hydroshare/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hydroshare/hydroshare/downloads","issues_url":"https://api.github.com/repos/hydroshare/hydroshare/issues{/number}","pulls_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls{/number}","milestones_url":"https://api.github.com/repos/hydroshare/hydroshare/milestones{/number}","notifications_url":"https://api.github.com/repos/hydroshare/hydroshare/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hydroshare/hydroshare/labels{/name}","releases_url":"https://api.github.com/repos/hydroshare/hydroshare/releases{/id}","created_at":"2014-10-02T02:19:41Z","updated_at":"2015-10-16T12:02:24Z","pushed_at":"2015-11-16T17:32:58Z","git_url":"git://github.com/hydroshare/hydroshare.git","ssh_url":"git@github.com:hydroshare/hydroshare.git","clone_url":"https://github.com/hydroshare/hydroshare.git","svn_url":"https://github.com/hydroshare/hydroshare","homepage":"https://www.hydroshare.org","size":57490,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":175,"forks":2,"open_issues":175,"watchers":12,"default_branch":"develop"}},"base":{"label":"hydroshare:develop","ref":"develop","sha":"db0879d2ea3c69e27d90dad88fdef9219f9ac309","user":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"repo":{"id":24703136,"name":"hydroshare","full_name":"hydroshare/hydroshare","owner":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hydroshare/hydroshare","description":"HydroShare is a collaborative website being developed for better access to data and models in the hydrologic sciences. ","fork":false,"url":"https://api.github.com/repos/hydroshare/hydroshare","forks_url":"https://api.github.com/repos/hydroshare/hydroshare/forks","keys_url":"https://api.github.com/repos/hydroshare/hydroshare/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hydroshare/hydroshare/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hydroshare/hydroshare/teams","hooks_url":"https://api.github.com/repos/hydroshare/hydroshare/hooks","issue_events_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/events{/number}","events_url":"https://api.github.com/repos/hydroshare/hydroshare/events","assignees_url":"https://api.github.com/repos/hydroshare/hydroshare/assignees{/user}","branches_url":"https://api.github.com/repos/hydroshare/hydroshare/branches{/branch}","tags_url":"https://api.github.com/repos/hydroshare/hydroshare/tags","blobs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hydroshare/hydroshare/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/refs{/sha}","trees_url":"https://api.github.com/repos/hydroshare/hydroshare/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/{sha}","languages_url":"https://api.github.com/repos/hydroshare/hydroshare/languages","stargazers_url":"https://api.github.com/repos/hydroshare/hydroshare/stargazers","contributors_url":"https://api.github.com/repos/hydroshare/hydroshare/contributors","subscribers_url":"https://api.github.com/repos/hydroshare/hydroshare/subscribers","subscription_url":"https://api.github.com/repos/hydroshare/hydroshare/subscription","commits_url":"https://api.github.com/repos/hydroshare/hydroshare/commits{/sha}","git_commits_url":"https://api.github.com/repos/hydroshare/hydroshare/git/commits{/sha}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/comments{/number}","issue_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/comments{/number}","contents_url":"https://api.github.com/repos/hydroshare/hydroshare/contents/{+path}","compare_url":"https://api.github.com/repos/hydroshare/hydroshare/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hydroshare/hydroshare/merges","archive_url":"https://api.github.com/repos/hydroshare/hydroshare/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hydroshare/hydroshare/downloads","issues_url":"https://api.github.com/repos/hydroshare/hydroshare/issues{/number}","pulls_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls{/number}","milestones_url":"https://api.github.com/repos/hydroshare/hydroshare/milestones{/number}","notifications_url":"https://api.github.com/repos/hydroshare/hydroshare/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hydroshare/hydroshare/labels{/name}","releases_url":"https://api.github.com/repos/hydroshare/hydroshare/releases{/id}","created_at":"2014-10-02T02:19:41Z","updated_at":"2015-10-16T12:02:24Z","pushed_at":"2015-11-16T17:32:58Z","git_url":"git://github.com/hydroshare/hydroshare.git","ssh_url":"git@github.com:hydroshare/hydroshare.git","clone_url":"https://github.com/hydroshare/hydroshare.git","svn_url":"https://github.com/hydroshare/hydroshare","homepage":"https://www.hydroshare.org","size":57490,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":175,"forks":2,"open_issues":175,"watchers":12,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/607"},"html":{"href":"https://github.com/hydroshare/hydroshare/pull/607"},"issue":{"href":"https://api.github.com/repos/hydroshare/hydroshare/issues/607"},"comments":{"href":"https://api.github.com/repos/hydroshare/hydroshare/issues/607/comments"},"review_comments":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/607/comments"},"review_comment":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/607/commits"},"statuses":{"href":"https://api.github.com/repos/hydroshare/hydroshare/statuses/0ef5757d454f258246ff0d53e5b5f1252f76b760"}}}}