From: drizea Date: Sat, 7 Jul 2012 13:33:02 +0000 (+0300) Subject: create, update and cancel holds functionality finished X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d11ea4190f0cc5c95688a27daab2ce1fcec11b83;p=working%2FEvergreen.git create, update and cancel holds functionality finished --- diff --git a/Open-ILS/src/Android/res/layout/fines_list_item.xml b/Open-ILS/src/Android/res/layout/fines_list_item.xml index 860067d598..85ad58f823 100644 --- a/Open-ILS/src/Android/res/layout/fines_list_item.xml +++ b/Open-ILS/src/Android/res/layout/fines_list_item.xml @@ -12,19 +12,19 @@ - diff --git a/Open-ILS/src/Android/res/layout/hold_details.xml b/Open-ILS/src/Android/res/layout/hold_details.xml index 2c71f78391..5871df6398 100644 --- a/Open-ILS/src/Android/res/layout/hold_details.xml +++ b/Open-ILS/src/Android/res/layout/hold_details.xml @@ -160,7 +160,7 @@ android:text="@string/contact_telephone" /> - @@ -271,6 +272,30 @@ android:gravity="center" /> + + + + + + + + diff --git a/Open-ILS/src/Android/res/values/strings.xml b/Open-ILS/src/Android/res/values/strings.xml index 4c4d80422a..b405472fa5 100644 --- a/Open-ILS/src/Android/res/values/strings.xml +++ b/Open-ILS/src/Android/res/values/strings.xml @@ -34,8 +34,9 @@ Update Hold Are you sure you want to cancel this hold? Automatically activate hold one - - + Contact phone number + Hold expire time + Date when the hold is frozen Total Owned Total Paid diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java index fd89ddcbcc..bfcf2ce8a8 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java @@ -812,9 +812,19 @@ public class AccountAccess { } - public Object updateHold(OSRFObject newHoldObject){ + public Object updateHold(OSRFObject ahr,Integer pickup_lib, boolean email_notify, boolean phone_notify, String phone, boolean suspendHold, String expire_time,String thaw_date){ //TODO verify that object is correct passed to the server - Object response = Utils.doRequest(conn,SERVICE_CIRC, METHOD_UPDATE_HOLD, new Object[]{authToken,newHoldObject}); + + ahr.put("pickup_lib", pickup_lib); //pick-up lib + ahr.put("phone_notify", phone); + ahr.put("email_notify", email_notify); + ahr.put("expire_time",expire_time); + //frozen set, what this means ? + ahr.put("frozen", suspendHold); + //only if it is frozen + ahr.put("thaw_date",thaw_date); + + Object response = Utils.doRequest(conn,SERVICE_CIRC, METHOD_UPDATE_HOLD, new Object[]{authToken,ahr}); return response; } diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldDetails.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldDetails.java index 1aafada668..56c932ca68 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldDetails.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldDetails.java @@ -1,71 +1,112 @@ package org.evergreen.android.accountAccess.holds; +import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import org.evergreen.android.R; import org.evergreen.android.accountAccess.AccountAccess; +import org.evergreen.android.globals.GlobalConfigs; import android.app.Activity; import android.app.AlertDialog; +import android.app.ProgressDialog; import android.app.AlertDialog.Builder; import android.app.DatePickerDialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Color; import android.os.Bundle; import android.text.format.DateFormat; import android.text.format.Time; import android.view.View; import android.view.View.OnClickListener; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.DatePicker; import android.widget.EditText; +import android.widget.Spinner; import android.widget.TextView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.Toast; -public class HoldDetails extends Activity{ +public class HoldDetails extends Activity { - public static final int RESULT_CODE_DELETE_HOLD = 0; - + public static final int RESULT_CODE_UPDATE_HOLD = 1; - + public static final int RESULT_CODE_CANCEL = 2; - + private TextView recipient; - + private TextView title; - + private TextView author; - + private TextView physical_description; - + private TextView screen_title; - + private AccountAccess accountAccess; - + private EditText expiration_date; - + private Button updateHold; - + private Button cancelHold; - + private Button back; - + + private EditText phone_number; + + private CheckBox phone_notification; + + private CheckBox email_notification; + private DatePickerDialog datePicker = null; - + + private CheckBox suspendHold; + + private Spinner orgSelector; + + private DatePickerDialog thaw_datePicker = null; + + private EditText thaw_date_edittext; + + private Date expire_date = null; + + private Date thaw_date = null; + private Context context; + + private int selectedOrgPos = 0; + + public Runnable updateHoldRunnable; + private ProgressDialog progressDialog; + + private GlobalConfigs globalConfigs; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = this; setContentView(R.layout.hold_details); - - final HoldRecord record = (HoldRecord) getIntent().getSerializableExtra("holdRecord"); - - System.out.println("Record " + record + " " + record.title + " " + record.ahr); - + globalConfigs = GlobalConfigs.getGlobalConfigs(this); + + final HoldRecord record = (HoldRecord) getIntent() + .getSerializableExtra("holdRecord"); + + System.out.println("Record " + record + " " + record.title + " " + + record.ahr); + accountAccess = AccountAccess.getAccountAccess(); - + recipient = (TextView) findViewById(R.id.hold_recipient); title = (TextView) findViewById(R.id.hold_title); author = (TextView) findViewById(R.id.hold_author); @@ -74,19 +115,52 @@ public class HoldDetails extends Activity{ cancelHold = (Button) findViewById(R.id.cancel_hold_button); updateHold = (Button) findViewById(R.id.update_hold_button); back = (Button) findViewById(R.id.back_button); - + + phone_number = (EditText) findViewById(R.id.hold_contact_telephone); + phone_notification = (CheckBox) findViewById(R.id.hold_enable_phone_notification); + email_notification = (CheckBox) findViewById(R.id.hold_enable_email_notification); + suspendHold = (CheckBox) findViewById(R.id.hold_suspend_hold); + + orgSelector = (Spinner) findViewById(R.id.hold_pickup_location); expiration_date = (EditText) findViewById(R.id.hold_expiration_date); - + thaw_date_edittext = (EditText) findViewById(R.id.hold_thaw_date); + screen_title.setText("Place Hold"); - + + + recipient.setText(accountAccess.userName); title.setText(record.title); author.setText(record.author); - if(record.recordInfo != null) - physical_description.setText(record.recordInfo.physical_description); + if (record.recordInfo != null) + physical_description + .setText(record.recordInfo.physical_description); + + // set record info + phone_notification.setChecked(record.phone_notification); + email_notification.setChecked(record.email_notification); + suspendHold.setChecked(record.suspended); - System.out.println(record.title + " " + record.author); + if (record.thaw_date != null) { + thaw_date = record.thaw_date; + thaw_date_edittext.setText(DateFormat.format("MMMM dd, yyyy", + thaw_date)); + } + if (record.expire_time != null) { + expire_date = record.expire_time; + expiration_date.setText(DateFormat.format("MMMM dd, yyyy", + expire_date)); + } + + // hide edit text + if( record.thaw_date == null) + disableView(thaw_date_edittext); + if(!record.phone_notification) + disableView(phone_number); + + System.out.println(record.title + " " + record.author); + back.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -95,65 +169,213 @@ public class HoldDetails extends Activity{ }); cancelHold.setOnClickListener(new OnClickListener() { - + @Override public void onClick(View v) { - - - Builder confirmationDialogBuilder = new AlertDialog.Builder(context); - confirmationDialogBuilder.setMessage(R.string.cancel_hold_dialog_message); - - confirmationDialogBuilder.setNegativeButton(android.R.string.no, null); - confirmationDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - - System.out.println("Remove hold with id" + record.ahr.getInt("id")); - - //TODO put into thread - accountAccess.cancelHold(record.ahr); - - setResult(RESULT_CODE_DELETE_HOLD); - - finish(); - } - }); - confirmationDialogBuilder.create().show(); - + + Builder confirmationDialogBuilder = new AlertDialog.Builder( + context); + confirmationDialogBuilder + .setMessage(R.string.cancel_hold_dialog_message); + + confirmationDialogBuilder.setNegativeButton( + android.R.string.no, null); + confirmationDialogBuilder.setPositiveButton( + android.R.string.yes, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int which) { + + System.out.println("Remove hold with id" + + record.ahr.getInt("id")); + + progressDialog = ProgressDialog.show(context, "Please wait", "Canceling hold"); + Thread cancelHoldThread = new Thread(new Runnable() { + + @Override + public void run() { + accountAccess.cancelHold(record.ahr); + + runOnUiThread(new Runnable() { + @Override + public void run() { + progressDialog.dismiss(); + setResult(RESULT_CODE_DELETE_HOLD); + + finish(); + } + }); + } + }); + cancelHoldThread.start(); + + } + }); + confirmationDialogBuilder.create().show(); + } }); + + updateHoldRunnable = new Runnable() { + @Override + public void run() { + // update new values + String expire_date_s = null; + String thaw_date_s = null; + if (expire_date != null) + expire_date_s = GlobalConfigs.getStringDate(expire_date); + if (thaw_date != null) + thaw_date_s = GlobalConfigs.getStringDate(thaw_date); + + accountAccess.updateHold(record.ahr, selectedOrgPos, + email_notification.isChecked(), phone_notification + .isChecked(), + phone_number.getText().toString(), suspendHold + .isChecked(), expire_date_s, thaw_date_s); + + runOnUiThread(new Runnable() { + @Override + public void run() { + progressDialog.dismiss(); + Toast.makeText(context, "Hold updated", Toast.LENGTH_SHORT); + setResult(RESULT_CODE_UPDATE_HOLD); + finish(); + } + }); + } + }; updateHold.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { + progressDialog = ProgressDialog.show(context, "Please wait", "Updating hold"); + Thread updateHoldThread = new Thread(updateHoldRunnable); + updateHoldThread.start(); + } + }); + + phone_notification + .setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + + if (isChecked) { + enableView(phone_number); + } else + disableView(phone_number); + } + }); + + suspendHold.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { - //update new values - accountAccess.updateHold(record.ahr); + if (isChecked) { + enableView(thaw_date_edittext); + } else { + disableView(thaw_date_edittext); + } } }); - Calendar cal = Calendar.getInstance(); + datePicker = new DatePickerDialog(this, - new DatePickerDialog.OnDateSetListener() { - - public void onDateSet(DatePicker view, int year, - int monthOfYear, int dayOfMonth) - { - Time chosenDate = new Time(); - chosenDate.set(dayOfMonth, monthOfYear, year); - long dtDob = chosenDate.toMillis(true); - CharSequence strDate = DateFormat.format("MMMM dd, yyyy", dtDob); - expiration_date.setText(strDate); - //set current date - }}, cal.get(Calendar.YEAR),cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); - + new DatePickerDialog.OnDateSetListener() { + + public void onDateSet(DatePicker view, int year, + int monthOfYear, int dayOfMonth) { + + Date chosenDate = new Date(year - 1900, monthOfYear, + dayOfMonth); + expire_date = chosenDate; + CharSequence strDate = DateFormat.format( + "MMMM dd, yyyy", chosenDate); + expiration_date.setText(strDate); + // set current date + } + }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), + cal.get(Calendar.DAY_OF_MONTH)); + expiration_date.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { datePicker.show(); } }); - + + thaw_datePicker = new DatePickerDialog(this, + new DatePickerDialog.OnDateSetListener() { + + public void onDateSet(DatePicker view, int year, + int monthOfYear, int dayOfMonth) { + + Date chosenDate = new Date(year - 1900, monthOfYear, + dayOfMonth); + thaw_date = chosenDate; + CharSequence strDate = DateFormat.format( + "MMMM dd, yyyy", chosenDate); + thaw_date_edittext.setText(strDate); + // set current date + } + }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), + cal.get(Calendar.DAY_OF_MONTH)); + + thaw_date_edittext.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + thaw_datePicker.show(); + } + }); + + ArrayList list = new ArrayList(); + for (int i = 0; i < globalConfigs.organisations.size(); i++) { + list.add(globalConfigs.organisations.get(i).padding + + globalConfigs.organisations.get(i).name); + + if (globalConfigs.organisations.get(i).id == record.pickup_lib) + selectedOrgPos = i; + } + ArrayAdapter adapter = new ArrayAdapter(this, + android.R.layout.simple_spinner_item, list); + orgSelector.setAdapter(adapter); + + orgSelector.setSelection(selectedOrgPos); + + orgSelector.setOnItemSelectedListener(new OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView arg0, View arg1, int ID, + long arg3) { + + selectedOrgPos = ID; + + } + + public void onNothingSelected(android.widget.AdapterView arg0) { + } + }); } - + + public void disableView(View view) { + + // view.setFocusable(false); + view.setFocusable(false); + + view.setBackgroundColor(Color.argb(255, 100, 100, 100)); + // view.setVisibility(View.INVISIBLE); + } + + public void enableView(View view) { + // view.setVisibility(View.VISIBLE); + + view.setFocusableInTouchMode(true); + + view.setBackgroundColor(Color.argb(255, 255, 255, 255)); + } + } diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldItem.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldItem.java deleted file mode 100644 index 744b2b903f..0000000000 --- a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldItem.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.evergreen.android.accountAccess.holds; - -import java.util.Date; - -import org.evergreen.android.globals.GlobalConfigs; -import org.opensrf.util.OSRFObject; - -public class HoldItem { - - //metarecord - public static final int M = 0; - //record - public static final int T = 1; - //volume - public static final int V = 2; - //issuance - public static final int I = 3; - //copy - public static final int C = 4; - //part - public static final int P = 5; - - private Integer requestLibID = null; - - private Integer pickupLibID = null; - - public Integer holdType = null; - //id for target object - public Integer target = null; - public Date expire_time = null; - - public String title = null; - - public String author = null; - - - /* Hold status - * holdStatus == 4 => AVAILABLE - * holdStatus == 3 => WAITING - * holdStatus <= 3 => TRANSIT - */ - - //only for P types - public String part_label = null; - - public Integer status = null; - - public Boolean active = null; - - public HoldItem(OSRFObject ahr){ - - this.target = ahr.getInt("target"); - String type = ahr.getString("hold_type"); - - if(type.equals("M")){ - holdType = M; - }else - if(type.equals("T")){ - holdType = T; - }else - if(type.equals("V")){ - holdType = V; - }else - if(type.equals("I")){ - holdType = I; - }else - if(type.equals("C")){ - holdType = C; - }else - if(type.equals("P")) - holdType = P; - - this.expire_time = GlobalConfigs.parseDate(ahr.getString("expire_time")); - - } - //based on status integer field retreive hold status in text - public String getHoldStatus(){ - - String holdStatus = ""; - - if(holdType == 7) - return "Suspended"; - if(holdType == 4) - return "Available"; - if(holdType == 3) - return "Waiting"; - if(holdType < 3) - return "Transit"; - - return holdStatus; - } - -} diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldRecord.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldRecord.java index f99f1220ff..ebd4350680 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldRecord.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/HoldRecord.java @@ -55,6 +55,16 @@ public class HoldRecord implements Serializable{ public RecordInfo recordInfo = null; + public boolean email_notification = false; + + public boolean phone_notification = false; + + public boolean suspended = false; + + public Date thaw_date; + + public int pickup_lib; + public HoldRecord(OSRFObject ahr){ this.target = ahr.getInt("target"); @@ -81,7 +91,22 @@ public class HoldRecord implements Serializable{ holdType = P; this.expire_time = GlobalConfigs.parseDate(ahr.getString("expire_time")); - + + this.thaw_date = GlobalConfigs.parseDate(ahr.getString("thaw_date")); + String res = ahr.getString("email_notify"); + + if(res.equals("t")) + this.email_notification = true; + res = ahr.getString("phone_notify"); + if(res.equals("t")) + this.phone_notification = true; + + res = ahr.getString("frozen"); + if(res.equals("t")) + this.suspended = true; + pickup_lib = ahr.getInt("pickup_lib"); + + } //based on status integer field retreive hold status in text public String getHoldStatus(){ diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/PlaceHold.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/PlaceHold.java index df4e77f18b..ecd366eb10 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/PlaceHold.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/holds/PlaceHold.java @@ -145,11 +145,11 @@ public class PlaceHold extends Activity{ String expire_date_s = null; String thaw_date_s = null; - if(expire_date != null) + if (expire_date != null) expire_date_s = GlobalConfigs.getStringDate(expire_date); - if(thaw_date != null) + if (thaw_date != null) thaw_date_s = GlobalConfigs.getStringDate(thaw_date); - + System.out.println("date expire: " + expire_date_s + " " + expire_date); int selectedOrgID = -1; if(globalConfigs.organisations.size() > selectedOrgPos)